#include <Audio.h>
// define this macro to use the "normal"
// statically-created objects
//#define USE_STATIC
// GUItool: begin automatically generated code
#if defined(USE_STATIC)
AudioInputTDM tdmI; //xy=86,212
#endif // defined(USE_STATIC)
AudioSynthWaveform wav2; //xy=261,100
AudioSynthWaveform wav1; //xy=262,45
AudioMixer4 mixInL; //xy=262,173
AudioMixer4 mixInR; //xy=262,252
AudioSynthWaveform wav5; //xy=478,352
AudioSynthWaveform wav7; //xy=479,437
AudioSynthWaveform wav3; //xy=480,265
AudioSynthWaveform wav4; //xy=480,309
AudioSynthWaveform wav6; //xy=481,393
AudioMixer4 mixL; //xy=483,116
AudioMixer4 mixR; //xy=483,194
AudioSynthWaveform wav8; //xy=483,484
#if defined(USE_STATIC)
AudioOutputTDM tdmO; //xy=708,308
AudioConnection patchCord1(tdmI, 0, mixInL, 0);
AudioConnection patchCord2(tdmI, 2, mixInR, 0);
AudioConnection patchCord3(tdmI, 4, mixInL, 1);
AudioConnection patchCord4(tdmI, 6, mixInR, 1);
AudioConnection patchCord5(tdmI, 8, mixInL, 2);
AudioConnection patchCord6(tdmI, 10, mixInR, 2);
AudioConnection patchCord7(tdmI, 12, mixInL, 3);
AudioConnection patchCord8(tdmI, 14, mixInR, 3);
#endif // defined(USE_STATIC)
AudioConnection patchCord9(wav2, 0, mixR, 0);
AudioConnection patchCord10(wav1, 0, mixL, 0);
AudioConnection patchCord11(mixInL, 0, mixL, 1);
AudioConnection patchCord12(mixInR, 0, mixR, 1);
#if defined(USE_STATIC)
AudioConnection patchCord13(wav5, 0, tdmO, 8);
AudioConnection patchCord14(wav7, 0, tdmO, 12);
AudioConnection patchCord15(wav3, 0, tdmO, 4);
AudioConnection patchCord16(wav4, 0, tdmO, 6);
AudioConnection patchCord17(wav6, 0, tdmO, 10);
AudioConnection patchCord18(mixL, 0, tdmO, 0);
AudioConnection patchCord19(mixR, 0, tdmO, 2);
AudioConnection patchCord20(wav8, 0, tdmO, 14);
#endif // defined(USE_STATIC)
AudioControlCS42448 cs42448_1; //xy=699,458
// GUItool: end automatically generated code
//==========================================================
// Placeholders for audio objects to be created
// during setup()
#if !defined(USE_STATIC)
AudioInputTDM* tdmI; //xy=86,212
AudioOutputTDM* tdmO; //xy=708,308
AudioConnection* cords[16]; // 8 in, 8 out
#endif // !defined(USE_STATIC)
void createObjects(void)
{
#if !defined(USE_STATIC)
// create the TDM input and output objects
tdmI = new AudioInputTDM;
tdmO = new AudioOutputTDM;
// now create their connections
// note the use of *tdmI and *tdmO, as we have pointers to
// the TDM objects, not (references to) the objects themselves
int cordNum = 0;
cords[cordNum++] = new AudioConnection {*tdmI, 0, mixInL, 0 };
cords[cordNum++] = new AudioConnection {*tdmI, 2, mixInR, 0 };
cords[cordNum++] = new AudioConnection {*tdmI, 4, mixInL, 1 };
cords[cordNum++] = new AudioConnection {*tdmI, 6, mixInR, 1 };
cords[cordNum++] = new AudioConnection {*tdmI, 8, mixInL, 2 };
cords[cordNum++] = new AudioConnection {*tdmI, 10, mixInR, 2 };
cords[cordNum++] = new AudioConnection {*tdmI, 12, mixInL, 3 };
cords[cordNum++] = new AudioConnection {*tdmI, 14, mixInR, 3 };
cords[cordNum++] = new AudioConnection {wav5, 0, *tdmO, 8 };
cords[cordNum++] = new AudioConnection {wav7, 0, *tdmO, 12 };
cords[cordNum++] = new AudioConnection {wav3, 0, *tdmO, 4 };
cords[cordNum++] = new AudioConnection {wav4, 0, *tdmO, 6 };
cords[cordNum++] = new AudioConnection {wav6, 0, *tdmO, 10 };
cords[cordNum++] = new AudioConnection {mixL, 0, *tdmO, 0 };
cords[cordNum++] = new AudioConnection {mixR, 0, *tdmO, 2 };
cords[cordNum++] = new AudioConnection {wav8, 0, *tdmO, 14 };
#endif // !defined(USE_STATIC)
}
//==========================================================
#define NP 8
AudioSynthWaveform* w[]={&wav1, &wav2, &wav3, &wav4, &wav5, &wav6, &wav7, &wav8};
int p[] =
{
0b1000000000000, // I
0b1010000000000, // II
0b1010100000000, // III
0b1011100000000, // IV
0b1110000000000, // V
0b1110100000000, // VI
0b1110101000000, // VII
0b1110101010000, // VIII
};
bool on[NP];
int pmask;
int state;
void setup()
{
AudioMemory(32); // TDM uses many blocks!
// set up CS42448, before MCLK is started
delay(10); // not needed, useful for 'scope trace though
cs42448_1.enable();
cs42448_1.volume(0.5f);
cs42448_1.inputLevel(0.5f);
delay(10); // not needed, useful for 'scope trace though
pinMode(LED_BUILTIN,OUTPUT);
mixL.gain(0,0.5);
mixL.gain(1,0.5);
mixR.gain(0,0.5);
mixR.gain(1,0.5);
// create TDM objects, which will start MCLK
// does nothing if objects are statically-defined
createObjects();
}
void loop() {
pmask >>= 1;
if (0 == pmask)
{
pmask = p[0];
//Serial.println("beep!");
digitalToggle(LED_BUILTIN);
}
for (int i=0;i<NP;i++)
{
bool beep = (pmask & p[i]) != 0; // sounding this time?
bool chg = on[i] != beep;
if (chg) // need to change sound on this channel
{
if (beep)
w[i]->begin(0.9f,1000.0f,0);
else
w[i]->amplitude(0.0);
}
on[i] = beep;
}
if (Serial.available())
{
while (Serial.available())
Serial.read();
state++;
switch (state)
{
default:
state = 0;
break;
case 0:
Serial.println("mix");
mixL.gain(0,0.5);
mixL.gain(1,0.5);
mixR.gain(0,0.5);
mixR.gain(1,0.5);
break;
case 1:
Serial.println("waves");
mixL.gain(0,1.0);
mixL.gain(1,0.0);
mixR.gain(0,1.0);
mixR.gain(1,0.0);
break;
case 2:
Serial.println("inputs");
mixL.gain(0,0.0);
mixL.gain(1,1.0);
mixR.gain(0,0.0);
mixR.gain(1,1.0);
state = -1;
break;
}
}
delay(100);
}