playing samples from SD card strange behavior

Status
Not open for further replies.

emmanuel63

Well-known member
Hello,

I have made a simple sample player with teensy 3.6 + audio shield. The samples are stored on buitin SD card and triggered with a bunch of Touch pins. To maximize polyphony and time access, my samples are mono.
When I trigger these mono samples, I have noticed short clics and cracks at the very begining of the playing. But when doing the same test with stereo samples : no cracks and clics (but of course reduced polyphony).

I tried to add envelopes with short attacks, delays and all kind of tweakings, but it doesn't solve the problem.
Any idea or test to do ?

Here is a basic sketch for testing. Set for T3.6 + audioshield + builtin SD.
Thank you for any help.
Emmanuel

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

AudioPlaySdWav           playSdWav1;
AudioOutputI2S           i2s1;
AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection          patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;

// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN    BUILTIN_SDCARD

//number of touch pin used
const byte touch_pin_number = 2;

//touch_pins#
const byte touch_pins[] = {0, 1, 16, 17, 22, 23};

//this arrays stores touch pin output values
int touch_value[touch_pin_number];

//touch threshold
const int threshold = 2000;

//touched or not touched
bool touchStatus[touch_pin_number];

void setup() {
  Serial.begin(9600);
  AudioMemory(8 );

  sgtl5000_1.enable();
  sgtl5000_1.volume(0.3);

  //Initializes SD
  SD.begin(SDCARD_CS_PIN);

}

void loop() {
  for (int i = 0; i < touch_pin_number; i++) {
    touch_value[i] = touchRead(touch_pins[i]);

    if (touch_value[i] > threshold && touchStatus[i] == 0) {
      Serial.println("touched");
      touchStatus[i] = 1;
      playSdWav1.play("marimba/60.wav");
    }

    if (touch_value[i] < threshold && touchStatus[i] == 1) {
      Serial.println("released");
      touchStatus[i] = 0;
    }
  }
}
 
the code in AudioPlaySDWav seems to do the right thing on stopping, so should be sending zeroes when not playing,
so the clicks are likely to be the actual samples in the files being offset? Have you looked at them in Audacity or
similar? You could open a mono and a stereo file and compare the starting waveforms.
 
Thanks for your suggestions.

I think my files are OK. There is no DC offset, no clipped section. I can't understand why stereo samples are read smoothly and not the mono samples. I think it is not a speed problem. The problem becomes critical when you retrigger fast the same sample. I can send you my samples (mono and stereo) but I don't know how to attach files.
Emmanuel
 
did you tried with a different microSD cards?
as far as I know, modern cards are fast, but when reading/writing the data sequentially (which is great when recording video in high resolution etc), if you need fast access to small files, microSD cards type 4 will give the best performance I think (those have a 4 inside a semicircle printed), and UHS-I/U3 or UHS-I/U1 the worst.
Hope it helps
 
I think I have tried everything I could : different Sd cards, FAT16, FAT32, exFAT, mono or stereo files, wav, raw, interrupts, delays, envelopes...
I also prepared my files with different softwares : audacity, audition. Nothing works. It seems impossible to get a clean start when triggering samples from SD. There are always artefacts, especially with mono files.
It is frustrating... I know I can use flash memory, but SD card is so easy to play with.
 
Have you tried with TeensyDuino 1.54 Beta? Current is #5 {see 'Annoucements' forum section } - it has a replacement SD system in place that will be the new standard and ideally provide faster throughput.

That doesn't explain why current can do Stereo one might think would require twice the data transfer rate than the Mono with issues.
 
Hello again,
YES ! It's working !
I have no more artefacts when playing mono files with AudioPlaySdWav object. I can play up to 6 samples (maybe more, I haven't tested yet) at the same time. Fast response, no lag, no clics. This is a major improvement. Thanks a lot.
I noticed AudioPlaySdRaw is not working well. It freezes.
I am going to do more testing and report.
 
Hello again,
YES ! It's working !
I have no more artefacts when playing mono files with AudioPlaySdWav object. I can play up to 6 samples (maybe more, I haven't tested yet) at the same time. Fast response, no lag, no clics. This is a major improvement. Thanks a lot.
I noticed AudioPlaySdRaw is not working well. It freezes.
I am going to do more testing and report.

THat is Great - please post on the TD 1.54 beta thread to be sure Paul see's the results of testing - esp if the PlaySdRaw doesn't work out.
 
Good note on the Beta TD 1.54 thread.

Question: did AudioPlaySdWav work on prior version of TeensyDuino? If so what version was that?
 
Status
Not open for further replies.
Back
Top