Teensy 4.1 SD + playSDRaw noise

Status
Not open for further replies.

mb_dtlj

Member
Hi
I'm using a teensy 4.1 with the Audio Adapter to read raw files via SD card and output to headphone jack.

I am using a modification of the WavFilePlayer example code (attached below)

I am getting a crackle about 75 ms after start of file playback.
I'm reading mono 16-bit 44.1k wavs converted to .RAW, but get the same crackle using .wavs
I am using the teensy 4.1's sd reader, but when I switch to the Audio adapter's sd, the noise goes away.

I'm hoping to use the teensy's reader instead of audio adapter's sd as apparently the 4.1 runs faster and I want to read multiple files simultaneously. (see here: https://forum.pjrc.com/threads/62158-SD-card-interface-Teensy-4-1-vs-Teensy-4-0-Audio-adapter?p=247733&viewfull=1#post247733)

fiddling with file normalization and audio adapter volume levels. even at low levels, the click is present, but it scales along with the overall output level. So I think it's not clipping either in file or at some gain stage.

One other thing I noticed is when I powered the teensy off of my computer's usb, there was more noise, and in fact it appeared at a regular interval of about 75 ms. When I recorded the output with both wall-wart and computer usb power, the initial crackle of noise (which was present no matter what power I used) lined up with this interval. So, I'm wondering if the crackle is some digital noise that is present when the 4.1's sd reader is working, but not when the audio adapter's shield is?

Below is a spectrogram showing recordings. I restarted the teensy and rerecorded the same test to see if noise spikes consistently appeared at the same time and they did. So I think the noise is maybe being created by the sd read process itself?

Is this a known issue? Any chance there's an easy fix involving a capacitor or something?
Screen Shot 2021-05-24 at 3.16.14 PM.jpg

code:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdRaw           playWav1;
AudioOutputI2S           audioOutput;
AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

void setup() {

  AudioMemory(20);

  sgtl5000_1.enable();
  //sgtl5000_1.adcHighPassFilterDisable();
  //sgtl5000_1.audioProcessorDisable();
  sgtl5000_1.volume(0.3);

  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
     // Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void playFile(const char *filename)
{

  playWav1.play(filename);

  // A brief delay for the library read WAV info
 //   delay(5);

  while (playWav1.isPlaying()) {
  }
}


void loop() {
  playFile("T004.RAW");  // filenames are always uppercase 8.3 format
  delay(500);
}
 
I also have the problem of glitches.
But if I increase the buffer to 256 the program crashes.
I use the mp3 player and the AudioAnalyzeFFT1024.
Does anyone have a good idea about this?
 
Status
Not open for further replies.
Back
Top