I have been working on an audio recorder with teensy. Mono works fine, and I have WAV header writing sorted too. Just trying to write a stereo version.
In a stereo audio file the samples are interleaved like this: LeftSampleRightSampleLeftSampleRightSampleLeftSampleRightSample etc. But the queue object returns 128 sample blocks. I have tried interleaving the samples using two queue objects, reading blocks into two left/right buffer arrays and then using a loop to combine these arrays one sample at a time. This works, but is too slow.
I just saw that there is an object memcpy_tointerleaveLR() in the library. This seems to be used internally to interleave audio streams for the I2s output, but would it be possible to use this to interleave buffers like this:
I have tried this, and the code only works if the buffer array is int16_t, but the SD library only writes bytes. Then tried this:
which compiles and runs, but records a digital glitch, not audio.
I'm not sure how to debug this, can anyone help?
James
In a stereo audio file the samples are interleaved like this: LeftSampleRightSampleLeftSampleRightSampleLeftSampleRightSample etc. But the queue object returns 128 sample blocks. I have tried interleaving the samples using two queue objects, reading blocks into two left/right buffer arrays and then using a loop to combine these arrays one sample at a time. This works, but is too slow.
I just saw that there is an object memcpy_tointerleaveLR() in the library. This seems to be used internally to interleave audio streams for the I2s output, but would it be possible to use this to interleave buffers like this:
Code:
int16_t bufferLR[256];
memcpy_tointerleaveLR(bufferLR,queue1.readBuffer(),queue2.readBuffer());
I have tried this, and the code only works if the buffer array is int16_t, but the SD library only writes bytes. Then tried this:
Code:
byte SDbuffer[512];
memcpy(SDbuffer,bufferLR,512);
which compiles and runs, but records a digital glitch, not audio.
I'm not sure how to debug this, can anyone help?
James