pdf-icon

Mic Class

config

Syntax:

mic_config_t config(void);

Description:

  • Get the current Mic configuration information

Parameters:

  • None

Return:

  • mic_config_t:
    • Mic configuration information
  struct mic_config_t
  {
    /// i2s_data_in (for mic)
    int pin_data_in = -1;

    /// i2s_bclk
    int pin_bck = I2S_PIN_NO_CHANGE;

    /// i2s_mclk
    int pin_mck = I2S_PIN_NO_CHANGE;

    /// i2s_ws (lrck)
    int pin_ws = I2S_PIN_NO_CHANGE;

    /// input sampling rate (Hz)
    uint32_t sample_rate = 16000;

    union
    {
      struct
      {
        uint8_t left_channel : 1;
        uint8_t stereo : 1;
        uint8_t reserve : 6;
      };
      input_channel_t input_channel = input_only_right;
    };

    /// Sampling times of obtaining the average value
    uint8_t over_sampling = 2;

    /// multiplier for input value
    uint8_t magnification = 16;

    /// Coefficient of the previous value, used for noise filtering
    uint8_t noise_filter_level = 0;

    /// use analog input mic ( need only pin_data_in )
    bool use_adc = false;

    /// for I2S dma_buf_len
    size_t dma_buf_len = 128;

    /// for I2S dma_buf_count
    size_t dma_buf_count = 8;

    /// background task priority
    uint8_t task_priority = 2;

    /// background task pinned core
    uint8_t task_pinned_core = -1;

    /// I2S port
    i2s_port_t i2s_port = i2s_port_t::I2S_NUM_0;
  };

Syntax:

void config(const mic_config_t& cfg);

Description:

  • Configure the Mic configuration information

Parameters:

  • mic_config_t& cfg:
    • Configuration information reference

Return:

  • None

begin

Syntax:

bool begin(void);

Description:

  • Initialize the Mic

Parameters:

  • None

Return:

  • bool:
    • true:successful initialization
    • false:failure

end

Syntax:

void end(void);

Description:

  • Reverse initialization

Parameters:

  • None

Return:

  • None

isRunning

Syntax:

bool isRunning(void);

Description:

  • Determine if the current Mic background task is running

Parameters:

  • None

Return:

  • bool:
    • true: Running
    • false: Not running

isEnabled

Syntax:

bool isEnabled(void);

Description:

  • Determine if the current Mic is initialized

Parameters:

  • None

Return:

  • bool:
    • true: Initialized
    • false: Not initialized

isRecording

Syntax:

size_t isRecording(void);

Description:

  • Determine if the current Mic is recording

Parameters:

  • None

Return:

  • Not Recording: 0
  • Recording (There's room in the queue): 1
  • Recording (There's no room in the queue.): 2

setSampleRate

Syntax:

void setSampleRate(uint32_t sample_rate);

Description:

  • Set the recording sample rate

Parameters:

  • uint32_t sample_rate:
    • The sample rate in Hz

Return:

  • None

record

Syntax:

bool record(uint8_t* rec_data, size_t array_len, uint32_t sample_rate, bool stereo = false);
bool record(int16_t* rec_data, size_t array_len, uint32_t sample_rate, bool stereo = false);
bool record(uint8_t* rec_data, size_t array_len);
bool record(int16_t* rec_data, size_t array_len);

Description:

  • Record raw audio data in 8-bit or 16-bit wav format

Parameters:

  • uint8_t* rec_data:
    • Pointer to store the raw audio data
  • size_t array_len:
    • The length of the array
  • uint32_t sample_rate:
    • The sample rate for recording in Hz
  • bool stereo:
    • true:stereo
    • false:mono

Return:

  • bool:
    • true: Successfully executed
    • false: Execution failed
On This Page