Here is my code:
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?
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?