Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# Using the mic_array - default model or with custom filters

## Configuration defines (mic_array_conf_default.h)

An application using the mic array needs to have defines set for compile-time configuration of the mic array instance. Defaults for these defines are defined in the header file `mic_array_conf_default.h`. These defines should be overridden in an optional header file `mic_array_conf.h` file or in the application’s `CMakeLists.txt`.

This section fully documents all of the settable defines and their default values.

MIC_ARRAY_CONFIG_MIC_COUNT

  Number of PDM microphone channels. Default: 2.

MIC_ARRAY_CONFIG_MIC_IN_COUNT

  Number of input mic channels - This is the width of the pdm port. Default: MIC_ARRAY_CONFIG_MIC_COUNT.

MIC_ARRAY_CONFIG_USE_PDM_ISR

  Use interrupt-driven PDM capture (1 = ISR, 0 = polling/task). Default: 1 -> Use ISR.

MIC_ARRAY_CONFIG_SAMPLES_PER_FRAME

  PCM samples per frame emitted by the driver. Must be >= 1. Default: 1.

MIC_ARRAY_CONFIG_USE_DC_ELIMINATION

  Enable DC elimination on the PCM output (1 = enabled). Default: 1.

## Function definitions (mic_array_task.h)

The header file `mic_array_task.h` contains the function API declarations that the application needs to call to initialise and start a mic array instance when using the default model (`mic_array_init()` and `mic_array_start()`) or when using custom filter (`mic_array_init_custom_filter()` and `mic_array_start()`).

void mic_array_init(

  pdm_rx_resources_t *pdm_res,
  const unsigned *channel_map,
  unsigned output_samp_freq,

)

  Initializes the mic array task.

  Initializes the contexts for the decimator thread and configures the clocks and ports for PDM reception. Note that this does not start any threads or PDM capture.

  After calling this, the PDM clock is active and signaling, but the PDM rx service has not been activated (when running in the interrupt context)/PDM rx thread is not created (when running in thread context) so the received PDM samples are ignored.

  Parameters:

    - pdm_res – Pointer to the pdm_rx_resources_t struct containing hardware resources required by the mic array module.

    - channel_map – Optional mapping from PDM input pin to mic-array output channel index.

      - Array size: MIC_ARRAY_CONFIG_MIC_COUNT

      - channel_map[i] is the PDM pin index that should feed mic output channel i.

      - If channel_map is NULL, a default 1:1 mapping is used: PDM pin i -> mic output channel i.

      - Valid values for channel_map[i] are in [0, MIC_ARRAY_CONFIG_MIC_IN_COUNT-1].

    - output_samp_freq – Target sampling rate (in Hz) for the decimated PCM output stream Supported values: 16000, 32000, 48000 (Hz).

void mic_array_start(chanend_t c_frames_out)

  Start the mic array task.

  This function sets up and activates the PDM rx service in ISR mode (when MIC_ARRAY_CONFIG_USE_PDM_ISR=1), and then immediately begins executing the decimator. When MIC_ARRAY_CONFIG_USE_PDM_ISR=0, it starts the PDM rx service and decimator as 2 parallel threads

  After calling this the real-time condition is active, meaning there must be another thread waiting to pull frames from the other end of `c_frames_out` as they become available.

  Parameters:

    - c_frames_out – (Non-streaming) Channel over which to send processed frames of audio.

void mic_array_init_custom_filter(

  pdm_rx_resources_t *pdm_res,
  mic_array_conf_t *mic_array_conf,

)

  Initialize the mic array using application-supplied decimation filter and PDM RX buffers.

  All memory referenced by `mic_array_conf` must be allocated and owned by the caller and must remain valid for the lifetime of the mic array task, i.e., until mic_array_start returns. This excludes the mic_array_conf_t structure itself and the mic_array_decimator_conf_t::filter_conf array, which may reside on the caller’s stack.

  After successful initialization, the PDM clock is configured and started, but no threads/ISRs are running until mic_array_start() is called.

  Note

  The caller owns the buffers referenced by `mic_array_conf` and must ensure correct sizing and required alignment of these buffers.

  Parameters:

    - pdm_res – Pointer to hardware resources used by the mic array module (ports, clocks, and chanends).

    - mic_array_conf – Pointer to top-level configuration that bundles the decimator pipeline configuration (mic_array_decimator_conf_t) and the PDM RX configuration (pdm_rx_conf_t).