I am playing raw PCM data over Bluetooth, and I do a lost of tests, and finally found that when TPCircularBuffer produce bytes, the noise happen, here is the two part of my code (One get PCM data from Bluetooth device, one use Portaudio to render the PCM).
Produce bytes ->:
- (void)a2dpSink:(A2DPSink *)sink channel:(IOBluetoothL2CAPChannel *)channel rawRTPdataReceived:(NSData *)data
{
NSData *mediaPayload = getMediaPayloadInRTP(data);
getSBCFramesInMediaPayload(mediaPayload);
recordCount++;
if (recordCount == 50) {
long index = 0;
uint16 i;
long size = 0;
for (i = 0; i < [sbcFrames count]; i++) {
size = [[sbcFrames objectAtIndex:i] length];
memcpy((unsigned char*)buf + index, (unsigned char*)[[sbcFrames objectAtIndex:i] bytes], size);
index += size;
}
[sbcFrames removeAllObjects];
// Start decode
int pcmBytes = 0;
decodeSBCFramesBuffer(buf, (int)index, pcm, &pcmBytes);
TPCircularBufferProduceBytes(&paData.buffer, pcm, pcmBytes);
if (!played) {
framesPerBuffer = pcmBytes / 4;
playPortAudio();
played = YES;
}
if (!Pa_IsStreamActive(stream)) {
e = Pa_StartStream(stream);
if( e != paNoError ) {
NSLog(@"start stream error!");
} else {
NSLog(@"start stream OK!");
}
}
recordCount = 0;
}
}
So I think the noise is just happen when TPCircularBufferProduceBytes(&paData.buffer, pcm, pcmBytes); is called, any idea? I am testing this issue for a few days.
I am playing raw PCM data over Bluetooth, and I do a lost of tests, and finally found that when TPCircularBuffer produce bytes, the noise happen, here is the two part of my code (One get PCM data from Bluetooth device, one use Portaudio to render the PCM).
Produce bytes
->:Consume bytes
->If I increase the
recordCount
to like200
then the noise occur in a long period.
So I think the noise is just happen when
TPCircularBufferProduceBytes(&paData.buffer, pcm, pcmBytes);
is called, any idea? I am testing this issue for a few days.