| 41 | } |
| 42 | |
| 43 | bool TeensyAudioRecorder::queueBlock(const audio_block_t* block, u8 channel) { |
| 44 | if (!block) return false; |
| 45 | |
| 46 | // Limit queue size to prevent unbounded memory growth |
| 47 | const fl::size MAX_QUEUE_SIZE = 16; // 16 blocks * 128 samples * 2.9ms = ~46ms buffer |
| 48 | if (mBlockQueue.size() >= MAX_QUEUE_SIZE) { |
| 49 | mTotalBlocksDropped++; |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | // Copy block data to our queue |
| 54 | QueuedBlock qb; |
| 55 | qb.channel = channel; |
| 56 | qb.timestamp = fl::millis(); |
| 57 | // Copy samples from audio_block_t (128 samples of int16) |
| 58 | for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) { |
| 59 | qb.samples[i] = block->data[i]; |
| 60 | } |
| 61 | |
| 62 | mBlockQueue.push_back(qb); |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | bool TeensyAudioRecorder::dequeueBlock(fl::vector<fl::i16>& samples, u8& channel, u32& timestamp) { |
| 67 | if (mBlockQueue.empty()) { |