#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SerialFlash.h>
//TDM1
//Zasilanie mikrofonów 3,3V
//Pin 20 - FS - Output
//Pin 8 - SD - Input
//Pin 21 - BCLK - Output 11,3 MHz - SCK
//Pin 23 - MCLK - Outpit 22,6 MHz
//TDM2
//Pin 4 - BCLK - Output 11,3 MHz - SCK
//Pin 23 - MCLK - Output 22,6 MHz
//Pin 5 - SD - Input
//Pin 3 FS - Output
//Kod wygenerowany przy użyciu Audio System Design Tool
// GUItool: begin automatically generated code
//TDM1
AudioInputTDM tdm1;
AudioRecordQueue queue1;
AudioRecordQueue queue2;
AudioRecordQueue queue3;
AudioRecordQueue queue4;
AudioRecordQueue queue5;
AudioRecordQueue queue6;
AudioRecordQueue queue7;
AudioRecordQueue queue8;
AudioRecordQueue queue9;
AudioRecordQueue queue10;
AudioRecordQueue queue11;
AudioRecordQueue queue12;
AudioRecordQueue queue13;
AudioRecordQueue queue14;
AudioRecordQueue queue15;
AudioRecordQueue queue16;
//TDM2
AudioInputTDM2 tdm2_1;
AudioRecordQueue queue17;
AudioRecordQueue queue18;
//TDM1
AudioConnection patchCord1(tdm1, 0, queue1, 0);
AudioConnection patchCord2(tdm1, 1, queue2, 0);
AudioConnection patchCord3(tdm1, 2, queue3, 0);
AudioConnection patchCord4(tdm1, 3, queue4, 0);
AudioConnection patchCord5(tdm1, 4, queue5, 0);
AudioConnection patchCord6(tdm1, 5, queue6, 0);
AudioConnection patchCord7(tdm1, 6, queue7, 0);
AudioConnection patchCord8(tdm1, 7, queue8, 0);
AudioConnection patchCord9(tdm1, 8, queue9, 0);
AudioConnection patchCord10(tdm1, 9, queue10, 0);
AudioConnection patchCord11(tdm1, 10, queue11, 0);
AudioConnection patchCord12(tdm1, 11, queue12, 0);
AudioConnection patchCord13(tdm1, 12, queue13, 0);
AudioConnection patchCord14(tdm1, 13, queue14, 0);
AudioConnection patchCord15(tdm1, 14, queue15, 0);
AudioConnection patchCord16(tdm1, 15, queue16, 0);
//TDM2
AudioConnection patchCord17(tdm2_1, 0, queue17, 0);
AudioConnection patchCord18(tdm2_1, 1, queue18, 0);
// GUItool: end automatically generated code
//M1
int16_t* mic1A;
int16_t* mic1B;
//M2
int16_t* mic2A;
int16_t* mic2B;
//M3
int16_t* mic3A;
int16_t* mic3B;
//M4
int16_t* mic4A;
int16_t* mic4B;
//M5
int16_t* mic5A;
int16_t* mic5B;
//M6
int16_t* mic6A;
int16_t* mic6B;
//M7
int16_t* mic7A;
int16_t* mic7B;
//M8
int16_t* mic8A;
int16_t* mic8B;
//M9
int16_t* mic9A;
int16_t* mic9B;
bool f1;
bool f2;
bool f3;
bool f4;
bool f5;
bool f6;
bool f7;
bool f8;
bool f9;
bool newLine;
int finalSignal1;
int finalSignal2;
int finalSignal3;
int finalSignal4;
int finalSignal5;
int finalSignal6;
int finalSignal7;
int finalSignal8;
int finalSignal9;
void setup() {
//Ustawienia
Serial.begin(9600);
AudioMemory(512);
queue1.begin();
queue2.begin();
queue3.begin();
queue4.begin();
queue5.begin();
queue6.begin();
queue7.begin();
queue8.begin();
queue9.begin();
queue10.begin();
queue11.begin();
queue12.begin();
queue13.begin();
queue14.begin();
queue15.begin();
queue16.begin();
queue17.begin();
queue18.begin();
}
void loop() {
//Mikrofon 1
if(queue1.available() > 0)
{
mic1A = queue1.readBuffer();
queue1.freeBuffer();
f1 = true;
}
if(queue2.available() > 0)
{
mic1B = queue2.readBuffer();
queue2.freeBuffer();
if(f1) {
finalSignal1 = mic1A[0]*256 + mic1B[0]/256;
}
}
//Mikrofon 2
if(queue3.available() > 0)
{
mic2A = queue3.readBuffer();
queue3.freeBuffer();
f2 = true;
}
if(queue4.available() > 0)
{
mic2B = queue4.readBuffer();
queue4.freeBuffer();
if(f2)
{
finalSignal2 = mic2A[0]*256 + mic2B[0]/256;
}
}
//Mikrofon 3
if(queue5.available() > 0)
{
mic3A = queue5.readBuffer();
queue5.freeBuffer();
f3 = true;
}
if(queue6.available() > 0)
{
mic3B = queue6.readBuffer();
queue6.freeBuffer();
if(f3)
{
finalSignal3 = mic3A[0]*256 + mic3B[0]/256;
}
}
//Mikrofon 4
if(queue7.available() > 0)
{
mic4A = queue7.readBuffer();
queue7.freeBuffer();
f4 = true;
}
if(queue8.available() > 0)
{
mic4B = queue8.readBuffer();
queue8.freeBuffer();
if(f4)
{
finalSignal4 = mic4A[0]*256 + mic4B[0]/256;
}
}
//Mikrofon 5
if(queue9.available() > 0)
{
mic5A = queue9.readBuffer();
queue9.freeBuffer();
f5 = true;
}
if(queue10.available() > 0)
{
mic5B = queue10.readBuffer();
queue10.freeBuffer();
if(f5)
{
finalSignal5 = mic5A[0]*256 + mic5B[0]/256;
}
}
//Mikrofon 6
if(queue11.available() > 0)
{
mic6A = queue11.readBuffer();
queue11.freeBuffer();
f6 = true;
}
if(queue12.available() > 0)
{
mic6B = queue12.readBuffer();
queue12.freeBuffer();
if(f6)
{
finalSignal6 = mic6A[0]*256 + mic6B[0]/256;
}
}
//Mikrofon 7
if(queue13.available() > 0)
{
mic7A = queue13.readBuffer();
queue13.freeBuffer();
f7 = true;
}
if(queue14.available() > 0)
{
mic7B = queue14.readBuffer();
queue14.freeBuffer();
if(f7)
{
finalSignal7 = mic7A[0]*256 + mic7B[0]/256;
}
}
//Mikrofon 8
if(queue15.available() > 0)
{
mic8A = queue15.readBuffer();
queue15.freeBuffer();
f8 = true;
}
if(queue16.available() > 0)
{
mic8B = queue16.readBuffer();
queue16.freeBuffer();
if(f8)
{
finalSignal8 = mic8A[0]*256 + mic8B[0]/256;
}
}
//Mikrofon 8
if(queue17.available() > 0)
{
mic9A = queue17.readBuffer();
queue17.freeBuffer();
f9 = true;
}
if(queue18.available() > 0)
{
mic9B = queue18.readBuffer();
queue18.freeBuffer();
if(f9)
{
finalSignal9 = mic9A[0]*256 + mic9B[0]/256;
}
}
if(f1 && f2 && f3 && f4 && f5 && f6 && f7 && f8 && f9)
{
Serial.print(finalSignal1);
Serial.print(" ");
Serial.print(finalSignal2);
Serial.print(" ");
Serial.print(finalSignal3);
Serial.print(" ");
Serial.print(finalSignal4);
Serial.print(" ");
Serial.print(finalSignal5);
Serial.print(" ");
Serial.print(finalSignal6);
Serial.print(" ");
Serial.print(finalSignal7);
Serial.print(" ");
Serial.print(finalSignal8);
Serial.print(" ");
Serial.print(finalSignal9);
Serial.println(" "); //Nowy wiersz danych
f1 = false;
f2 = false;
f3 = false;
f4 = false;
f5 = false;
f6 = false;
f7 = false;
f8 = false;
f9 = false;
}
if(newLine) {
Serial.println(" ");
newLine = false;
}
}