Wrong DAC Output when playing 2 WAV files with Teensy 3.6

Status
Not open for further replies.

otti123

Member
Hello,

i am using Teensy 3.6, Arduino 1.84 and Teensyduino 1.39.

I have 2 short WAV files on an SD card Sandisk Ultra 16GB HC I and try to play these 2 WAV files at the same time.

One WAV file is played through DAC channel 0 and the other through DAC channel 1.

I get some blanks in the output from time to time ( 2-5 times OK, then bad output ).

Here is the Sketch:

Code:
#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playWav1;     //xy=547,467
AudioPlaySdWav           playWav2;     //xy=551,665
AudioOutputAnalogStereo  dac;          //xy=983,525
AudioConnection          patchCord1(playWav1, 0, dac, 0);
AudioConnection          patchCord2(playWav2, 0, dac, 1);
// GUItool: end automatically generated code

// Use these with the Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used
#define SDCARD_SCK_PIN   13  // not actually used

Bounce button0 = Bounce(0,10);  // 10 ms debounce time

void setup() {
  Serial.begin(9600);
  AudioMemory(10);

  pinMode(0, INPUT_PULLUP); 
    
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  dac.analogReference(INTERNAL);
}

void loop() {
  button0.update();
  if(button0.fallingEdge()) {
    playWav1.play("Pulse1.WAV");
    playWav2.play("HolzB.WAV");
  }
}
i have attached the scope pictures of the DAC output.

Good.gifError1.gifError2.gif

The first picture is how it should be. The second and third picture shows the problem.
The Yellow Pulse is about 4ms high and 4 ms low.
Sampling is 44100 Hz, 16 Bit Mono.

https://www.dropbox.com/s/330sdr8mzwea3d4/HolzB.wav?dl=0

https://www.dropbox.com/s/jdb6wsxua9usug5/Pulse1.wav?dl=0


I also tried this with Teensy 3.2 and mixing the 2 WAV files with mixer object. This setup works fine. Same setup with Teensy 3.6 gave the same problems.

What could be the problem ?
 
Last edited:
Please give this fix a try.

https://github.com/PaulStoffregen/Audio/commit/24c6b7e11e4ea67555d4836c6cd0899e598aa440

I just tested it. As nearly as I can tell, this fixes the problem. Please let me know if you still see it or anything else strange?

However, in your code you may wish to use this:

Code:
  AudioNoInterrupts();
  playWav1.play("Pulse1.WAV");
  playWav2.play("HolzB.WAV");
  AudioInterrupts();

If you don't use AudioNoInterrupts(), the audio library can update between the two function calls, which causes the 2nd waveform to be offset by 2.9 ms.
 
Hello Paul,

sorry that i do not respond earlier. I have currently no chance to test it. I will be back in office next wednesday for testing. I have short holiday and currently no audio board at home. I will reply as soon as i can.
 
again me. I found a Teensy 3.6 at home and setup the test hardware. I tested with latest Beta version and now it seems that it is working correct.
 
Dear Paul,

i use now Teensyduino 1.44 and arduino 1.87. I have same problem as last year although i see in "output_dacs.cpp" / line 192 the changes you made one year ago. And now i have same problem as before.

I have not tested it for the last year so i wonder what else could have changed.

Do you see any solution ?

Regards

Ottmar
 
When you say "have same problem", does that mean you're running the *exact* code from msg #1, using those 2 WAV files, and you're observing the exact same wrong waveforms on your oscilloscope?

If *anything* is different, I need you to be very specific exactly what code to run, which WAV files to use, and how to observe the problem.
 
When you say "have same problem", does that mean you're running the *exact* code from msg #1, using those 2 WAV files, and you're observing the exact same wrong waveforms on your oscilloscope?

If *anything* is different, I need you to be very specific exactly what code to run, which WAV files to use, and how to observe the problem.

Hello Paul,

yes, i am runninh exactly the same code as in msg1 with these 2 wav files and see the same wrong waveforms.

Regards, Ottmar
 
I cannot reproduce your problem on T3.6 1.8.5/1.42. Without Paul's suggested bracketing with AudioNoInterrupts();, I can see the waveform starts being offset by 2.9 ms occasionally. The best I could do was a bounce illustrated in the following
wbnc.png

What do you see if you remove the bounce logic in loop, and add a delay(40); in the loop(), so the wav's are played every 40 ms? do you see any glitches?

Of course, absence of proof is not proof of absence.

EDIT: also tested on 1.8.7/1.44 -- no glitches
 
Last edited:
I ran it here too on a Teensy 3.6 using Arduino 1.8.7 with Teensyduino 1.44. Touched a wire between pin 0 & GND dozens of times. Always the same correct result.

file.png
 
In File > Preferences, try turning on verbose output while compiling.

Arduino will print lots of info. Near the end is a summary of exactly which pathnames it's using for each library. Perhaps you have an old copy of the Audio library in a location like Documents/Arduino/libraries, which is overriding the good one that Teensyduino installs into hardware/teensy/avr/libraries inside Arduino 1.8.7.
 
In File > Preferences, try turning on verbose output while compiling.

Arduino will print lots of info. Near the end is a summary of exactly which pathnames it's using for each library. Perhaps you have an old copy of the Audio library in a location like Documents/Arduino/libraries, which is overriding the good one that Teensyduino installs into hardware/teensy/avr/libraries inside Arduino 1.8.7.

I will do that when i am at work. We want to use the Teensy 3.6 with build in SD Card interface instead of currently used Teensy 3.2.
I also wonder what happens, because i tried a year ago after the patch of Paul and it worked correct.

Thany you all for your super fast support.

Regards, Ottmar
 
I tested again and had a look to the compilation process. Everything OK. Then i changed the SD Card to a new one with exact the same type. Now it is functional. The older SD Card works with Teensy 3.2 SPI Interface without any problems. But with SDIO on Teensy 3.6 it has problems. Curious...

Regards and thanks for all the help, Ottmar
 
Status
Not open for further replies.
Back
Top