WAV playback sounds distorted

Status
Not open for further replies.
Paul......
Sorry I have been away from base all day and missed all the activity relating to this...............
But back now and downloaded your fix, copied in as Audio library and tested with the sine wav KiloHz1.wav etc....
Yes they all play perfectly for me. Yes I know there is a "roughness sound" at the end of KiloHz3.wav due to the multiple fadeouts. I only put these fadeouts in so I could see easier what bits of the tail end of the file was getting distorted before the fix.....or indeed was it playing to the end.

KiloHz1.wav is stereo, has 2 ms fadein at start and 2 ms fadeout at end. KiloHz2.wav is just simply a copy of it, to see if there was an error would it be reproduced in both files. KiloHz3.wav is stereo with 2 ms fadein at start, then at end 8 ms fadeout followed by 6 ms fadeout followed by 4 ms fadeout at very end. There is no period of silence at start or end of any of the files. As far as I can see from recording the teensy DAC output using Audacity the waveforms of the original test files are reproduced by the teensy DAC output OK. I haven't tested the audio adaptor connected up to it yet.......

There is one problem I do see in the recorded output..............In the test sketch in the Zip in post #89 above, I changed the delays to 400 ms so as to stop playing the current file at end of the delay, before coming to end of file, and then send another playWav1.play(filename) to start playing the next file as quickly as possible. Most of the transitions between the last file playing and the next starting are completely tight with no gaps.....But I get repeated groups of 3 sucessive gaps together at 5.6 seconds intervals. The gaps are 3 ms wide (or maybe its 2.9 ms = 1 buffer??).......so for instance...all tones play for 400 ms.......say I get a gap at 2.0, 2.4 and 2.8 seconds.....then no gaps until 7.6 seconds (2 + 5.6), then gaps at 7.6, 8.0, and 8.4.....then no gaps until 13.2 and 3 successive gaps here as well between the files played. Apart from a gap it's not causing much problem but my question is why is it happening for some and at repeated intervals.....Paul are you getting this with your tests..??.
Thanks for your help..............
 
Apart from a gap it's not causing much problem but my question is why is it happening for some and at repeated intervals.....Paul are you getting this with your tests..??.

I didn't test this. I only looked at the reported problems, startup and ending behavior (truly a bug in the library), and the 80 ms repeat (library doing exactly what it should).

The library updates on a 2.9 ms schedule. If you want to make changes without an update disrupting your timing, you must use AudioNoInterrupts to prevent the library from updating.

Because Teensy is very fast, often you can make changes without the update happening. But not always. If your code isn't doing much else, and especially if it waits for an event from the update, like indication a file isn't playing anymore, odds are good it can fall into a timing pattern where it hits the update every time, or on a repeating pattern. You're almost certainly seeing such an effect.
 
Paul wrote...........
"I didn't test this. I only looked at the reported problems, startup and ending behavior (truly a bug in the library), and the 80 ms repeat (library doing exactly what it should)."

Yes, I understand you were only looking at the start and end problems. I have only mentioned it now because I have only noticed now when testing your fix. I did notice random gaps before but didn't think much about it. What I notice now is they are in groups of 3 repeating at 5.6 seconds intervals and all other transitions between files is completely tight ... no gaps...... I'll try AudioNoInterrupts to see if it sorts it. Do you mean just put in like this.......
AudioNoInterrupts();
playWave1.play(filename);
AudioInterrupts();
delay(400);
AudioNoInterrupts();
playWave1.play(filename);
AudioInterrupts();
etc....etc....

Thanks for your help...............

I am just using the sketches that are in the Zip files.
 
Yes, Thanks Paul......I tried AudioNoInterrupts(); etc and it worked. Absolutely no gaps anywhere.....I and testing DAC out only at the moment...but assume audio adaptor etc will be OK as well. jpg of Teensy output attached.

dsparks....AudioNoInterrupts....just do it as my last post............Paul put a link in takes you to Audio Library help and describes it.
 

Attachments

  • PaulSDcardWavFixed1.JPG
    PaulSDcardWavFixed1.JPG
    58.9 KB · Views: 121
