[Learn, Build & Win] SonoGuard Update 2: I²S Mic Capture to SD Card & The "Alien Audio" Bug

Hello again! I’m back with the second major milestone for SonoGuard (my edge-AI acoustic hazard wearable for the DigiKey / Circuit Digest contest).

With the MAX32655FTHR and MAX9867 audio codec successfully communicating over I²C, the next challenge was routing the digital MEMS microphone data into the Cortex-M4F and logging it to the microSD card to verify the audio quality before writing the live DSP algorithms.

1. The I²S & DMA Pipeline

Capturing audio while simultaneously writing to an SD card will cause dropped frames if you rely on the CPU. To fix this, I set up a hardware Ping-Pong DMA buffer:

  • The I²S peripheral pulls audio from the codec and uses DMA to fill Buffer A in the background.
  • When Buffer A is full, an interrupt fires, and I instantly repoint the DMA to fill Buffer B.
  • While the hardware silently fills Buffer B, the CPU uses the FatFs library to write Buffer A to the microSD card.

2. “Alien Audio” Sample Rate Bug

When I pulled the first capture.wav file off the SD card, the audio sounded incredibly deep and slow—like an alien voice.

This is a classic embedded audio bug. I had configured my WAV header and I²S peripheral for a 24 kHz sample rate (based on the board’s 12.288 MHz oscillator math). However, reading the hardware registers revealed that the MSDK’s max9867_init() driver actually forces the hardware to 48 kHz by default.

Because the hardware was capturing 48,000 samples per second, but my WAV file was telling the computer to play them back at 24,000 samples per second, it stretched the audio out to exactly half-speed!

The Fix: I bumped the I²S configuration and WAV header definitions in main.c up to 48 kHz (#define SMPL_RATE 48000), and the audio completely cleared up.

Audacity Verification

Here is a screenshot of the raw PCM audio pulled straight from the MAX32655FTHR’s SD card into Audacity. The waveform is clean, perfectly pitched, and there is no clipping.

Next Steps

Now that the microphone pipeline is mathematically aligned and proven clean, it is time to build the brain. In the next update, I will be porting my Python FFT algorithms to C using the Arm CMSIS-DSP library to run live frequency analysis on the Cortex-M4F’s hardware Floating Point Unit (FPU).

Project Repository:GitHub - Christy-Roy-tech/SonoGuard-MAX32655FTHR · GitHub