Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 8 1 2 3 ... LastLast
Results 1 to 25 of 177

Thread: WAV playback sounds distorted

  1. #1
    Senior Member
    Join Date
    Jul 2014
    Posts
    210

    WAV playback sounds distorted

    I have been developing a device that plays samples from the audio adapter via the SD card reader. The WAVs are in the proper format and have been playing from the audio board just fine. Recently however, I have noticed that while playing successive samples of the same sample while not letting the previous sample quit playing, the audio starts to distort or sound bit crushed. There is a very clear quantization sound happening. The only change I have made has been to update to the latest stable Teensy and audio board software and libraries.

    Im wondering if anyone else has had this issue and whether or not there is a fix?

    Thank you!

  2. #2
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    I've noticed the same with RAW files once in a while - it seems to clear itself up after a few seconds for me

    mine are off the SDcard at 44khz mono 16bit

  3. #3
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    It does not go away for me unless the interval between successive samples plays is reduced. Almost any overlap between the same sample will cause the issue. And it seems to get worse as the time between successive sample plays decreases. As if the quantization builds upon its self. I never noticed it before in the "beta" software.

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    Use the basic test sketch in this thread shown below..... and see if it happens when running only this basic code

    thread....................... "teensy 3.1 and audio shield strange wav player problem"

    It will play the same file over and over again in a loop............

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    I just ran some tests via the sample code included.

    #include <Audio.h>
    #include <Wire.h>
    #include <SD.h>
    #include <SPI.h>

    // Create the Audio components. These should be created in the
    // order data flows, inputs/sources -> processing -> outputs
    //
    AudioPlaySdWav wav;
    AudioOutputI2S dac;

    // Create Audio connections between the components
    //
    AudioConnection c1(wav, 0, dac, 0);
    AudioConnection c2(wav, 1, dac, 1);

    // Create an object to control the audio shield.
    //
    AudioControlSGTL5000 audioShield;


    void setup() {
    // Audio connections require memory to work. For more
    // detailed information, see the MemoryAndCpuUsage example
    AudioMemory(5);

    audioShield.enable();
    audioShield.volume(0.5);

    SPI.setMOSI(7);
    SPI.setSCK(14);
    if (SD.begin(10)) {
    wav.play("40BP.WAV");
    }
    }

    void loop() {
    //float vol = analogRead(15);
    // vol = vol / 1024;
    audioShield.volume(0.5);
    delay(100);
    wav.play("40BP.WAV");
    }


    The distortion is still there. I also tested the output on line-out, headphones out, and the DAC pin out. All with the exact same results. So I know its not related to the output choice.

    I believe it has something to do with how the WAVs are read from the SD card. I have also tried the same samples from different cards. Same results.

  6. #6
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Mine was not overlapping samples btw, so I've experienced a similiar issue (although very short lived) simply playing 4 or 5 different samples concurrently.

  7. #7
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    So this is not an isolated issue that I am experiencing. Thats good to know.

    I hope we can get some feedback from Paul on this issue.

  8. #8
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Can you check and see if you are maxing out your cpu load at the times of the problem?

    I would suggest the first step is loading your files onto the flash 16mb chip on the audio board. You should reduce the cpu load and therefore less likely to encounter issues.

  9. #9
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    How do I go about loading my audio samples onto the 16MB flash chip?

    And the CPU is well under max. Running around 20-30%.

  10. #10
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Is that peak cpu?


    https://forum.pjrc.com/threads/27409...m-Serial-Flash

    Code is written for you by Frank B. Away you go

  11. #11
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    Hi dsparks....What type of distortion are you talking about.....Can you post a output sound file or Screen Dump of the Teensy output recording.
    I have run the sketch you posted earlier and it plays for me.....quite a smooth sound. It is looping at 100 milli seconds.....so very short sounds to hear distortions in it. But....what I do notice is when I record the sound in Audacity and Zoom in.....I get the double attempts at starting to play the files each time. I have attached screen dumps to show you ESD.wav file used from my other posts. The top waveform shows it looping at 100 ms as per your sketch and the bottom waveform is a Zoomed in of one of the starting to play the file again on the next loop. You can clearly see what I think is 2 attempts at starting to play OR overlapping the start bit of playing. Once it starts it plays everytime the rest of the file OK.....but you can see the distortion at each start. Is this what you are finding. Can you please post your Teensy output waveform either as I have done or as a sound recording. I am using the sketch you posted earlier. So we are both doing the same thing.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	ESDplaybackTest.JPG 
