Skip to content

Connecting Sipeed MicArray to MaixDuino #144

@DatchMoth

Description

@DatchMoth

Sorry that I post just a question here rather than reporting bugs or technical issues.

I'm trying to connect Sipped MicArray to MaixDuino development board.
It is easy to find Maixpy sample code on the official page, but not MaixDuino's one.

So far I make a code as below referring to SpeechRecognizer class lib.

My questions are...

  • How is stereo audio data stored in 1 sample when just only 1 channel? I think first 16bit is of left and others are of right, but SpeechRecognizer seems to handle 32bit each (reference code).
  • Is it possible to obtain 3 channels data via just 1 I2S device interface? And if could, how is the stored data structure?
#include "i2s.h"

// I2S control pins
// center mic of mic array and on-board mic are not used
#define MIC_D0_PIN 21
#define MIC_D1_PIN 22
#define MIC_D2_PIN 23
#define MIC_CLK_PIN 15
#define MIC_WS_PIN 32

// audio data buffer
#define SAMPLING_RATE 8000 // [Hz]
#define SAMPLING_TIME 1 // [ms]
#define BUFFER_SIZE (SAMPLING_TIME * SAMPLING_RATE / 1000)

uint32_t buffer0[BUFFER_SIZE];
int16_t buffer0_l[BUFFER_SIZE];
int16_t buffer0_r[BUFFER_SIZE];

void setup_i2s_pins() {
  fpioa_set_function(MIC_CLK_PIN, FUNC_I2S0_SCLK);
  fpioa_set_function(MIC_WS_PIN, FUNC_I2S0_WS);
  fpioa_set_function(MIC_D0_PIN, FUNC_I2S0_IN_D0);
  fpioa_set_function(MIC_D1_PIN, FUNC_I2S0_IN_D1);
  fpioa_set_function(MIC_D2_PIN, FUNC_I2S0_IN_D2);

  i2s_init(I2S_DEVICE_0, I2S_RECEIVER, 0x3F); // use 3 channels

  i2s_rx_channel_config(I2S_DEVICE_0, I2S_CHANNEL_0,
          RESOLUTION_16_BIT, SCLK_CYCLES_32,
          TRIGGER_LEVEL_4, STANDARD_MODE);
  i2s_rx_channel_config(I2S_DEVICE_0, I2S_CHANNEL_1,
          RESOLUTION_16_BIT, SCLK_CYCLES_32,
          TRIGGER_LEVEL_4, STANDARD_MODE);
  i2s_rx_channel_config(I2S_DEVICE_0, I2S_CHANNEL_2,
          RESOLUTION_16_BIT, SCLK_CYCLES_32,
          TRIGGER_LEVEL_4, STANDARD_MODE);

  i2s_set_sample_rate(I2S_DEVICE_0, SAMPLING_RATE);
}

void setup() {
  Serial.begin(115200);

  setup_i2s_pins();

  dmac_init();

  i2s_receive_data_dma(I2S_DEVICE_0, buffer0, BUFFER_SIZE, DMAC_CHANNEL0);
}

void loop() {
  // WIP: still coded for just 1 channel.
  i2s_receive_data_dma(I2S_DEVICE_0, buffer0, BUFFER_SIZE, DMAC_CHANNEL0);
  for(int i = 0; i < BUFFER_SIZE; i+=2)
  {
    buffer0_l[i] = (int16_t)(buffer0[i] & 0xFFFF);
    buffer0_r[i] = (int16_t)(buffer0[i+1] & 0xFFFF);
  }

  // print results
  for(int i=0; i < BUFFER_SIZE; i++)
  {
    Serial.print(4000);Serial.print(",");
    Serial.print(buffer0_l[i]);Serial.print(",");
    Serial.print(buffer0_r[i]);Serial.print(",");
    Serial.println(-4000);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions