Code:

#include <Arduino.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "Arduino-Teensy-Codec-lib-master/play_sd_mp3.h"
// GUItool: begin automatically generated code
AudioPlaySdMp3 playSdWav1; //xy=174,103
AudioPlaySdMp3 playSdWav2; //xy=174,136
AudioPlaySdMp3 playSdWav3; //xy=174,169
AudioPlaySdMp3 playSdWav5; //xy=173.75000381469727,232.50000381469727
AudioPlaySdMp3 playSdWav4; //xy=175,201
AudioPlaySdMp3 playSdWav6; //xy=175.00000381469727,263.75000381469727
AudioPlaySdMp3 playSdWav7; //xy=175.00000381469727,297.5000057220459
AudioPlaySdMp3 playSdWav8; //xy=176.25,331.2500066757202
AudioPlaySdMp3 playSdWav9; //xy=176.25,365.00000762939453
AudioPlaySdMp3 playSdWav10; //xy=178.75,398.75000858306885
AudioPlaySdMp3 playSdWav11; //xy=178.75000381469727,431.25000953674316
AudioPlaySdMp3 playSdWav12; //xy=178.75,463.75000953674316
AudioPlaySdMp3 playSdWav13; //xy=177.5,495.00000762939453
AudioPlaySdMp3 playSdWav14; //xy=177.5,526.2500085830688
AudioPlaySdMp3 playSdWav15; //xy=177.50000381469727,556.2500095367432
AudioPlaySdMp3 playSdWav16; //xy=177.50000381469727,587.5000095367432
AudioPlaySdMp3 playSdWav17; //xy=177.50000381469727,618.7500095367432
AudioPlaySdMp3 playSdWav18; //xy=177.50000381469727,650.0000095367432
AudioPlaySdMp3 playSdWav19; //xy=177.5,681.2500104904175
AudioPlaySdMp3 playSdWav20; //xy=177.5,712.5000114440918
AudioPlaySdMp3 playSdWav21; //xy=177.5,743.7500123977661
AudioPlaySdMp3 playSdWav22; //xy=177.50000381469727,775.0000114440918
AudioPlaySdMp3 playSdWav23; //xy=177.5,806.2500123977661
AudioPlaySdMp3 playSdWav24; //xy=177.50000381469727,837.5000133514404
AudioPlaySdMp3 playSdWav25; //xy=175.00000381469727,870.0000133514404
AudioMixer4 mixer1; //xy=386,119
AudioMixer4 mixer2; //xy=387,182
AudioMixer4 mixer3; //xy=387,245
AudioMixer4 mixer4; //xy=388,307
AudioMixer4 mixer9; //xy=388,619
AudioMixer4 mixer5; //xy=389,370
AudioMixer4 mixer6; //xy=389,433
AudioMixer4 mixer7; //xy=389,495
AudioMixer4 mixer8; //xy=389,557
AudioMixer4 mixer10; //xy=389,680
AudioMixer4 mixer12; //xy=388.75000762939453,805.0000114440918
AudioMixer4 mixer11; //xy=389.50000381469727,742.0000114440918
AudioMixer4 mixer13; //xy=580.0000076293945,138.75000381469727
AudioMixer4 mixer14; //xy=580.0000076293945,201.25001907348633
AudioMixer4 mixer15; //xy=585.0000038146973,701.2500152587891
AudioMixer4 mixer16; //xy=587.5000076293945,637.5000076293945
AudioMixer4 mixer17; //xy=386,119
AudioMixer4 mixer18; //xy=387,182
AudioMixer4 mixer19; //xy=387,245
AudioMixer4 mixer20; //xy=388,307
AudioMixer4 mixer21; //xy=388,619
AudioMixer4 mixer22; //xy=389,370
AudioMixer4 mixer23; //xy=389,433
AudioMixer4 mixer24; //xy=389,495
AudioMixer4 mixer25; //xy=389,557
AudioMixer4 mixer26; //xy=389,680
AudioMixer4 mixer27; //xy=388.75000762939453,805.0000114440918
AudioMixer4 mixer28; //xy=389.50000381469727,742.0000114440918
AudioMixer4 mixer29; //xy=580.0000076293945,138.75000381469727
AudioMixer4 mixer30; //xy=580.0000076293945,201.25001907348633
AudioMixer4 mixer31; //xy=585.0000038146973,701.2500152587891
AudioMixer4 mixer32;
AudioAmplifier amp2; //xy=872.2500152587891,550
AudioAmplifier amp1; //xy=873.2500152587891,515
AudioOutputI2S i2s2_1; //xy=1002.2500152587891,531
AudioOutputTDM2 tdm1; //xy=1003.2500152587891,309
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(playSdWav3, 0, mixer1, 2);
AudioConnection patchCord6(playSdWav3, 1, mixer2, 2);
AudioConnection patchCord7(playSdWav5, 0, mixer3, 0);
AudioConnection patchCord8(playSdWav5, 1, mixer4, 0);
AudioConnection patchCord9(playSdWav4, 0, mixer1, 3);
AudioConnection patchCord10(playSdWav4, 1, mixer2, 3);
AudioConnection patchCord11(playSdWav6, 0, mixer3, 1);
AudioConnection patchCord12(playSdWav6, 1, mixer4, 1);
AudioConnection patchCord13(playSdWav7, 0, mixer3, 2);
AudioConnection patchCord14(playSdWav7, 1, mixer4, 2);
AudioConnection patchCord15(playSdWav8, 0, mixer3, 3);
AudioConnection patchCord16(playSdWav8, 1, mixer4, 3);
AudioConnection patchCord17(playSdWav9, 0, mixer5, 0);
AudioConnection patchCord18(playSdWav9, 1, mixer6, 0);
AudioConnection patchCord35(playSdWav10, 0, mixer5, 1);
AudioConnection patchCord36(playSdWav10, 1, mixer6, 1);
AudioConnection patchCord41(playSdWav11, 0, mixer5, 2);
AudioConnection patchCord42(playSdWav11, 1, mixer6, 2);
AudioConnection patchCord45(playSdWav12, 0, mixer5, 3);
AudioConnection patchCord46(playSdWav12, 1, mixer6, 3);
AudioConnection patchCord21(playSdWav13, 0, mixer7, 0);
AudioConnection patchCord22(playSdWav13, 1, mixer8, 0);
AudioConnection patchCord23(playSdWav14, 0, mixer7, 1);
AudioConnection patchCord24(playSdWav14, 1, mixer8, 1);
AudioConnection patchCord25(playSdWav15, 0, mixer7, 2);
AudioConnection patchCord26(playSdWav15, 1, mixer8, 2);
AudioConnection patchCord27(playSdWav16, 0, mixer7, 3);
AudioConnection patchCord28(playSdWav16, 1, mixer8, 3);
AudioConnection patchCord29(playSdWav17, 0, mixer9, 0);
AudioConnection patchCord30(playSdWav17, 1, mixer10, 0);
AudioConnection patchCord31(playSdWav18, 0, mixer9, 1);
AudioConnection patchCord32(playSdWav18, 1, mixer10, 1);
AudioConnection patchCord33(playSdWav19, 0, mixer9, 2);
AudioConnection patchCord34(playSdWav19, 1, mixer10, 2);
AudioConnection patchCord37(playSdWav20, 0, mixer9, 3);
AudioConnection patchCord38(playSdWav20, 1, mixer10, 3);
AudioConnection patchCord39(playSdWav21, 0, mixer11, 0);
AudioConnection patchCord40(playSdWav21, 1, mixer12, 0);
AudioConnection patchCord43(playSdWav22, 0, mixer11, 1);
AudioConnection patchCord44(playSdWav22, 1, mixer12, 1);
AudioConnection patchCord47(playSdWav23, 0, mixer11, 2);
AudioConnection patchCord48(playSdWav23, 1, mixer12, 2);
AudioConnection patchCord49(playSdWav24, 0, mixer11, 3);
AudioConnection patchCord50(playSdWav24, 1, mixer12, 3);
AudioConnection patchCord19(playSdWav25, 0, mixer16, 3);
AudioConnection patchCord20(playSdWav25, 1, mixer15, 3);
AudioConnection patchCord51(mixer1, 0, mixer13, 0);
AudioConnection patchCord52(mixer2, 0, mixer14, 0);
AudioConnection patchCord53(mixer3, 0, mixer13, 1);
AudioConnection patchCord54(mixer4, 0, mixer14, 1);
AudioConnection patchCord55(mixer9, 0, mixer16, 0);
AudioConnection patchCord56(mixer5, 0, mixer13, 2);
AudioConnection patchCord57(mixer6, 0, mixer14, 2);
AudioConnection patchCord58(mixer7, 0, mixer13, 3);
AudioConnection patchCord59(mixer8, 0, mixer14, 3);
AudioConnection patchCord60(mixer10, 0, mixer15, 0);
AudioConnection patchCord61(mixer12, 0, mixer15, 1);
AudioConnection patchCord62(mixer11, 0, mixer16, 1);
AudioConnection patchCord63(mixer13, 0, mixer16, 2);
AudioConnection patchCord64(mixer14, 0, mixer15, 2);
AudioConnection patchCord65(playSdWav1, 0, mixer17, 0);
AudioConnection patchCord66(playSdWav1, 1, mixer18, 0);
AudioConnection patchCord67(playSdWav2, 0, mixer17, 1);
AudioConnection patchCord68(playSdWav2, 1, mixer18, 1);
AudioConnection patchCord69(playSdWav3, 0, mixer17, 2);
AudioConnection patchCord70(playSdWav3, 1, mixer18, 2);
AudioConnection patchCord71(playSdWav5, 0, mixer19, 0);
AudioConnection patchCord72(playSdWav5, 1, mixer20, 0);
AudioConnection patchCord73(playSdWav4, 0, mixer17, 3);
AudioConnection patchCord74(playSdWav4, 1, mixer18, 3);
AudioConnection patchCord75(playSdWav6, 0, mixer19, 1);
AudioConnection patchCord76(playSdWav6, 1, mixer20, 1);
AudioConnection patchCord77(playSdWav7, 0, mixer19, 2);
AudioConnection patchCord78(playSdWav7, 1, mixer20, 2);
AudioConnection patchCord79(playSdWav8, 0, mixer19, 3);
AudioConnection patchCord80(playSdWav8, 1, mixer20, 3);
AudioConnection patchCord81(playSdWav9, 0, mixer21, 0);
AudioConnection patchCord82(playSdWav9, 1, mixer22, 0);
AudioConnection patchCord83(playSdWav10, 0, mixer21, 1);
AudioConnection patchCord84(playSdWav10, 1, mixer22, 1);
AudioConnection patchCord85(playSdWav11, 0, mixer21, 2);
AudioConnection patchCord86(playSdWav11, 1, mixer22, 2);
AudioConnection patchCord87(playSdWav12, 0, mixer21, 3);
AudioConnection patchCord88(playSdWav12, 1, mixer22, 3);
AudioConnection patchCord89(playSdWav13, 0, mixer23, 0);
AudioConnection patchCord90(playSdWav13, 1, mixer24, 0);
AudioConnection patchCord91(playSdWav14, 0, mixer23, 1);
AudioConnection patchCord92(playSdWav14, 1, mixer24, 1);
AudioConnection patchCord93(playSdWav15, 0, mixer23, 2);
AudioConnection patchCord94(playSdWav15, 1, mixer24, 2);
AudioConnection patchCord95(playSdWav16, 0, mixer23, 3);
AudioConnection patchCord96(playSdWav16, 1, mixer24, 3);
AudioConnection patchCord97(playSdWav17, 0, mixer25, 0);
AudioConnection patchCord98(playSdWav17, 1, mixer26, 0);
AudioConnection patchCord99(playSdWav18, 0, mixer25, 1);
AudioConnection patchCord100(playSdWav18, 1, mixer26, 1);
AudioConnection patchCord101(playSdWav19, 0, mixer25, 2);
AudioConnection patchCord102(playSdWav19, 1, mixer26, 2);
AudioConnection patchCord103(playSdWav20, 0, mixer25, 3);
AudioConnection patchCord104(playSdWav20, 1, mixer26, 3);
AudioConnection patchCord105(playSdWav21, 0, mixer27, 0);
AudioConnection patchCord106(playSdWav21, 1, mixer28, 0);
AudioConnection patchCord107(playSdWav22, 0, mixer27, 1);
AudioConnection patchCord108(playSdWav22, 1, mixer28, 1);
AudioConnection patchCord109(playSdWav23, 0, mixer27, 2);
AudioConnection patchCord110(playSdWav23, 1, mixer28, 2);
AudioConnection patchCord111(playSdWav24, 0, mixer27, 3);
AudioConnection patchCord112(playSdWav24, 1, mixer28, 3);
AudioConnection patchCord113(playSdWav25, 0, mixer32, 3);
AudioConnection patchCord114(playSdWav25, 1, mixer31, 3);
AudioConnection patchCord115(mixer17, 0, mixer29, 0);
AudioConnection patchCord116(mixer18, 0, mixer30, 0);
AudioConnection patchCord117(mixer19, 0, mixer29, 1);
AudioConnection patchCord118(mixer20, 0, mixer30, 1);
AudioConnection patchCord119(mixer25, 0, mixer32, 0);
AudioConnection patchCord120(mixer21, 0, mixer29, 2);
AudioConnection patchCord121(mixer22, 0, mixer30, 2);
AudioConnection patchCord122(mixer23, 0, mixer29, 3);
AudioConnection patchCord123(mixer24, 0, mixer30, 3);
AudioConnection patchCord124(mixer26, 0, mixer31, 0);
AudioConnection patchCord6125(mixer28, 0, mixer31, 1);
AudioConnection patchCord126(mixer27, 0, mixer32, 1);
AudioConnection patchCord127(mixer29, 0, mixer32, 2);
AudioConnection patchCord6128(mixer30, 0, mixer31, 2);
AudioConnection patchCord129(mixer15, 0, tdm1, 0);
AudioConnection patchCord130(mixer16, 0, tdm1, 1);
AudioConnection patchCord131(mixer31, 0, amp1, 0);
AudioConnection patchCord132(mixer32, 0, amp2, 0);
AudioConnection patchCord133(amp2, 0, i2s2_1, 1);
AudioConnection patchCord134(amp1, 0, i2s2_1, 0);
// GUItool: end automatically generated code
void playing()
{
if (!playSdWav1.isPlaying())
{
playSdWav1.play("01.mp3");
// playSdWav1.("01.mp3");
delayMicroseconds(10);
}
if (!playSdWav2.isPlaying())
{
playSdWav2.play("02.mp3");
delayMicroseconds(1);
}
}
void muteAll()
{
mixer17.gain(0, 0.0);
mixer17.gain(1, 0.0);
mixer17.gain(2, 0.0);
mixer17.gain(3, 0.0);
mixer18.gain(0, 0.0);
mixer18.gain(1, 0.0);
mixer18.gain(2, 0.0);
mixer18.gain(3, 0.0);
mixer19.gain(0, 0.0);
mixer19.gain(1, 0.0);
mixer19.gain(2, 0.0);
mixer19.gain(3, 0.0);
mixer20.gain(0, 0.0);
mixer20.gain(1, 0.0);
mixer20.gain(2, 0.0);
mixer20.gain(3, 0.0);
mixer21.gain(0, 0.0);
mixer21.gain(1, 0.0);
mixer21.gain(2, 0.0);
mixer21.gain(3, 0.0);
mixer22.gain(0, 0.0);
mixer22.gain(1, 0.0);
mixer22.gain(2, 0.0);
mixer22.gain(3, 0.0);
mixer23.gain(0, 0.0);
mixer23.gain(1, 0.0);
mixer23.gain(2, 0.0);
mixer23.gain(3, 0.0);
mixer24.gain(0, 0.0);
mixer24.gain(1, 0.0);
mixer24.gain(2, 0.0);
mixer24.gain(3, 0.0);
mixer25.gain(0, 0.0);
mixer25.gain(1, 0.0);
mixer25.gain(2, 0.0);
mixer25.gain(3, 0.0);
mixer26.gain(0, 0.0);
mixer26.gain(1, 0.0);
mixer26.gain(2, 0.0);
mixer26.gain(3, 0.0);
mixer27.gain(0, 0.0);
mixer27.gain(1, 0.0);
mixer27.gain(2, 0.0);
mixer27.gain(3, 0.0);
mixer28.gain(0, 0.0);
mixer28.gain(1, 0.0);
mixer28.gain(2, 0.0);
mixer28.gain(3, 0.0);
mixer31.gain(3, 0.0);
mixer32.gain(3, 0.0);
}
void switching()
{
static byte count = 0;
static unsigned long timer = millis();
if ((millis() - timer) > 10000)
{
muteAll();
switch (count)
{
case 0:
mixer17.gain(0, 1.0);
mixer18.gain(0, 1.0);
break;
case 1:
mixer17.gain(1, 1.0);
mixer18.gain(1, 1.0);
break;
default:
break;
}
count++;
if (count >= 2)
count = 0;
timer = millis();
}
}
void setup()
{
AudioMemory(1000);
Serial.begin(9600);
again:
if (!(SD.begin(BUILTIN_SDCARD)))
{
// stop here, but print a message repetitively
while (1)
{
Serial.println("Unable to access the SD card");
delay(500);
goto again;
}
}
amp1.gain(0.3);
amp2.gain(0.3);
muteAll();
Serial.println("\n\n MemUse \t MaxMemUse \t CPUuse \t MaxCPUuse");
}
void loop()
{
static unsigned long timer = millis();
playing();
switching();
if ((millis() - timer) > 500)
{
Serial.print("\n MemUse " + String(AudioMemoryUsage()));
Serial.print("\t MaxMemUse " + String(AudioMemoryUsageMax()));
Serial.print("\t CPUuse " + String(AudioProcessorUsage()));
Serial.print("\t MaxCPUuse " + String(AudioProcessorUsageMax()));
Serial.print("\t Time_1 " + String(playSdWav1.positionMillis()));
Serial.println("\t Time_2 " + String(playSdWav2.positionMillis()));
AudioMemoryUsageMaxReset();
AudioProcessorUsageMaxReset();
timer = millis();
}
}