What is the reason for using the circular buffer in iOS Audio Calling APP?

My question is pretty much explanatory. Sorry if he seems too dumb.

I am writing an iOS VoIP dialer and have checked some open source code (iOS sound calling application). And almost all of them use Circular Buffer to store recorded and received PCM audio data. So I wonder why in this case use a circular buffer. What is the exact reason for using such a sound buffer.

Thanks in advance.

+4
source share
2 answers
Good question. There is another good reason to use a circular buffer.

iOS, () ( , ), (, 20 ) . iOS ( 20 , 370 372 . , 370 372 . ). UDP- (G729 VoIP). g729 8. , 368 (8 * 46) 20 . , ? .

, . - , . , - .

+2

. . () (/) .

, 0.023 , (/ ) 1024 . , , 0.023 . , , , - , , .

- . , . "" , "".

, . , 0,023 , 1024 . , .

void myCallback(float *samples,int sampleCount, SampleSaver *saver){
    SampleSaverSaveSamples(saver,samples,sampleCount);
}

!! ...

, , 0.023 , , SampleSaver , .

- . TPCircularBuffer, . , (), , () , (). , TPCircularBuffer ( ).

//this is on the high priority thread that can't wait for anything like a slow write to disk
void myCallback(float *samples,int sampleCount, TPCircularBuffer *buffer){
    int32_t availableBytes = 0;
    float *head = TPCircularBufferHead(buffer, &availableBytes);
    memcpy(head,samples,sampleCount * sizeof(float));//copies samples to head
    TPCircularBufferProduce(buffer,sampleCount * sizeof(float)); //moves buffer head "forward in the circle"

}

. , .

//this is on some background thread that can take it sweet time
void myLeisurelySavingCallback(TPCircularBuffer *buffer, SampleSaver *saver){
    int32_t available;
    float *tail = TPCircularBufferTail(buffer, &available);
    int samplesInBuffer = available / sizeof(float); //mono 
    SampleSaverSaveSamples(saver, tail, samplesInBuffer);
    TPCircularBufferConsume(buffer, samplesInBuffer * sizeof(float)); // moves tail forward
}

, , , , ( , ), , 0,023 !

, . . - , .

+13

All Articles