I tried that and it does clean up my glitch about 50% of the time. Its still there though.

Im going to implement the mixer solution Paul suggested earlier.
 
Paul.....There were 2 problems on this thread and I think thet are getting mixed up.......

Teenfor3 Problem was Double starts to SDwave files and end of file problems.....I think that has been sorted. I have only tested the fix on Teensy DAC, I will put the audio adaptor together tomorrow and test on that but I think it will be OK. I now getting good quality sounds without distortion and I am only playing basic sketch on a basic setup on a breadboard.

dsparks problem is to do with quantization and drum beat type sounds and looks like it not sorted.....dsparks will post comments on that.
Can dsparks run my test sketch and confirm he gets good sound from my samples to eliminate any wiring or hardware problem..??
 
I tried that and it does clean up my glitch about 50% of the time.

that's not really surprising that i won't make it go away. so yes, try with a mixer. as suggested earlier in the thread, you'd probably just need to come up with a simple way to fade out one instance of AudioPlaySdWav while starting the next, rather than killing the (single) voice and restarting it ... that's guaranteed to lead to artefacts of one kind or another. it's easily possible to stream several files simultaneously, so that shouldn't be a big deal.

you'll need some counter or other method to keep track of how many voices are on / what's the next unallocated AudioPlaySdWav object.

for inspiration, here's a few examples/options re voice allocation, though they're more complex than what you need:
https://github.com/pichenettes/midipal/blob/master/midipal/apps/dispatcher.cc#L137-L168

also ultimately i'd try Frank's SPI flash library, it'll be more responsive for drumming.
 
I just set up a simple if / else statement with some isPlaying() checks.

So for example. If wav1 is playing, then I fade the mixer down to 0 and stop the wav1 and play wav2

Seems to work ok.
 
I am still hearing the glitch.

Would it be better to format the card as FAT32 or FAT16?

And what block allocation size would be best?

Thank you!
 
Also this may have been missed..

I understand that playing the wav then cutting it off and playing the same file can result in a strange sound, but that is NOT the sound I am hearing. I have played the exact same WAV files on my computer and looped them at 80ms as in my Teensy code I test with. It does NOT produce the same sound I am hearing on the Teensy/audio board.

I assume this is almost all related to the accessing of the WAV file from the SD card. So now Im wondering, is it possible to load the file once and store it in some sort of memory or wav table when accessing it multiple times?

Thank you for the insight!
 
I understand that playing the wav then cutting it off and playing the same file can result in a strange sound, but that is NOT the sound I am hearing. I have played the exact same WAV files on my computer and looped them at 80ms as in my Teensy code I test with. It does NOT produce the same sound I am hearing on the Teensy/audio board.

well, chances are the mechanics of playing a wav on your computer and the teensy are very different, so that's not really comparable.

I assume this is almost all related to the accessing of the WAV file from the SD card. So now Im wondering, is it possible to load the file once and store it in some sort of memory or wav table when accessing it multiple times?

so are you still hearing that when mixing several instances of the wav player?

as to pre-loading an entire file* ... do the math: the teensy has 64K of RAM. so, generally speaking, not really. drum samples can be fairly small though and don't have to be 44.1kHz either, so play_memory might be an option? (as Paul mentioned above). that's storing the files in the flash, which is somewhat larger (256K).
 
I understand.

Its important that my drum samples remain at 44.1K and stereo.

They are all under 256K in size as WAV files. How would I go about loading the sample that is selected once and storing it in the flash? Then how do I access this?

Is that even possible?

Thanks!
 
I have played the exact same WAV files on my computer and looped them at 80ms as in my Teensy code I test with. It does NOT produce the same sound I am hearing on the Teensy/audio board.

As always, if you want me to investigate, you must follow the "forum rule". If we're talking about the difference between some PC-based player and Teensy, you need to post *exact* details and steps for the PC side too.
 
Paul I was merely stating that while modifying my WAV samples on my computer I played them in quick succession there too, just to see if they did the same thing. Im not trying to break any forum rules. Sorry for the extra info.

Im just trying to nail this issue down.
 
is it possible to load the file once and store it in some sort of memory or wav table when accessing it multiple times?

