Hi,
I want to play 6 audio files simultaneously, raw format, from the sd card. When the button is pressed, the audio should play.
--> When I plug in the Teensy, I have complete silence. No pop, crackle or anything. Help.
Set-up:
- 6 working buttons
- Teensy 3.2 & audio board
- Check the raw files here:
https://cloud.constantvzw.org/s/TzpRFmioY7sxC5Q
As a zip file: https://cloud.constantvzw.org/remote.php/webdav/wvw/Teensy_raw_player/raw_files_sketch.zip
- the buttons, sd card worked perfectly with another sketch (to make the microphone record raw files)
- sketch was written, based on the example sample player for raw files from the teensy's internal memory (as I want my sounds to come from a microphone recording, this is not possible)
--> This thread has been reposted as the previous was written in a hurry, full of typo's.
Thanks - I'm still learning to code. This is for a community project with weaving..
Dywen
I want to play 6 audio files simultaneously, raw format, from the sd card. When the button is pressed, the audio should play.
--> When I plug in the Teensy, I have complete silence. No pop, crackle or anything. Help.
Set-up:
- 6 working buttons
- Teensy 3.2 & audio board
- Check the raw files here:
https://cloud.constantvzw.org/s/TzpRFmioY7sxC5Q
As a zip file: https://cloud.constantvzw.org/remote.php/webdav/wvw/Teensy_raw_player/raw_files_sketch.zip
- the buttons, sd card worked perfectly with another sketch (to make the microphone record raw files)
- sketch was written, based on the example sample player for raw files from the teensy's internal memory (as I want my sounds to come from a microphone recording, this is not possible)
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioPlaySdRaw sound0; //xy=319,114
AudioPlaySdRaw sound1; //xy=320,160
AudioPlaySdRaw sound2; //xy=324,211
AudioPlaySdRaw sound3; //xy=331,255
AudioPlaySdRaw sound4; //xy=333,300
AudioPlaySdRaw sound5; //xy=341,350
AudioMixer4 mix1; // two 4-channel mixers are needed in
AudioMixer4 mix2; // tandem to combine 6 audio sources
AudioOutputI2S headphones; //xy=909,159
AudioOutputAnalog dac; // play to both I2S audio board and on-chip DAC
// Create Audio connections between the components
//
AudioConnection patchCord1(sound0, 0, mix1, 0);
AudioConnection patchCord2(sound1, 0, mix1, 1);
AudioConnection patchCord3(sound2, 0, mix1, 2);
AudioConnection patchCord4(sound3, 0, mix1, 3);
AudioConnection patchCord5(sound4, 0, mix2, 1);
AudioConnection patchCord6(sound5, 0, mix2, 2);
AudioConnection patchCord7(mix1, 0, mix2, 0); // output of mix1 into 1st input on mix2
AudioConnection patchCord8(mix2, 0, headphones, 0);
AudioConnection patchCord9(mix2, 0, headphones, 1);
AudioConnection patchCord10(mix2, dac);
// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield; //xy=341,471
// Bounce objects to read six pushbuttons (pins 0-5)
//
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 ms debounce time
Bounce button2 = Bounce(2, 5);
Bounce button3 = Bounce(3, 5);
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);
void setup() {
Serial.begin(115200);
// Configure the pushbutton pins for pullups.
// Each button should connect from the pin to GND.
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(10);
// turn on the output
audioShield.enable();
audioShield.volume(0.5);
// by default the Teensy 3.1 DAC uses 3.3Vp-p output
// if your 3.3V power has noise, switching to the
// internal 1.2V reference can give you a clean signal
// dac.analogReference(INTERNAL);
// reduce the gain on mixer channels, so more than 1
// sound can play simultaneously without clipping
mix1.gain(0, 0.4);
mix1.gain(1, 0.4);
mix1.gain(2, 0.4);
mix1.gain(3, 0.4);
mix2.gain(1, 0.4);
mix2.gain(2, 0.4);
}
void loop() {
// Update all the button objects
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
// When the buttons are pressed, just start a sound playing.
// The audio library will play each sound through the mixers
// so any combination can play simultaneously.
//
if (button0.fallingEdge()) {
Serial.println("Button 0 is pressed");
sound0.play("sound0.RAW");
}
if (button1.fallingEdge()) {
Serial.println("Button 1 is pressed");
sound1.play("sound1.RAW");
}
if (button2.fallingEdge()) {
Serial.println("Button 2 is pressed");
sound2.play("sound2.RAW");
}
if (button3.fallingEdge()) {
Serial.println("Button 3 is pressed");
sound3.play("sound3.RAW");
}
if (button4.fallingEdge()) {
Serial.println("Button 4 is pressed");
sound4.play("sound4.RAW");
}
if (button5.fallingEdge()) {
Serial.println("Button 5 is pressed");
sound5.play("sound5.RAW");
}
}
--> This thread has been reposted as the previous was written in a hurry, full of typo's.
Thanks - I'm still learning to code. This is for a community project with weaving..
Dywen
Last edited: