I'm writing a TDM 8x8 matrix mixer.
The basic pattern is
All goes well up to 4 replications of the Mixer 1-2-3 pattern. Any higher number (I've tested 5, 6 & 8), produces an output (green trace) like this:
Here's the code:
Output is as follows, so I'm not running out of CPU or AudioMemory.
...
137: proc 1, mem 21, gain 0.43, peak1 0.54, peak2 0.25
138: proc 1, mem 21, gain 0.81, peak1 0.54, peak2 0.23
139: proc 1, mem 10, gain 0.77, peak1 0.54, peak2 0.44
...
The basic pattern is
All goes well up to 4 replications of the Mixer 1-2-3 pattern. Any higher number (I've tested 5, 6 & 8), produces an output (green trace) like this:
Here's the code:
Code:
/*
* 8 channels TDM into matrix of 8 x 2 4-channel mixers
* Down mix to 8 single output channels to TDM outs
*/
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#define MIXRS 5
#define CHANS 8
#define ABLOX 36
AudioMixer4 Amixer[MIXRS][2]; // pairs of 4 input Amixers, summed by a Bmixer
AudioMixer4 Bmixer[MIXRS]; // mix down pairs of Amixers
AudioConnection * Apatch[MIXRS][CHANS]; // TDM to Amixers
AudioConnection * Bpatch[MIXRS][2]; // Amixers to Bmixers
AudioConnection * Cpatch[MIXRS]; // Bmixers to outputs. Insert tone/FX here.
AudioInputTDM TDM_in;
AudioOutputTDM TDM_out;
AudioControlCS42448 cs42448_1;
AudioAnalyzePeak peak1, peak2;
AudioConnection p1(TDM_in, 0, peak1, 0);
AudioConnection p2(Bmixer[0], 0, peak2, 0);
void setup() {
// put your setup code here, to run once:
AudioMemory(ABLOX);
Serial.begin(115200);
delay(1000);
Serial.println("Starting T4 TDM multi mixer test");
for(int i = 0; i < MIXRS; i++)
{
for(int j = 0; j < CHANS; j++)
{
// set up TDM to A mixer patches - only every second TDM in/out is used
if(j < CHANS/2)
{
Apatch[i][j] = new AudioConnection(TDM_in, i*2, Amixer[i][0], i);
Amixer[i][0].gain(j, 1.0); // unity gain for the mixer channel
}
else // second half TDM go to the other Amixer in the pair
{
Apatch[i][j] = new AudioConnection(TDM_in, i*2, Amixer[i][1], i - CHANS/2);
Amixer[i][1].gain(j, 1.0); // unity gain for the mixer channel
}
}
// pacth Amixers to Bmixers
Bpatch[i][0] = new AudioConnection(Amixer[i][0], 0, Bmixer[i], 0);
Bpatch[i][1] = new AudioConnection(Amixer[i][1], 0, Bmixer[i], 1);
Bmixer[i].gain(0, 1.0); // unity gain for the mixer channel
Bmixer[i].gain(1, 1.0);
// Bmixers to TDM outputs
Cpatch[i] = new AudioConnection(Bmixer[i], 0, TDM_out, i*2);
}
Serial.println("Done setup");
}
uint32_t loops;
void loop() {
float Again = 1.0;
int procUse = AudioProcessorUsageMax();
AudioProcessorUsageMaxReset();
int memUse = AudioMemoryUsage();
float peakA = peak1.read();
float peakB = peak2.read();
Again = (float)random(200, 1000) / 1000.0; // gain 0.2 .. 1.0
Amixer[0][0].gain(0, Again); // vary gain for mixer channel 0
Serial.printf("%i: proc %i, mem %i, gain %3.2f, peak1 %3.2f, peak2 %3.2f\n",loops, procUse, memUse, Again, peakA, peakB);
delay(5000);
loops++;
}
Output is as follows, so I'm not running out of CPU or AudioMemory.
...
137: proc 1, mem 21, gain 0.43, peak1 0.54, peak2 0.25
138: proc 1, mem 21, gain 0.81, peak1 0.54, peak2 0.23
139: proc 1, mem 10, gain 0.77, peak1 0.54, peak2 0.44
...