So this code works. It shouldn't, but it does. (Friend wrote it, acchmm). I just find it amusing how broken it is that it seems to fix itself.
The SAI's are in 16bit extended.
The for loop is nuts. There are not 8 16bit ints there. There are 8 8bit ints. Yet it works. In fact a whole bunch of different viarities work also.
for (int i = 0; i < 8; i+=4)
Is my favourite.
for (int i = 0; i < 2; i++) // Nope , not even with a int32_t buffer.
for (int i = 0; i < 4; i++) // Nope
for (int i = 0; i < 8; i++) // YES
for (int i = 0; i < 8; i+=2) // YES
for (int i = 0; i < 8; i+=4) // YES
I think it's just lucky word alignment.
int16_t buffer[8];
float gain = 0.75f;
while (1) {
HAL_SAI_Receive(&hsai_BlockA1, (uint8_t*) buffer, 8, 10);
for (int i = 0; i < 8; i++) {
double sample = buffer[i];
sample = sample * gain; // pre-gain
sample = PeakFilter_Update(&bassBoost, sample);
sample = PeakFilter_Update(&midCut, sample);
sample = PeakFilter_Update(&highBoost, sample);
buffer[i] = (int16_t) sample;
}
HAL_SAI_Transmit(&hsai_BlockA2, (uint8_t*) buffer, 8, 10);
}
EDIT: I'm laughing at myself but this is a classic example. Classic. Your code works first time. "That was easy". Never pay any attention. "Some time later...", "That doesn't look right... I'll take a look...."
"Wait. How does this work? How did this ever work? What the hell?"
No... I'm not looking for help to fix it. I can see a symetry of problems that if fixes will make it make sense, but I just found it funny. Symmetrical insanity just happens to work.
EDIT2: Oh and it has many other issues to boot.