Problems with Teensy3.1 playing SDWAV files Mono and Stereo

Status
Not open for further replies.

Teenfor3

Well-known member
There has been several threads in the last weeks relating to problems experienced with playing WAV files using Teensy3.1 ans either audio shield or SD adaptor. Different issues arose with different users and basically I think all the issues have got mixed up and this makes them harder to untangle.


I am starting this thread for hopefully a specific problem I am experiencing, and I have had several threads running on it in the past and haven't got any solution yet.

The problem is when starting to play a wav file from SD using eg. wav.play("filename") if the file is stereo the file open for approx 3 ms and plays 3ms of sound then starts again and plays the start over again and then continues to play to the end of the file. I have tested this using the Audio shield outputs and also on the Teensy3.1 DAC port and it happens on both. My method of discovering this is to record the sound output using a PC and Audacity, then zoom in to see the waveform. I have tested it with pushbutton selecting play and also playing the files in a loop and it happens in both situations.
MONO files play perfectly.
There is also a problem as the play is coming to the end of the file for stereo files only. The last 1 or 2 ms are distorted. Again MONO files play perfectly.


I have been investigating this for a number of weeks now and even with the most basic setup, a teensy connected to a SD adaptor and output to DAC port and recorded on a PC it is possible to see this easily. I had been hoping that even though I may not be able to get a solution, that someone somewhere would be able to confirm that this happens with them, or that it doesn't happen with them. But to date I have been unable to get that confirmed. I have attached a zip file containing a most basic sketch, some sound files, jpeg files of a basic setup on a breadboard, jpegs of my recordings of the teensy output etc.
and I would be grateful if someone to try this out and either tell me I am doing something wrong or it happens with them.
I have been able to test this on 2 different Teensy3.1 and on 1 audio adaptor and it doesn't matter what combination it happens every time. I have more teensys and audio adaptors on order and will be able to test further then. I want to prove it with the most basic setup first and then try that audio adaptor after.

There is still a further problem I was finding with a project that has the audio adaptor, that was a glitch at 185 ms for stereo and 370 ms for mono files after the file starts to play, if there were more that 14 files on the SD. But that only happens with Audio adaptor connected not with the Teensy on its own so I don't want to mix the 2 problems here.

Hopefully I may get an outcome this time......Thanks..........
 

Attachments

  • PlaySDcardWAVPaul2.zip
    1.2 MB · Views: 107
I have just go my new Teensy3.1s and Audio Adaptors. I have hooked up the new teensy exactly as shown on the jpeg of the breadboard and get exactly the same result. So that is it tested on 2 independant teensys that are connected to nothing else other than the SDcard adaptor and both show same problem. Stereo files play with a double start (3ms) and end (1 ms) is distorted and gives an amplified last cycle for a faded out 1 khz sound. MONO files play perfectly.
So does that point to some of the routines in the audio library. The connections and setup on the breadboard are basic...................
 
I decided to try to see if any there was any change if connecting PlayWav1 output port1 to DAC or PlayWav1 output Port0 to DAC. And there is a difference.
The screens in the Zipfile attachment are all for port1 to DAC.

When Port0 is connected to DAC......done in the sketch by.... AudioConnection patchCord1(playWav1, 0, dac2, 0);

The start of all the files have a 2 cycle fadein. Start of file plays just under 2.75 cycles (1 khz wave), then glitches to Zero for 0.25 cycles approx. Then plays start of file again and continues normal Until end of file. The end of the files all have a 8 cycle fadeout, followed by a 6 cycle fadeout and followed by a 4 cycle fadeout at the very end. Up to the end of the 6 cycle fadeout plays normal. Then for the last 4 cycle fadeout the first 1.25 cycles play normal, then glitches to ZERO amplitude and plays no more of the file. There would be still 2.75 cycles to play. Each cycle is 1 ms for 1 khz wave.

When Port1 is connected to DAC...... done in the sketch by.... AudioConnection patchCord1(playWav1, 1, dac2, 0);

As before the start of all the files have a 2 cycle fadein. Start of file plays 2.75 cycles (1 khz wave), then glitches to Zero and then plays the start of file again and continues normal Until end of file. The end of the files as before all have a 8 cycle fadeout, followed by a 6 cycle fadeout and followed by a 4 cycle fadeout at the very end. Up to the end of the 6 cycle fadeout plays normal. Then for the last 4 cycle fadeout the first 1.25 cycles play normal, then glitches to ZERO amplitude and then plays 0.75 cycles distorted followed by one cycle at low amplitude followed by 1 cycle at full wave amplitude. This would be the actual end of the file, there would be no more cycles to play. Each cycle is 1 ms for 1 khz wave.

So I can see there is a difference in the output of each port of the object playWav1. Does that help to point to the problem....???
Problem is still only with stereo files....................
 
A "work around" until the problems of the "start of play" and "end of play" for SDwav files is sorted......

If you want quick cleaner starts and minimum gap between wavs that are played by successive play statements then make sure there is 3 ms only of silence at start of file and a minimum fadein, probably 2 ms.

Similarly.....If you want to play to the end of the wavefile and stop as quick as possible or play the next file as quick as possible.......then make sure there is a fadeout of 2 ms followed by 2 ms only of silence at the file end.

If there is sound immediately at the start then the first 3 ms of the wavefile is played twice and if there is sound up to the end of the wavefile the last 3 ms is distorted and the end of the file is not played at all.

You can have larger gaps of silence if you want......just means bigger gaps.......and at start the 3 ms of silence that would be played twice is just 6 ms of silence....so not heard....... Also long period of silence at end even if distorted at last 3 ms is still silence and not heard.

This only is needed for STEREO WAV file played from SDcard......... MONO WAV files play OK......
 
Last edited:
Status
Not open for further replies.
Back
Top