DIYLAB
Well-known member
Hello all,
I have some modules for audio visualization, one of them is a goniometer.
That gets its data from audio samples for the left and right channel. There are 2x 16 blocks each, so 2x 2048 samples.
This takes time, a lot of time :/
In the loop, the blocks are read one after the other:
I am looking for the best way to get the samples without the program waiting so long.
Would a circular buffer be the solution?
So always push the blocks one after the other into the circular buffer?
How do you do that?
I am very grateful for any suggestions!
Kind regards
DIYLAB
I have some modules for audio visualization, one of them is a goniometer.
That gets its data from audio samples for the left and right channel. There are 2x 16 blocks each, so 2x 2048 samples.
This takes time, a lot of time :/
Code:
short samplesLeft[2048];
short samplesRight[2048];
In the loop, the blocks are read one after the other:
Code:
/// <summary>
/// Get samples for left and right channel.
/// </summary>
void getSamples(byte blocks) {
if (queue1.available() >= blocks && queue2.available() >= blocks) {
for (byte i = 0; i < blocks; i++) {
memcpy(&samplesLeft[128 * i], queue1.readBuffer(), 256);
memcpy(&samplesRight[128 * i], queue2.readBuffer(), 256);
queue1.freeBuffer();
queue2.freeBuffer();
}
}
}
I am looking for the best way to get the samples without the program waiting so long.
Would a circular buffer be the solution?
So always push the blocks one after the other into the circular buffer?
How do you do that?
I am very grateful for any suggestions!
Kind regards
DIYLAB