@@ -236,46 +236,54 @@ float DataQueue::writeAllChannels (const AudioBuffer<float>& buffer,
236236{
237237 if (m_numChans == 0 || nSamples == 0 )
238238 return 0 .0f ;
239+ int index1 = 0 ;
240+ int size1 = 0 ;
241+ int index2 = 0 ;
242+ int size2 = 0 ;
239243
240- // Get FIFO indices from first channel - all channels should be in sync
241- int index1, size1, index2, size2;
242- m_fifos[0 ]->prepareToWrite (nSamples, index1, size1, index2, size2);
243-
244- if ((size1 + size2) < nSamples)
245244 {
246- LOGE (__FUNCTION__, " Recording Data Queue Overflow: sz1: " , size1, " sz2: " , size2, " nSamples: " , nSamples);
247- }
245+ // Get FIFO indices from first channel - all channels should be in sync
246+ auto fifoScope = m_fifos[0 ]->write (nSamples);
247+ index1 = fifoScope.startIndex1 ;
248+ size1 = fifoScope.blockSize1 ;
249+ index2 = fifoScope.startIndex2 ;
250+ size2 = fifoScope.blockSize2 ;
248251
249- float maxUsage = 0 .0f ;
252+ if ((size1 + size2) < nSamples)
253+ LOGE (__FUNCTION__, " Recording Data Queue Overflow: sz1: " , size1, " sz2: " , size2, " nSamples: " , nSamples);
250254
251- // Fill sample numbers once for the stream (not per-channel)
252- fillSampleNumbers (index1, size1, sampleNumber);
253- if (size2 > 0 )
254- {
255- fillSampleNumbers (index2, size2, sampleNumber + size1);
256- }
257-
258- // Batch copy and update all channels
259- for (int destChannel = 0 ; destChannel < m_numChans; ++destChannel)
260- {
261- int srcChannel = srcChannels[destChannel];
262-
263- // Copy first segment
264- m_buffer.copyFrom (destChannel, index1, buffer, srcChannel, 0 , size1);
265-
266- // Copy second segment (wrap-around) if present
255+ // Fill sample numbers once for the stream (not per-channel)
256+ fillSampleNumbers (index1, size1, sampleNumber);
267257 if (size2 > 0 )
268258 {
269- m_buffer. copyFrom (destChannel, index2, buffer, srcChannel, size1, size2 );
259+ fillSampleNumbers ( index2, size2, sampleNumber + size1 );
270260 }
271261
272- // Update FIFO state - need to call prepareToWrite for channels > 0
273- if (destChannel > 0 )
262+ const int * srcChannelPtr = srcChannels.getRawDataPointer ();
263+
264+ // Batch copy and update all channels
265+ for (int destChannel = 0 ; destChannel < m_numChans; ++destChannel)
274266 {
275- int d1, d2, d3, d4;
276- m_fifos[destChannel]->prepareToWrite (nSamples, d1, d2, d3, d4);
267+ const int srcChannel = srcChannelPtr[destChannel];
268+ const float * src = buffer.getReadPointer (srcChannel);
269+ float * dest = m_buffer.getWritePointer (destChannel);
270+
271+ // Copy first segment
272+ FloatVectorOperations::copy (dest + index1, src, size1);
273+
274+ // Copy second segment (wrap-around) if present
275+ if (size2 > 0 )
276+ {
277+ FloatVectorOperations::copy (dest + index2, src + size1, size2);
278+ }
279+
280+ // Update FIFO state for channels > 0 (indices are aligned with channel 0)
281+ if (destChannel > 0 )
282+ {
283+ jassert (m_fifos[destChannel]->getFreeSpace () >= (size1 + size2));
284+ m_fifos[destChannel]->finishedWrite (size1 + size2);
285+ }
277286 }
278- m_fifos[destChannel]->finishedWrite (size1 + size2);
279287 }
280288
281289 // Return usage from last channel (all should be the same)
0 commit comments