White noise while playing two wav files simultaneously

Status
Not open for further replies.

mi-schi

Member
Here is my code:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=235,343
AudioPlaySdWav           playSdWav2;     //xy=268,400
AudioMixer4              mixer1;         //xy=661,111
AudioMixer4              mixer2;         //xy=684,186
AudioOutputI2S           i2s1;           //xy=836,267
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection          patchCord2(playSdWav1, 1, mixer2, 0);
AudioConnection          patchCord3(playSdWav2, 0, mixer1, 1);
AudioConnection          patchCord4(playSdWav2, 1, mixer2, 1);
AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
AudioConnection          patchCord6(mixer2, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=520,430
// GUItool: end automatically generated code

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   13

// 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

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

void setup() {
  Serial.begin(9600);
  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  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);
    }
  }
  mixer1.gain(0, 0.5);
  mixer1.gain(1, 0.5);
  mixer2.gain(0, 0.5);
  mixer2.gain(1, 0.5);
  delay(1000);
}

void loop() {
  if (playSdWav1.isPlaying() == false) {
    Serial.println("Start playing 1");
    playSdWav1.play("KICK1.WAV");
    delay(10); // wait for library to parse WAV info
  }
  if (playSdWav2.isPlaying() == false) {
    Serial.println("Start playing 2");
    playSdWav2.play("CLAP1.WAV");
    delay(10); // wait for library to parse WAV info
  }
}

It is the tutorial code with some changes, like other filenames, more AudioMemory, correct pins for teensy 4.0. Both wav files are correct. If I comment out the first if statement I hear a clap. If I comment out the second if statement I hear a kick. If the two wav files play simultaneously I have a white noise while the silent parts of the clap. The kick is not in rhythm. Does anyone have an idea why it doesn't work?
 

Attachments

  • wav-files.zip
    1.5 MB · Views: 51
Have you tried playing one of the samples from the PJRC website? They are stereo files. If the WaveFilePlayer example plays one of them without problems, it isn't likely that you have a hardware problem. OTOH, your code works here, so it doesn't look like a software problem either.

Pete
 
Maybe I found a problem: my to slow sd card class 10.
For simultaneous playing of 2, 3 or 4 stereo WAV files, many common "class 10" cards perform poorly. Even though they can support many megabytes per second in sequential access, they have high latency for non-sequential access.
source: https://www.pjrc.com/store/teensy3_audio.html

Here is the SD card test output:
SD Card Test
------------
SD card is connected :)
Card type is SDHC
File system space is 264.29 Mbytes.
SD library is able to access the filesystem

Reading SDTEST1.WAV:
Overall speed = 0.39 Mbyte/sec
Worst block time = 2.82 ms
97.30% of audio frame time

Reading SDTEST1.WAV & SDTEST2.WAV:
SDTEST2.WAV is too small for speed testing

Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV:
SDTEST3.WAV is too small for speed testing

Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 0.36 Mbyte/sec
Worst block time = 5.65 ms
194.63% of audio frame time

Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV staggered:
Overall speed = 0.36 Mbyte/sec
Worst block time = 5.65 ms
194.63% of audio frame time

I try to order a faster one.
 
Have you tried playing one of the samples from the PJRC website? They are stereo files. If the WaveFilePlayer example plays one of them without problems, it isn't likely that you have a hardware problem. OTOH, your code works here, so it doesn't look like a software problem either.

Pete

Ah, sorry, I forgot to answer: Thank you for the link, I've tried it but I have the same result. One file works, if I play two I have a white noise.
 
Status
Not open for further replies.
Back
Top