#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SPI.h>
// Create the Audio components. These should be created in the
AudioMixer4 mix1; // two 4-channel mixers are needed in
AudioMixer4 mix2; // tandem to combine 6 audio sources
// Create Audio connections between the components
AudioPlaySdRaw wav;
AudioPlaySdRaw wav2;
AudioPlaySdRaw wav3;
AudioPlaySdRaw wav4;
AudioPlaySdRaw wav5;
AudioOutputI2S dac;
// Create Audio connections between the components
// order data flows, inputs/sources -> processing -> outputs
AudioConnection c1(wav, 0, mix1, 0);
AudioConnection c2(wav2, 0, mix1, 1);
AudioConnection c3(wav3, 0, mix1, 2);
AudioConnection c4(wav4, 0, mix1, 3);
AudioConnection c5(wav5, 0, mix1, 4);
AudioConnection c6(mix1, 0, mix2, 0); // output of mix1 into 1st input on mix2
AudioConnection c7(mix1, 0, mix2, 1);
AudioConnection c8(mix1, 0, mix2, 2);
AudioConnection c9(mix1, 0, mix2, 3);
AudioConnection c10(mix1, 0, mix2, 4);
AudioConnection c11(mix2, 0, dac, 0);
//// Create the Audio components. These should be created in the
//// order data flows, inputs/sources -> processing -> outputs
////
//AudioPlaySdRaw 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
pinMode(25,OUTPUT); //pin to oscillate
AudioMemory(150);
audioShield.enable();
audioShield.volume(0.1);
SPI.setMOSI(7);
SPI.setSCK(14);
if (SD.begin(10)) {
//wav.play("01_16M.WAV");
}
}
void loop()
{
for (byte x = 20; x >0; x--)
{
oscillationWrite(25, 1000); //send start bit, actually first bit
delayMicroseconds(500); // wait
oscillationWrite(25, 500); //send start bit, actually first bit
delayMicroseconds(500); // wait
}
AudioProcessorUsageMaxReset();
delay(150);
wav.play("059AP.RAW");
delay(130);
wav2.play("059AP.RAW");
delay(125);
wav.play("059AP.RAW");
delay(120);
wav2.play("059AP.RAW");
Serial.println(AudioProcessorUsageMax());
}
void oscillationWrite(byte pin, int time)
{
for (byte i = 0; i < time / 26; i++) // time/26 = 38khz
{
digitalWrite(pin, HIGH);
delayMicroseconds(6);
digitalWrite(pin, LOW);
delayMicroseconds(20);
}
}