Teensy3.1 Audio Shield Glitch in Play Wav Sound

Status
Not open for further replies.

Teenfor3

Well-known member
I have a problem with the example PlayWavfromsdcard sketch and all I have added is put

play.wav (c.wav");
delay (4000);
wav.stop();
delay (4000);

and commented out everything else in the loop to get it to play the first 4
seconds of the file over and over again as a test with a 4 second pause.

This all seems to work OK but I get a glitch at the start of play each time,
about 186 milliseconds into the sound. I thought a simple play.wav command
would give me a clean start of play.? The sound plays for 4 secs and pauses
for 4 seconds OK and repeats.

I have attached copies of mp3 recordings of it from audacity. The line jack on the
audio shield was connected to line in on PC for the recording. The sound
file on the SDcard for teensy to play is only a squarewave files I had
generated in audacity and saved it to sdcard. This sound file loops in audacity without any glitches even between the end and the beginning when played by "hold shift and click Play in audacity"

I also attach the code from the example sketch which I have modified to give various combinations of play and stop and all give me the glitch...sounds like a beep beep at the start of play.

Testfile1usb.mp3 is the sound recorded from PlayRepeatAudioshield1.ino and has the first play in the setup and from then on repeated plays and stops in the loop. The Teensy3.1 and audioshield are powered from the USB port of PC when recording. You can see on the first play what I think is digital noise from the setup then then a few odd square waves the the sound squarewaves and then a glitch at approx 186 milliseconds later. For the repeated plays we dont see any digital setup noise, it just starts to play with a glitch at 186 milliseconds.
The Testfile1pwr.mp3 is a recording of same sketch but with the teensy3.1 and shield powered by a powerpack plugged into the teensy usb socket, and only the audio out jack from the shield connected to the PC soundcard linein. This gives a clean sound, no digital noise, but still the glitch at 186 milliseconds.

Testfile2usb.mp3 and Testfile2pwr is similar except I have put a delay is setup to separate the setup noises from the play loop. You can see the difference in the sketch PlayRepeatAudioshield2.ino. Still get the glitch at 186 milliseconds.

I just wonder is others getting this problem and has anyone got a solution. Please.



This is sketch PlayRepeatAudioshield1.ino......

Code:
#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); // memory allocation

  audioShield.enable();
  audioShield.volume(40);  // set volume at 40

  SPI.setMOSI(7);
  SPI.setSCK(14);
   if (SD.begin(10)) {
  //  wav.play("01_16M.WAV");
  wav.play("C.WAV");
  }
}

void loop() {
//  float vol = analogRead(15);
 // vol = vol / 10.24;
 // audioShield.volume(vol);
 // delay(20);
 
 delay(4000);   // play for 4 seconds
 
 wav.stop();
 
 delay(4000);   // stop for 4 seconds
 
  wav.play("C.WAV");

}





This is sketch PlayRepeatAudioshield2.ino

Code:
#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); // memory allocation

  audioShield.enable();
  audioShield.volume(40);  // set volume at 40

  SPI.setMOSI(7);
  SPI.setSCK(14);
   if (SD.begin(10)) {
  //  wav.play("01_16M.WAV");
 // wav.play("C.WAV");
 
  }
  delay(1000);
}

void loop() {
//  float vol = analogRead(15);
 // vol = vol / 10.24;
 // audioShield.volume(vol);
 // delay(20);
 
 wav.play("C.WAV");
 
 delay(4000);   // play for 4 seconds
 
 wav.stop();
 
 delay(4000);   // stop for 4 seconds
 
 // wav.play("C.WAV");

}
 

Attachments

  • PlayRepeatAudioshield2.ino
    1.1 KB · Views: 194
  • PlayRepeatAudioshield1.ino
    1 KB · Views: 184
  • Testfilesounds.zip
    1.6 MB · Views: 206
I have been trying to do some more testing and discovered that AudioInterupts and AudioNoInterupts have a bearing on it. But not sure how to use it.???
I have attached my sketch and recordings. It seems to need AudioNoInterupts before the first play and AudioInterupts after play then AudioNoInterupts again after the wav.stop. and repeat each time, But it is not totally consistant but works most of the time.
 

Attachments

  • PlayRepeatAudioshield2Int.ino
    2.2 KB · Views: 195
  • TestfileInterupts.zip
    347.7 KB · Views: 181
I have now tried playing RAW sounds from SDcard on Audio shield and I still get a similar glitch but now it is 372 milliseconds into the sound after the sound starts to play. What I have done is......Using SOX converted the original sound file I had "C.WAV" which was 16 bit stereo 44100, to Mono 1 channel 16 bit 44100 and play it using the example sketch for PlayWavFromSDcard but change the audio component to "AudioPlaySdRaw wav;" and the rest is the sameas original example for WAV, I also set volume to 40. I have attached the code used below and attached a mp3 recording using audacity of the output from tha audio jack. The crackling at the start of the recording is me plugging in the usb power to the teensy....you can then hear the sound start to play and then 372 milliseconds later you hear the glitch.

