Buzzing in RAW Audio Recording - T4.1 with Audio Shield Rev D

jamgalactic

New member
I'm trying to solve a problem where RAW audio recorded to the Audio Shield SD card contains a considerable amount of buzzing noise.
I'm using a MAX4466 amplified electret mic attached to the MIC input on the shield. It is getting 3.3v VCC from the shield 3.3 pin point.

The Audio Shield is connected to the Teensy using headers and pins, and all of the solder points look clean to me. I am using a breadboard to test the max4466 connections because I did not want to directly solder in the case issues like this came up.

I've tried several things to clean up the audio. I've tested grounding the mic to the Teensy GND pin, the Audio Shield GND pin, and the MIC GND Pin.
I've tried powering the max4466 using both the audio shield 3.3v pinout, and the Teensy 3.3v pin (located between pins 12 and 24)

There does appear to be a small amount of audible noise while the audio is being written to the SD card.

I am planning to add some capacitors to the mic connections to try and reduce noise there. I also have some MAX9814 modules coming in that I plan to try, if those might sound better.

Any suggestions or advice would be greatly appreciated. Thank you!

C++:
#include <Bounce2.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
const char *normalFilename = "REC.RAW";
File normalFile;
// Audio Components
AudioInputI2S        audioInput;
AudioAnalyzePeak     peak;
AudioRecordQueue     queue;
AudioPlaySdWav       playAnnouncement; // Used for playing effect announcements
AudioPlaySdRaw       playRaw;
AudioOutputI2S       audioOutput;
AudioMixer4          mixer1;
// AudioEffectGranular  effectGranular;
// AudioEffectBitcrusher effectBitcrush;
AudioConnection      patchCord1(audioInput, 0, queue, 0);
AudioConnection      patchCord2(audioInput, 0, peak, 0);
AudioConnection      patchCord3(playAnnouncement, 0, mixer1, 0);
AudioConnection      patchCord4(playRaw, 0, mixer1, 1);
AudioConnection      patchCord5(mixer1, 0, audioOutput, 0);
AudioConnection      patchCord6(mixer1, 0, audioOutput, 1);
AudioControlSGTL5000 audioShield;
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14
Bounce2::Button recordButton = Bounce2::Button();
Bounce2::Button playNormalButton = Bounce2::Button();
// Bounce2::Button pitchButton = Bounce2::Button();
// Bounce2::Button speedButton = Bounce2::Button();
// Bounce2::Button distortButton = Bounce2::Button();
//const int redLED = 16;
//const int greenLED = 17;
unsigned long lastButtonPressTime = 0;  // To track inactivity
const int DEBOUNCE_DELAY = 200;  // Milliseconds to debounce

int pitchIndex = 2;
int speedIndex = 2;
int distortionIndex = 0;
int mode = 0;
// float pitchOptions[5] = {0.5, 0.75, 1.0, 1.5, 2.0};
// float speedOptions[5] = {0.25, 0.5, 1.0, 2.0, 4.0};
// int distortionLevels[4] = {16, 8, 4, 0};  // **16-bit = No Distortion**
void setup() {
    Serial.begin(115200);
    recordButton.attach(2, INPUT_PULLUP);
    recordButton.interval(8);
    recordButton.setPressedState(LOW);
    playNormalButton.attach(14, INPUT_PULLUP);
    playNormalButton.interval(8);
    playNormalButton.setPressedState(LOW);
  
    // pitchButton.attach(3, INPUT_PULLUP);
    // pitchButton.interval(8);
    // pitchButton.setPressedState(LOW);
    // speedButton.attach(4, INPUT_PULLUP);
    // speedButton.interval(8);
    // speedButton.setPressedState(LOW);
  
    // distortButton.attach(5, INPUT_PULLUP);
    // distortButton.interval(8);
    // distortButton.setPressedState(LOW);
    AudioMemory(60);
    audioShield.enable();
    audioShield.inputSelect(AUDIO_INPUT_MIC);
    audioShield.micGain(0);
    audioShield.volume(0.5);
    // Set mixer gains (adjust levels as needed)
    mixer1.gain(0, 1.0);  // Channel 0 (WAV)
    mixer1.gain(1, 1.0);  // Channel 1 (RAW)
    //pinMode(redLED, OUTPUT);
    //pinMode(greenLED, OUTPUT);
    // Initialize SD card
    SPI.setMOSI(SDCARD_MOSI_PIN);
    SPI.setSCK(SDCARD_SCK_PIN);
    if (!SD.begin(SDCARD_CS_PIN)) {
        Serial.println("SD Card initialization failed!");
        return;
    }
    // Initial effect settings
    // effectGranular.beginPitchShift(1.0); // 1.0 = normal pitch
    // effectGranular.setSpeed(1.0); // Keep speed normal while shifting pitch
    // effectBitcrush.bits(16);
}
void loop() {
  recordButton.update();
  playNormalButton.update();
  pitchButton.update();
  speedButton.update();
  distortButton.update();
 
  if(recordButton.pressed() && mode != 1){
    if(mode == 2 || mode == 3){
      stopPlaying();
    }
    if(mode == 0) {
      startRecording();
    }
  }
  if(mode == 1 && !recordButton.isPressed()) {
    Serial.println("Record Button Released");
    stopRecording();
  }
  if(playNormalButton.pressed() && mode != 1){
    Serial.println("Play Normal Button Pressed");
    if(mode == 3) {
      //stop playing
    }
    if(mode == 0) {
      startPlaying();
    }
  }
  if(mode == 1) {
    continueRecording();
  }
  if(mode == 2) {
    continuePlaying();
  }
}
// Start recording audio
void startRecording() {
  Serial.println("Recording Started...");
  mode = 1;
  if(SD.exists(normalFilename)) {
    SD.remove(normalFilename);
  }
  normalFile = SD.open(normalFilename, FILE_WRITE);
  if(normalFile) {
    queue.begin();
    //digitalWrite(redLED, HIGH);
  } else {
    Serial.println("Error opening normal file for writing!");
    return;
  }
}
// Continue recording
void continueRecording() {
  if(mode == 1){
    Serial.println("continue");
  }
  if(mode == 1 && queue.available() >= 2) {
    byte buffer[512];
    memcpy(buffer, queue.readBuffer(), 256);
    queue.freeBuffer();
    memcpy(buffer+256, queue.readBuffer(), 256);
    queue.freeBuffer();
    normalFile.write(buffer, 512);
  }
}
// Stop recording audio
void stopRecording() {
  Serial.println("Recording Stopped.");
  mode = 0;
  queue.end();
  while(queue.available() > 0) {
    normalFile.write((byte*)queue.readBuffer(), 256);
    queue.freeBuffer();
  }
  normalFile.close();
  // Create a reversed version on SD
}
void startPlaying() {
  if(mode == 0) {
    Serial.println("Playing audio");   
    playRaw.play(normalFilename);
    mode = 2;   
  }
}
void continuePlaying(){
  if((mode == 2 || mode == 3) && !playRaw.isPlaying()) {
    playRaw.stop();
    mode = 0;
  }
}
void stopPlaying(){
  Serial.println("Stopping audio");
  if(mode == 2 || mode == 3){
    playRaw.stop();
    mode = 0;
  }
}
 
Back
Top