- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想从iPhone麦克风录制音频,然后转换为iLBC,然后流式传输到远程服务器。但是我总是在1768846202
中得到AudioConverterFillComplexBuffer
。
我知道这意味着kAudioConverterErr_InvalidInputSize
,但我不知道哪个输入是错误的。
我搜索了一些文章,例如Stream audio from iOS,Record audio on iPhone with smallest file size和AudioUnit PCM compression to iLBC and decompression to PCM,但是这些都不能解决我的问题。
这是我的转换函数:
-(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__];
}
最佳答案
我在this中更改了一些代码,然后找到了解决方案。
createAudioConvert:
AudioStreamBasicDescription inputFormat = *(CMAudioFormatDescriptionGetStreamBasicDescription(CMSampleBufferGetFormatDescription(sampleBuffer))); // 输入音频格式
AudioStreamBasicDescription outputFormat;
memset(&outputFormat, 0, sizeof(outputFormat));
outputFormat.mSampleRate = 8000;
outputFormat.mFormatID = kAudioFormatiLBC;
outputFormat.mChannelsPerFrame = 1;
// use AudioFormat API to fill out the rest of the description
UInt32 size = sizeof(outputFormat);
AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &outputFormat);
outputFormat.mBytesPerPacket = 50;
outputFormat.mFramesPerPacket = 240;
AudioClassDescription *desc = [self getAudioClassDescriptionWithType:kAudioFormatiLBC, fromManufacturer:kAppleSoftwareAudioCodecManufacturer];
if (AudioConverterNewSpecific(&inputFormat, &outputFormat, 1, desc, &m_converter) != noErr)
{
printf("AudioConverterNewSpecific failed\n");
return NO;
}
return YES;
if ([self createAudioConvert:sampleBuffer] != YES)
{
return NO;
}
CMBlockBufferRef blockBuffer = nil;
AudioBufferList inBufferList;
if (CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, &inBufferList, sizeof(inBufferList), NULL, NULL, 0, &blockBuffer) != noErr)
{
printf("CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer failed");
return NO;
}
AudioBufferList outBufferList;
outBufferList.mNumberBuffers = 1;
outBufferList.mBuffers[0].mNumberChannels = 1;//2;
outBufferList.mBuffers[0].mDataByteSize = *aacLen;
outBufferList.mBuffers[0].mData = aacData;
UInt32 outputDataPacketSize = 1;
OSStatus err = AudioConverterFillComplexBuffer(m_converter, inputDataProc, &inBufferList, &outputDataPacketSize, &outBufferList, NULL);
printf("AudioConverterFillComplexBuffer\n");
if ( err != noErr)
{
printf("AudioConverterFillComplexBuffer failed\n");
return NO;
}
*aacLen = outBufferList.mBuffers[0].mDataByteSize;
CFRelease(blockBuffer);
return YES;
OSStatus inputDataProc(AudioConverterRef inConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData,AudioStreamPacketDescription **outDataPacketDescription, void *inUserData) {
ioData->mNumberBuffers = 1;
AudioBufferList bufferList = *(AudioBufferList*)inUserData;
ioData->mBuffers[0].mNumberChannels = 1;
ioData->mBuffers[0].mData = bufferList.mBuffers[0].mData;
ioData->mBuffers[0].mDataByteSize = bufferList.mBuffers[0].mDataByteSize;
UInt32 maxPackets = bufferList.mBuffers[0].mDataByteSize / 2;
*ioNumberDataPackets = maxPackets;
return noErr;
}
关于objective-c - 将音频从iPhone麦克风转换为iLBC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887497/
现在我正在我的 Audio Unit proc 中获取 PCM 音频,它将传入的音频缓冲区数据写入循环缓冲区以在其他地方使用。 现在我想获取 iLBC 音频数据,所以我将 AudioStreamBas
一段时间以来,我一直在使用 gsm 编解码器进行网络音频聊天。由于“语音预测”,现在我想实现像 speex 或 iLBC 这样的 smth。据我了解,我需要数据包的时间戳。我也知道要使编解码器预测语音
如何获取通过 iPhone 录制的音频文件以在 Android 中播放。 最佳答案 我没有在 Android supported media formats 的解码器部分看到 iLBC 编解码器 查看
如何以 iLBC 格式录制音频?我从问题 # 1010343 得到了一些帮助,并实现了这段代码: NSMutableDictionary *recordSetting = [[NSMutableDic
二手http://www.ilbcfreeware.org/software.html - 我只从 ilbc_test.exe 创建的文件中获取静态数据。 还有人有其他建议吗?据我所知,sox 似乎无
我是一名优秀的程序员,十分优秀!