WAV playback sounds distorted

Status
Not open for further replies.

dsparks

Well-known member
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!
 
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
 
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.
 
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............
 
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.
 
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.
 
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.
 
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.
 
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%.
 
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.
 

Attachments

  • ESDplaybackTest.JPG
    ESDplaybackTest.JPG
    102.9 KB · Views: 180
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.
 
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............
 
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?
 
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.
 

Attachments

  • 40BPX.wav.zip
    110.4 KB · Views: 171
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.
 
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!
 

Attachments

  • sample test.mp3.zip
    196.1 KB · Views: 131
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.?.?.?
 

Attachments

  • dsparks40BPX.jpg
    dsparks40BPX.jpg
    56.2 KB · Views: 204
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.
 
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....
 

Attachments

  • RandomDrum.zip
    603.8 KB · Views: 154
Last edited:
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:
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..???

...........................................
 
@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 ?
 
Status
Not open for further replies.
Back
Top