I'm receiving blocks of audio samples of varying length from a stream, and each block is a 1D ndarray. A block may be received every 50ms or less. I need to keep a buffer of the last 48000 samples
I've tried defining my buffer like this:
buffer = np.zeros([48000], dtype=np.float32)
Then in my receive block function:
buffer = np.concatenate([buffer,input_block])
buffer = np.delete(buffer,slice(0,np.size(input_block))
However this is too slow. I understand this is causing a resize and copy of array elements and is not optimal.
I've tried a variety of circular buffer implementations such as this and this however they are much slower - I'm not sure why.
Rather than concatenating each new input_block upon receipt I expect it would be more efficient at the point in time where I need to read from my buffer to concatenate a list of past input_blocks. There's a bit of complexity to doing this given the varying size of each block but it should be possible.
Is there another approach I should consider?