So from this...I get glitch at 186 milliseconds if playing WAV files and a glitch at 372 milliseconds if playing RAW files.......Just thinking as I type this...the time to the glitch is 372 for the mono RAW which is twice that it was was for stereo WAV........so the number of samples processed would be the same......I assume.......so what happens there that is common.....or can be debugged easily.......????????


Code:
#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
//
AudioPlaySdRaw     wav;  // Now playing RAW mono 16 bit 44100 sounds
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(40);  // set vol at 40

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

void loop() {
 // float vol = analogRead(15);
 // vol = vol / 10.24;
 // audioShield.volume(vol);
 // delay(20);
}
 

Attachments

  • TestfileRawGlitch.zip
    280.5 KB · Views: 178
Playing Raw sound file same as sketch in last post
I have also noticed that when I power the Teensy3.1 and audio shield from the PC USB and record the the audio output fron line jack using audacity I see a train of noise pulses in the other audacity channel. When zoomed in it shows a train of pulses 6 milliseconds apart and every 64th pulse is a group of 4 close together, this corresponds to 372 milliseconds between each group. ( 64 x 5.8 = 372 approx ). The audible glitch that I can hear in the sound happens at the first group of 4 pulses ie. 372 milliseconds. Actually 3 milliseconds after it. The other groups of pulses later, although there don't seem to cause any audible glitch. I have attached a mp3 recording and the PlaySdRaw sketch used is the same as previous PlaySdRaw code posted. I was wondering if anyone can tell me what these are as it might point to the source of what is causing the glitch in sound. Thanks.
 

Attachments

  • TestRawUsb1.zip
    290 KB · Views: 173
I've played and recorded a short raw sample here and the glitch always occurs at the same point near the beginning of the file. The glitch is a section of audio that is zero amplitude and its length corresponds to 64 samples. That is a bit strange because 64 samples is half an audio buffer - I would have expected a whole buffer to be missing (or perhaps my math is off).

Pete
 
In my previous message, the recording was done on the PC from the line output. I have created a new sketch which records the audio in the flash chip. That does not have the glitch. Curiouser.

Pete
 
Yes curious any suggestions wher I can read up.on the technical side of what's happening. I am not at bse today so.not testing today. From reading your post are you playing sound from the sdcard and recording to the sdcard usig a sketch to contol it. What I was doing was playing a sound file that I had previously played on audacity and foundit free of any glitches. I played the sound from the sdcard using the example sketch with the linr jack of the audio shield connected to the linein of the PC and used audacity to record the sound output fron the audio shield just same as using an oscilloscope. I think it gives a simple way of looking at what is happening. When I play the audacity recording iit souns same as listening to sound from the audio shield and if you zoom in you can see the waveform. I know my recordings are mp3 so not same quality as record wav. Iam on a tablet so excuse typing
 
In the first case I was playing a clean WAV file from the SD card to line out and then recording it on the PC with GoldWave. Goldwave showed the glitch as I described.
In this case I had uSD -> line out.
In the second case, I have a W25Q128FV flash chip which I soldered on the audio board and wrote some code for it. Then instead of playing the uSD file to line out, I played the WAV file into the code which records audio directly onto the flash chip. I could then play that audio back directly from the flash, or write it to uSD and then look at it on the PC. The flash file did not have a glitch.
In this case I had uSD -> flash.

Pete
 
Thanks el-supremo for your reply. At the moment I just want to play sound files and I was hoping direct from SDcard. I don't have the memory chip. So I assume I could copy the sound files from SDcard to memory and play direct from memory. The glitch using the SDcard is so small its a pity we cant find a way to find out what is causing it. The files play perfectly otherwise but its just the "beep beep" sound at the start of each file. and I have tried several sound files. I did some tests to try and find if it was playing the first part of the file twice, but its not doing that. It plays the first 186 milliseconds approx, then the glitch (zero amplitude as you say), then continues playing the rest of the file. I changed my test file to be a mix of sine and square tones for the first 180 milliseconds and then started the bit after 190 milliseconds with a sawtooth tone so I could see what is happening. I have attached a mp3 of the sound file played and a mp3 of the sound file output recorded. Would be grateful if anyone can give me some help or tell me where I can get info to read up on this.
 

Attachments

  • TestPlayFile.zip
    181.7 KB · Views: 190
It works.....I bought a new SDcard....Same make as the ones I had been using.....The new one is SanDisk Ultra Micro SD HC 16GB. The one I had been using was a 32 GB SanDisk Micro SD HC. All I did was Copy the sound files from the 32GB SDcard to the 16GB card and all worked. I didnt upload new program, just inserted the new SDcard. I don't get any glitch at 186 milliseconds (8192 samples). I do get a slight glitch at about 3 milliseconds after sound starts to play but unable to hear the glitch....so its OK. I can play the next sound files without using play.stop() in between......??????
 
Status
Not open for further replies.
Back
Top