1
iPhoneマイクからオーディオを録音し、iLBCに変換してからリモートサーバーにストリームします。しかし、私はいつもAudioConverterFillComplexBuffer
に1768846202
を持っています。 私はこの意味はkAudioConverterErr_InvalidInputSize
ですが、どの入力が間違っているのか分かりません。iPhoneマイクからiLBCにオーディオを変換する
Stream audio from iOS、Record audio on iPhone with smallest file size、AudioUnit PCM compression to iLBC and decompression to PCMなどの記事を検索しましたが、いずれも問題を解決していません。ここで
は私のCONVERT関数です:
-(AudioBuffer) doConvert: (AudioBuffer)pcmData
{
char *outputBuffer = NULL;
OSStatus status;
UInt32 theOutputBufSize = pcmData.mDataByteSize;//32768;
outputBuffer = (char*)malloc(sizeof(char) * theOutputBufSize);
/* Create the output buffer list */
AudioBufferList outBufferList;
outBufferList.mNumberBuffers = 1;
outBufferList.mBuffers[0].mNumberChannels = 1;
outBufferList.mBuffers[0].mDataByteSize = theOutputBufSize;
outBufferList.mBuffers[0].mData = outputBuffer;
//Converting
//UInt32 ioOutputDataPackets = numOutputPackets;
UInt32 numOutputDataPackets = 1;
AudioStreamPacketDescription outPacketDesc[1];
status = AudioConverterFillComplexBuffer(audioConverterDecode,
encodeProc,
&pcmData,
&numOutputDataPackets,
&outBufferList,
outPacketDesc);
//outBufferList.mBuffers[0].mDataByteSize = theOutputBufSize;
[self hasError:status:__FILE__:__LINE__];
/* Set the ouput data */
AudioBuffer outData;
outData.mNumberChannels = 1;
outData.mData = outBufferList.mBuffers[0].mData;
outData.mDataByteSize = outBufferList.mBuffers[0].mDataByteSize;
return outData;
}
そして、私の初期機能:
-(void)initDecoder
{
NSLog(@"initDecoder");
AudioStreamBasicDescription srcFormat, dstFormat;
//AudioConverterRef converter = NULL;
char *outputBuffer = NULL;
OSStatus status;
//output format
dstFormat.mSampleRate = 8000.0;
dstFormat.mFormatID = kAudioFormatiLBC ;
dstFormat.mChannelsPerFrame = 1;
//dstFormat.mBitsPerChannel = 0;
dstFormat.mBytesPerPacket = 38;//50;
dstFormat.mFramesPerPacket = 160;//240;
dstFormat.mBytesPerFrame = 0;
dstFormat.mBitsPerChannel = 0;
dstFormat.mFormatFlags = 0;// little-endian
//source format
srcFormat.mSampleRate = SAMPLE_RATE; //This is 48000
srcFormat.mFormatID = kAudioFormatLinearPCM;
srcFormat.mFormatFlags = kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;
srcFormat.mFramesPerPacket = 1;
srcFormat.mChannelsPerFrame = 1;
srcFormat.mBitsPerChannel = 16;
srcFormat.mBytesPerPacket = 2;
srcFormat.mBytesPerFrame = 2;
srcFormat.mReserved = 0;
status = AudioConverterNew(&srcFormat, &dstFormat, &audioConverterDecode);
[self hasError:status:__FILE__:__LINE__];
}