Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: playing samples from SD card strange behavior

  1. #1
    Senior Member
    Join Date
    Dec 2018
    Posts
    114

    playing samples from SD card strange behavior

    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;
        }
      }
    }

  2. #2
    Senior Member
    Join Date
    Dec 2018
    Posts
    114
    ps : of course change the sample name...

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    712
    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.

  4. #4
    Senior Member
    Join Date
    Dec 2018
    Posts
    114
    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

  5. #5
    Member
    Join Date
    Sep 2019
    Location
    Sevilla, Spain
    Posts
    38
    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

  6. #6
    Senior Member
    Join Date
    Dec 2018
    Posts
    114
    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.

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,487
    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.

  8. #8
    Senior Member
    Join Date
    Dec 2018
    Posts
    114
    OK i am going to try this beta right now and report.

  9. #9
    Senior Member
    Join Date
    Dec 2018
    Posts
    114
    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.

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,487
    Quote Originally Posted by emmanuel63 View Post
    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.

  11. #11
    Senior Member
    Join Date
    Dec 2018
    Posts
    114
    OK. I do it.

  12. #12
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,487
    Good note on the Beta TD 1.54 thread.

    Question: did AudioPlaySdWav work on prior version of TeensyDuino? If so what version was that?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •