Converting system audio input data to 8kHz PCM
Converting system audio input data to 8kHz PCM
- Subject: Converting system audio input data to 8kHz PCM
- From: email@hidden (Colin Henein)
- Date: Thu, 8 Apr 2004 15:13:53 -0400 (EDT)
Greetings CoreAudio types,
I am trying to record audio from the system default input source, and
convert it using AudioConverterFillComplexBuffer into mono 8 bit, 8
kHz, linear PCM.
My audio stream seems to be coming in, but I continually get 'insz'
errors from the converter, and I think I may be setting
AudioBufferList fields badly or something.
I've read everything I can find about this, including tech notes,
mailing list archives, header files and documentation but can't figure
out how to proceed. I am hoping you can point me in the right
direction, any tips are appreciated.
My general plan is to pass the AudioBufferList that I get in the audio
IOProc directly to a call to AudioConverterFillComplexBuffer. So, in
the IOProc I pass the input AudioBufferList into ...FillComplex... as
the user data pointer, and then in the ...FillComplex... data callback
I basically return it.
Here's what I'm doing:
- First, I get the input format:
AudioDeviceGetProperty ( deviceID, 0, 1, kAudioDevicePropertyStreamFormat, &size, &indesc);
- then I create my output format:
outdesc.mSampleRate = 8000; outdesc.mFormatID = kAudioFormatLinearPCM;
outdesc.mFormatFlags = kAudioFormatFlagsAreAllClear;
outdesc.mBytesPerPacket = 1; outdesc.mFramesPerPacket = 1;
outdesc.mBytesPerFrame = 1; outdesc.mChannelsPerFrame = 1;
outdesc.mBitsPerChannel = 8;
- then I add my audio ioproc (with the converter reference as user
data) then start the audio device.
In the IOProc, I do the following:
- Find out the size of output buffer I require (stored into a var:
bufreq) by getting the kAudioConverterPropertyCalculateOutputBufferSize
property from the converter (using inInputData->mBuffers[0].mDataByteSize
as input)
- Create an AudioBufferList, and malloc a buffer of size bufreq. Set
the number of channels to 1, mDataByteSize = bufreq
- Call AudioConverterFillComplexBuffer(converter, mydatacallbackfunction, (void*)inInputData, &bufreq, &outData, NULL);
- In AudioConverterFillComplexBuffer's data callback I do the following
(casts omitted)
for (i=0; i < (userData->mNumberBuffers); i++) {
ioData->mBuffers[i].mDataByteSize = userData->mBuffers[i].mDataByteSize;
ioData->mBuffers[i].mData = userData->mBuffers[i].mData;
ioData->mBuffers[i].mNumberChannels = userData->mBuffers[i].mNumberChannels;
}
return noErr;
The problem is that no matter what I do I seem to get 'insz' errors
back from the call to AudioConverterFillComplexBuffer. Also, the
number of packets requested by the converter doesn't seem to be
similar at all to the amount of data passed in, or to the amount of
output data to be generated.
I've seen references to mDataByteSize being used for both size of
memory block, and number of packets, but playing with this doesn't
seem to yield improvement.
Any suggestions?
Regards,
Colin Henein
_______________________________________________
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.