AudioConverter problem.
AudioConverter problem.
- Subject: AudioConverter problem.
- From: Fredrik Oja <email@hidden>
- Date: Wed, 06 Nov 2002 12:57:06 +0100
Hi list!
I'm currently porting my audio engine code from QT to CoreAudio. I want
to capture audio data in mono/8khz/Linear16 format in chunks of 320
bytes(20ms). I have created an AudioConverter using the device default
format as input an following format as output:
destFormatDesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger |
kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsAlignedHigh;
destFormatDesc.mFramesPerPacket = 1;
destFormatDesc.mBytesPerFrame = 2;
destFormatDesc.mBytesPerPacket = 2;
destFormatDesc.mChannelsPerFrame = 1;
destFormatDesc.mBitsPerChannel = 16;
destFormatDesc.mSampleRate = (double) 8000.0;
destFormatDesc.mFormatID = kAudioFormatLinearPCM;
I use a circular buffer between the IOProc callback and the
AudioConverter callback as following:
OSStatus captureCallback(AudioDeviceID inDevice, const AudioTimeStamp*
inNow,
const AudioBufferList*
inInputData,
const AudioTimeStamp*
inInputTime,
AudioBufferList*
outOutputData,
const AudioTimeStamp*
inOutputTime,
void* contextPtr) {
CoreAudioDevice* dev = (CoreAudioDevice *)contextPtr;
for (int i = 0; i < inInputData->mNumberBuffers; i++) {
UInt32 size = inInputData->mBuffers[i].mDataByteSize;
dev->recordBuffer->write((char
*)inInputData->mBuffers[i].mData, size);
}
return 0;
}
OSStatus converterCallback(AudioConverterRef theConverter,
UInt32*
outDataSize, void** outData,
void* inUserData) {
char* tmpBuf = (char *)malloc(*outDataSize);
CoreAudioDevice* dev = (CoreAudioDevice *) inUserData;
*outDataSize = dev->recordBuffer->read(tmpBuf, *outDataSize);
*outData = tmpBuf;
return 0;
}
Finally I read data from the converter every 20ms:
char tmpBuffer[320];
UInt32 size = 320;
OSStatus result = AudioConverterFillBuffer(converter, converterCallback,
this, &size, tmpBuffer);
For some reason, the output audio does not sound Ok. Almost like a
static "click" between every frame of audio, and like some audio chunks
are repeating. I am really stuck here, so if anyone could help me out I
would really appreciate it.
I'm using OS10.2 with an iMic device as source.
Thanks,
Fredrik Oja
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.