Views:	111 
Size:	102.9 KB 
ID:	3278  

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    Thanks Pensive for the link.......just noticed it as I posted last post.
    Yes, Frank B has also written a new library Arduino_Teensy_Codec.lib. I have downloaded it to my library folder and run the MP3player example. And...Magic...it gives a clean start everytime as the file starts to play. I have only done initial tests but so far seems better thn PlaySDwav etc.

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    Frank B's MP3player plays a clean start to each file, but, there is approx 60 milli seconds between that last file end and start of next file.
    Using wav.play(filename) in a loop. So seems much slower than playSDwave at switching between files............

  14. #14
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    Teen43,

    I do not have a way to capture my output wav form, but Im almost certain what you captured is what I am experiencing. Im playing the samples in such a quick succession as that may be how they are triggered in real life by a drummer. So a 60ms time frame between sample plays would NOT be acceptable. I am however interested in experimenting with that code however. Do you have a link to the code by Frank B?

  15. #15
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    Oh and here is the audio sample I am testing with. Its not the only sample. Its every sample, but this one is much easier to hear the audio artifacts produced.
    Attached Files Attached Files

  16. #16
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    If you click on the link Pensive gave above and click on the links there....It wiil take you to github
    Click on blue Arduino_Teensy_Codec_lib and you get all the files....download the Zip.
    But this is the FrankB library for MP3 etc......its the one that gives me the 60 ms delay between successive plays.

    The standard audio library for PlaySDwav etc has much less delay as you see from my screen dumps but it distorted the start of play...probably for roughly the same delay........I think the PlaySDwav will be faster than MP3 if someone can sort out what is wrong with start playing the files or point me in the right direction....I am not good at reading the library coding.... I haven't tried the aac or flac option to see if they are faster.

    If it is only drum sounds probably the synth sketches would be OK......I tried them and they work and fast...........but for my project I want to be able to play real sounds from a SD however short and if I want to change them it is only a matter of copying new sound files to the SD

    the MP3 just gives a silent delay. Did you try the serial flash......it should be faster and cleaner...........I assume the serial flash they mean is the optional chip mounted on the teensy board.......I don't have it on mine.......so I suppose I cannot use the serial flash routines. Serial to SD cannot be considered flash or can it.? ? ?
    There is also a new GUI in FrankB library for the new objects etc.

    Regards capturing the output of teensy to see what is happening, all I am doing is sending output to i2s1, unmute_lineout and connect it to linein on computer and record in Audacity. Dac on the board probably works as well and plug to linein or mic-in on computer OR via the headphone on the audio adaptor. I would like to see your waveforms if you can send them.

  17. #17
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    Teenfor3


    I have attached the sample output I am getting.

    Please ignore the ground loop hum and minor pops. Its the bit crushing / quantizing at the start of the sample plays that I am referring too.

    Thanks!
    Attached Files Attached Files

  18. #18
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    Yes, seems to be a similar problem, I think 2 starts at beginning of file each time for some reason. Your recording in badly clipped, either clipped in the recording or when playing in teensy. Try reducing the play volume in the sketch. I have attached screen dumps of me playing your original 40BPX.wav and compared them. Any ideas waht to look for in the library to see why it starts to read twice.?.?.?
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	dsparks40BPX.jpg 
Views:	104 
Size:	56.2 KB 
ID:	3283  

  19. #19
    Senior Member
    Join Date
    Jul 2014
    Posts
    210
    Even as low volume and different out puts such as headphones, line-out, and DAC, all produce the same.

    I have even modified a test wav file by reducing its gain by -6db. Still the same issues.

  20. #20
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    This is a recording of my teensy playing your file with a random number for the delay in the loop of your test sketch. Still has the 2 starts...sound not bad...what does a drum sound like.?.?....maybe the recording sound more like gunfire..?????. I have no problem with clipping or volume.????

    The recorded sound is not bad except for the initial click as the file is opened......this is I think caused by the 2 starts at opening the playing of the sound is OK and the end is OK. need some help in trying to find how a file is opened and initially played....
    Attached Files Attached Files
    Last edited by Teenfor3; 01-11-2015 at 01:31 AM.

  21. #21
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    hmmm.

    Try putting it through a mixer with the gains set to 0.7 to eliminate saturation?

  22. #22
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    60ms ? really ? I would expect ~20..30ms. But i never measured it. Ok, this depends heavily on your SD-Card, how much files are on it, and many more uncontrollable variables.

    One thing you can try with the codecs:: Start the playing, and pause it immediately. Then, unpause the playing when you need it. This way, it should be < 3 milliseconds.

    Did you delete all tags from the file ? The tags are stored in front of the sounddata.
    And, of course it helps do run the teensy with 120MHZ, and to use -O2
    Or you can store the MP3 (better is aac!) in the program-flash or serial-flash
    Last edited by Frank B; 01-11-2015 at 11:19 AM.

  23. #23
    Senior Member
    Join Date
    Apr 2014
    Posts
    318
    dsparks,
    Try this.............
    Put the SDcard into a PC SD reader slot on PC and copy all the files from the SDcard into a folder on PC.
    Then format the SDcard fat32 on PC using SDformatter.
    Then select all the files that were on the SDcard from your PC folder and copy and paste them all together to the SDcard.
    Do not edit or open any of the files copied to SDcard from PC software.
    Un mount the SDcard from the PC.
    Uplug the SDcard from the PC SDcard slot.
    Plug the SDcard back into Teensy audio adaptor slot.

    The files on the SDcard should now be contiguous ie. not fragmented.

    Do not copy individual files to the SDcard or delete individual files from the SDcard.
    Always copy all OFF then edit as required, them format and copy files back on alltogether.
    That way the files will not get fragmented.
    .................................................. .......................

    Pensive or Paul......
    Any ideas or help with how to read or debug the SDwav library code in more detail to find out why it reads the start of the file twice..???

    ...........................................

  24. #24
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    The files are in the libraries\Audio in your Arduino-Folder. Look at play_sd_wav.cpp.

  25. #25
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,679
    @teenfor3: Do you use the bounce library ? Your example sounds like your are not...
    Do you have the double-starts when you start playing in a loop, without using keystrokes ?

Posting Permissions

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