0

I am working on an app in Android with purely C/C++ and the app needs to record sound continuously and process the data synchronously, so I'm wondering when I use buffer-queue in the openSL to record sound, whether I can release the ones that are filled and en-queue new empty ones in the buffer-queue?

I have consider the solution to clear the whole buffer-queue when all the buffers are filled and re-en-queue the new ones by using callback, but I'm afraid that this process may take some time and I will lose the data during the time.

InnocentKiller
  • 5,234
  • 7
  • 36
  • 84

1 Answers1

0

I'm unsure what your question exactly is. The buffer queue should be seen as a circular/ring queue, i.e.: you write the contents of a new buffer into the next queued (thus "free") buffer, when the current buffer finishes playing, the queued buffer becomes the current one, and the previously current buffer the new enqueued buffer, basically swapping their status. You needn't worry about this when recording and processing sound, but focus on a single, temporary buffer that you write into and write these contents into the enqueued buffer. Then the ring buffer for output can continue doing it's thing and on the next callback (i.e. when the buffers in the queue swap), you clear the content of the temporary buffer and fill it with all the magic you'd like it to hold. What it basically comes down to is that all your recording and rendering will take place after each callback and you have queue both for output and for input, which will overcome the possibility that data would be lost.

Igor Zinken
  • 884
  • 5
  • 19
  • In fact, I need the app to monitor some sound signals,which may be quite short,so I was afraid that I might miss them when the buffers were switching... However, I have tried the solution I referred and it works quite well...But I am still not sure whether there are potential drawbacks...Anyway, thanks a lot. – user3340273 Mar 06 '14 at 05:21