Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: What happens when AudioRecordQueue queue gets filled with blocks?

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    3

    What happens when AudioRecordQueue queue gets filled with blocks?

    Assuming that we allocated some audio memory from AudioMemory(x), what happens when the audio queue (instance of AudioRecordQueue) gets filled completely with samples?
    I dug into the library itself (https://github.com/PaulStoffregen/Au..._queue.cpp#L78) and found out the AudioRecordQueue::update()
    method which if I am interpreting correctly, it is simply starting to fill with samples starting from the end of the queue. Am I correct regarding this?

  2. #2
    Senior Member
    Join Date
    Feb 2015
    Posts
    248
    When the sample blocks get filled up, the head resets to zero, which means the old sample data will start being overwritten. You can see the resetting happening on line 90:
    Code:
    if (h >= max_buffers) h = 0;
    Also, you don't need to worry about allocating memory for this object. The memory is statically allocated inside the class definition, in record_queue.h on line 58:
    Code:
    audio_block_t * volatile queue[max_buffers];
    max_buffers is defined earlier in record_queue.h to be either 53 or 209. AudioMemory(x) is only needed to reserve enough space for the PatchCord objects if I remember correctly.

    Is there something specific you're trying to do?

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    3
    Quote Originally Posted by wcalvert View Post
    When the sample blocks get filled up, the head resets to zero, which means the old sample data will start being overwritten. You can see the resetting happening on line 90:
    Code:
    if (h >= max_buffers) h = 0;
    Also, you don't need to worry about allocating memory for this object. The memory is statically allocated inside the class definition, in record_queue.h on line 58:
    Code:
    audio_block_t * volatile queue[max_buffers];
    max_buffers is defined earlier in record_queue.h to be either 53 or 209. AudioMemory(x) is only needed to reserve enough space for the PatchCord objects if I remember correctly.

    Is there something specific you're trying to do?
    Thank you for your detailed answer. I also appreciate your insight regarding AudioMemory. I am using a microphone for my project and wanted to know what
    happens to the samples when the queue fills up.
    Maybe I should start another thread but also wanted to ask what is the difference between ::clear() and ::freeBuffer().
    Presumably clear will empty the whole queue while freeBuffer will only clear the block at the front of the queue.
    Last edited by superflash; 01-17-2020 at 08:50 AM.

  4. #4
    Senior Member
    Join Date
    Feb 2015
    Posts
    248
    clear() releases all blocks (either 53 or 209 depending on the #define), you probably don't want to use that as a part of your normal recording cycle. freeBuffer() releases the "userblock" which is a buffer that is used to get data out of the queue and into your application code. I will just link this thread as it looks like it has a good example of the recording cycle: https://forum.pjrc.com/threads/46150...dio-to-SD-Card

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •