Skip to content

Audio input in mic.h doesn't work #1

@aroehl78

Description

@aroehl78

For audio input to work for ESP32, please add the dma buffer to the private section and use i2s_channel_read.

i2s_read is legacy.

Here is the updated code for mic.h:

  private:
    int micGain = 32; // 0 - 64
    int samples_read = 0;
	static const int dmaBufferLength = 64;  //AR - added
    static const int16_t bufferLen = dmaBufferLength * 4;
    uint16_t inputBuf[bufferLen];
    int mBufIndex = 0;

    #if IS_ESP8266()
      System.println("Mic class not yet implemented for ESP8266");
      void readMic() {
        // TBC
      }
    #elif IS_ESP32()
      inline
      void readMic() {
        size_t bytesIn = 0;
        esp_err_t result = i2s_channel_read(rx_handle, inputBuf, bufferLen, &bytesIn, portMAX_DELAY);  // AR - changed
        if (result == ESP_OK && bytesIn > 0) {
          samples_read = bytesIn / 2; // stereo 16 bit samples
        }
      }
    #endif

I tested it and it works wonderfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions