你想做这样的事情吗?这会将所有存储的缓冲区聚合到一个缓冲区中。请注意,我确实有一个单独的缓冲区来存储索引;要么你可能不需要这个,要么理论上你可以将它打包到 fwBuffer 数组中的一个位置。
// Max number of data chunks
const unsigned maxBuffers = 1024;
// All the data stored here.
short int fwBuffer[1000000];
// how many data chunks we have
unsigned saveBufferCount = 0;
// Index to find each data chunk
// bufferIndex[saveBufferCount] points to where the next buffer will be placed (i.e. _after_ all the stored data).
short int* bufferIndex[maxBuffers] = {fwBuffer};
void storeBuffer(unsigned length, unsigned inchannels, short int* inbuffer)
{
short int *bufferIterator = bufferIndex[saveBufferCount];
// Could do a memcpy here.
int count = 0;
for (count = 0; count < length*inchannels; count++)
{
*bufferIterator++ = inbuffer[count];
}
++saveBufferCount;
bufferIndex[saveBufferCount] = bufferIterator;
}