Yes.

First, run the example, from File > Examples > Audio > SamplePlayer. It comes with 6 sounds in the example, which you can trigger by buttons (or wires) connected between pins 0-5 and GND.

The sounds are stored a files with arrays of numbers. To convert a .wav file to a .c and h file, as was done for the 6 sounds in that example, use the wav2sketch program (there's a copy already on your hard drive, deep within the Audio library folder).

https://github.com/PaulStoffregen/Audio/tree/master/examples/SamplePlayer/wav2sketch

Reading data directly from program memory is extremely fast and efficient. If you're running into SD card latency issues (eg, run the card test in the audio lib's HardwareTesting folder), you'll find the program memory player is immune to such troubles.
 
Im just trying to nail this issue down.

Me too. If there is another bug, I certainly want to find and fix it. Sometimes it takes me days or even weeks to work the time into my schedule, but I believe I've shown a pretty good track record of actually digging into reproducible problems and fixing bugs. For me, fixing the bug is usually the quick part. Reproducing the problem almost always takes most of my time....
 
I agree Paul, you are a huge help to fixing numerous issues we all encounter. And that is greatly appreciated!

I know its difficult to reproduce the same results sometimes and that just makes it that much harder to solve.


In regards to the wav2sketch option.

So I understand this correctly. Youre saying I could select a WAV sample in my program via some button or whatever type of interface. Once loaded, convert that WAV sample into a .c file and then access it from flash memory? Everytime a sample selection is made I would need it to erase the previous flash sample and store the new one. This sounds like the best option in my opnion. And all within my running Teensy program???
 
Please, run the SamplePlayer example. Real hands-on experience with that example will probably answer most of your questions far better than any text on this forum ever could.
 
Agreed , hands on experience is way better. I have already been over the SamplePlayer.

It does not answer my question about whether or not I can load a WAV from an SD and convert it and ultimately play that converted file from flash all within my Teensy code.
 
Paul and dsparks......When I tested last night I was using teensy only audio output and the sine wave samples and all worked perfectly as posted.
I setup another teensy and an audio adaptor as per the standard tutorial on the PJRC web and all seemed to be OK for the sample sine wave. Then I copied more sound files on to the SDcard. Short files approx 4-5 seconds of random sounds, buzz sounds etc. and played them all in a loop with a delay between. All played OK started OK and ended OK but I noticed I was getting the 3 ms gap between the sine wave files and the "ragged" waveform buzz files played OK tight between last file stopping and next starting except for a few random gaps.

Then I noticed this was happening with one SDcard than the other. I formatted several times, didnt cure it, but kept on formatting and copying the files on in different order etc. But seems no pattern to it. Eventually I now have about 25 files on each SDcard...the same files are on each and all play perfectly with no gaps anywhere between them. I was only playing stereo except the mono wave that was in the test 4 it was still there..... So I think your fix has sorted the start and end play problems OK but there must be a problem with the SD routines actually reading the SDcard. It seems to be very "fiddly" about formatting etc.
I am using SDformatter but I also tried windows format and made no difference.
Is there a standard recommendation for for formatting......what options in SD formatter should I pick.

The teensy DAC output and the audio adaptor output both seem OK now...... its the copying files to SDcard seems to be the problem
 
The other interesting fact in my case is that I am NOT noticing the issue with snare samples or other higher toned samples. Most of the kick samples I am using.

I have checked them all in audacity and even tried lowering the levels on them. Same result. Its as iff the lower frequency is causing the issue. Or maybe its just because the lower end sound doesnt cover up hearing the higher pitched glitch sound.
 
Trying to get my WAV samples converted into sketch format so I can test the idea you suggested Paul, but the wav2sketch EXE does NOT work on my windows computer. Is there another way to convert my WAV files?

Thanks!
 
For windows..... put both wave2sketch.exe and your sample 40BPX.wav in same folder and double click the exe file. Two files will be created in that folder one is the .c and other is the .h. Copy these to the folder you have your sketch.ino in and compile. You should see the tabs for the .c and .h in the IDE.
 
Status
Not open for further replies.
Back
Top