AudioConverterFillComplexBuffer返回-50(paramErr) [英] AudioConverterFillComplexBuffer return -50 (paramErr)

查看:455
本文介绍了AudioConverterFillComplexBuffer返回-50(paramErr)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将PCM 32位浮点音频流转换为ALAC.我找到了一些可用的工作示例,但我自己的代码不断从AudioConverterFillComplexBuffer获得-50(paramErr).我的目光从看这段代码而错了.我看不到与示例有什么不同.

I'm trying to convert a PCM 32-bit float audio stream to ALAC. I found some working examples to build from, but my own code keeps getting a -50 (paramErr) from AudioConverterFillComplexBuffer. My eyes are crossing from looking at this code; I can't see what's different from my examples.

我设置了输入和输出格式并创建了转换器:

I set up my input and output formats and create the converter:

UInt32 numChannels = 2;

// Describe the input stream
AudioStreamBasicDescription inputFormat;
memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
inputFormat.mSampleRate = 44100;
inputFormat.mFormatID = kAudioFormatLinearPCM;
inputFormat.mFramesPerPacket = 1; 
inputFormat.mChannelsPerFrame = numChannels;  
inputFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked;
inputFormat.mBitsPerChannel = sizeof(Float32) * 8;
inputFormat.mBytesPerPacket = numChannels * (inputFormat.mBitsPerChannel / 8);
inputFormat.mBytesPerFrame = inputFormat.mBytesPerPacket * inputFormat.mFramesPerPacket;

// Describe the output stream
AudioStreamBasicDescription outputFormat;
memset(&outputFormat, 0, sizeof(AudioStreamBasicDescription));
outputFormat.mSampleRate = 44100;
outputFormat.mFormatID = kAudioFormatAppleLossless;
outputFormat.mFramesPerPacket = 4096;

OSStatus err = AudioConverterNew(&inputFormat, &outputFormat, &_alacConverter);

然后我得到最大的输出数据包大小,并分配一个缓冲区来保存转换后的数据:

Then I get the maximum output packet size and allocate a buffer to hold the converted data:

size = sizeof(UInt32);
UInt32 maxOutputSize;
AudioConverterGetProperty(_alacConverter, 
                          kAudioConverterPropertyMaximumOutputPacketSize, 
                          &size, 
                          &maxOutputSize);

_outputBuffer = [[NSMutableData dataWithCapacity:maxOutputSize] retain];

最后,我调用AudioConverterFillComplexBuffer来获取一些数据:

Finally, I call AudioConverterFillComplexBuffer to get some data:

AudioBufferList bufferList; 
memset(&bufferList, 0, sizeof(AudioBufferList));
memset(&bufferList.mBuffers[0], 0, sizeof(AudioBuffer));

bufferList.mNumberBuffers = 1;
bufferList.mBuffers[0].mNumberChannels = numChannels;
bufferList.mBuffers[0].mDataByteSize = [_outputBuffer length];
bufferList.mBuffers[0].mData = [_outputBuffer mutableBytes];

AudioStreamPacketDescription streamDesc = {0};

UInt32 numPackets = 1;

err = AudioConverterFillComplexBuffer(_alacConverter, 
                                      _encoderDataProc, 
                                      self, 
                                      &numPackets, 
                                      &bufferList, 
                                      &streamDesc);

...我总是会收到-50错误.谁能给我一个提示,我要去哪里错了?非常(非常)感谢!

...where I always get the -50 error. Can anyone give me a clue where I'm going wrong? Many (many) thanks!

更新:我只是将存根函数用作数据源,但从未将其称为:

Update: I'm just using a stub function as the data source, which is never called:

OSStatus _encoderDataProc(AudioConverterRef inAudioConverter, 
                          UInt32* ioNumberDataPackets, 
                          AudioBufferList* ioData, 
                          AudioStreamPacketDescription** outDataPacketDescription,
                          void* inUserData)
{
    TraceDebug(@"_encoderDataProc has been called");
    return -1;
}

maxOutputSize返回为32776.从好的角度来看,这是我从CAShow(_alacConverter)中获得的信息:

The maxOutputSize comes back as 32776. And for good measure, here's what I get from CAShow(_alacConverter):

AudioConverter 0xa8404e (0x101c449f0):
  PCMConverter2 0x101c34370
    Input:   2 ch,  44100 Hz, 'lpcm' (0x00000009) 32-bit little-endian float
    Output:  2 ch,  44100 Hz, 'lpcm' (0x0000000C) 32-bit little-endian signed integer
  CodecConverter 0x101c44b90
    Input:   2 ch,  44100 Hz, 'lpcm' (0x0000000C) 32-bit little-endian signed integer
    Output:  2 ch,  44100 Hz, 'alac' (0x00000004) from 32-bit source, 4096 frames/packet
    codec: 'aenc'/'alac'/'appl'
    Input layout tag: 0x650002
    Output layout tag: 0x650002

一如既往,任何帮助将不胜感激.自原始帖子发布以来,我在这方面没有取得进展.

As ever, any help is greatly appreciated. I've made no headway on this since the original post.

推荐答案

我陷入了同样的境地(基本上是在将您的代码用作模板之后).解决方案似乎是为AudioBufferList分配内存.实施此答案为我解决了问题(尽管我的Objective-C不够好,无法看到确切的区别:))

I was stuck in the same situation (basically after using your code as a template). Solution seems to be in allocation of memory for the AudioBufferList. Implementing this answer did the trick for me (although my objective-C is not good enough to see the exact difference :))

这篇关于AudioConverterFillComplexBuffer返回-50(paramErr)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