• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 输出未生成 AudioConverterFillComplexBuffer 以从 AAC 转换为 PCM?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:22:00 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

您好,我正在尝试使用 AudioConverterFillComplexBuffer 将 AAC 缓冲区转换为 PCM。这是我的代码

 -(void)initDecoder{
         AudioStreamBasicDescription outAudioStreamBasicDescription;
        outAudioStreamBasicDescription.mSampleRate = 44100.0;
        outAudioStreamBasicDescription.mFormatID = kAudioFormatLinearPCM;
        outAudioStreamBasicDescription.mFormatFlags = 0xc;
        outAudioStreamBasicDescription.mBytesPerPacket = 2;
        outAudioStreamBasicDescription.mFramesPerPacket = 1;
        outAudioStreamBasicDescription.mBytesPerFrame = 2;
        outAudioStreamBasicDescription.mChannelsPerFrame = 1;
        outAudioStreamBasicDescription.mBitsPerChannel = 16;

        AudioStreamBasicDescription inAudioStreamBasicDescription;

        inAudioStreamBasicDescription.mSampleRate = 44100;
        inAudioStreamBasicDescription.mFormatID = kAudioFormatMPEG4AAC;
        inAudioStreamBasicDescription.mFormatFlags = kMPEG4Object_AAC_SSR;
        inAudioStreamBasicDescription.mBytesPerPacket = 0;
        inAudioStreamBasicDescription.mFramesPerPacket = 1024;
        inAudioStreamBasicDescription.mBytesPerFrame = 0;
        inAudioStreamBasicDescription.mChannelsPerFrame = 1;
        inAudioStreamBasicDescription.mBitsPerChannel = 0;
        inAudioStreamBasicDescription.mReserved = 0;


        AudioClassDescription audioClassDescription;
        memset(&audioClassDescription, 0, sizeof(audioClassDescription));


        audioClassDescription.mManufacturer = kAppleSoftwareAudioCodecManufacturer;
        audioClassDescription.mSubType = outAudioStreamBasicDescription.mFormatID;
        audioClassDescription.mType = kAudioFormatLinearPCM;
        NSAssert(audioClassDescription.mSubType == outAudioStreamBasicDescription.mFormatID && audioClassDescription.mManufacturer == kAppleSoftwareAudioCodecManufacturer, nil);


        NSAssert(AudioConverterNewSpecific(&inAudioStreamBasicDescription, &outAudioStreamBasicDescription, 1, &audioClassDescription, &audioConverterDecode) == 0, nil);

     }

    OSStatus inInputDataProc(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData)
    {
        AudioBufferList audioBufferList = *(AudioBufferList *)inUserData;

        ioData->mBuffers[0].mData = audioBufferList.mBuffers[0].mData;
        ioData->mBuffers[0].mDataByteSize = audioBufferList.mBuffers[0].mDataByteSize;

        return  noErr;
    }

    -(void)decodeSampleAudioBufferList)inAaudioBufferList{
        //inAaudioBufferList is the AAC buffer

        if (!audioConverterDecode) {

            [self initDecoder];
        }

         NSAssert(inAaudioBufferList.mNumberBuffers == 1, nil);

        uint32_t bufferSize = 1024*2;//inAaudioBufferList.mBuffers[0].mDataByteSize;
        uint8_t *buffer = (uint8_t *)malloc(1024*2);
        memset(buffer, 0, bufferSize);
        AudioBufferList outAudioBufferList;
        outAudioBufferList.mNumberBuffers = 1;
        outAudioBufferList.mBuffers[0].mNumberChannels = 1;
        outAudioBufferList.mBuffers[0].mDataByteSize = bufferSize;
        outAudioBufferList.mBuffers[0].mData = buffer;

        UInt32 ioOutputDataPacketSize = bufferSize;


       OSStatus ret = AudioConverterFillComplexBuffer(audioConverterDecode, inInputDataProc, &inAaudioBufferList, &ioOutputDataPacketSize, &outAudioBufferList, NULL) ;//== 0, nil);

        NSData *data = [NSData dataWithBytesutAudioBufferList.mBuffers[0].mData lengthutAudioBufferList.mBuffers[0].mDataByteSize];
        DLog(@"Rev Size = %d",(unsigned int)outAudioBufferList.mBuffers[0].mDataByteSize);
        free(buffer);

    }

解码后的输出长度为零,AudioConverterFillComplexBuffer 的 OSStatus 代码为 561015652

那么可能出了什么问题..?



Best Answer-推荐答案


这是在黑暗中拍摄的,您可能已经找到了解决方案,但我相信您需要更改它
UInt32 ioOutputDataPacketSize = bufferSize;
到这个

UInt32 ioOutputDataPacketSize = bufferSize/2;

就我个人而言,我在 inInputDataProc 方法中执行此操作并始终发送

UInt32 ioOutputDataPacketSize = 1;  

进入 AudioConverterFillComplexBuffer 方法,然后像这样在 inInputDataProc 中设置它。

UInt32 maxPackets = audioBufferList.mBuffers[0].mDataByteSize / 2;
*ioNumberDataPackets = maxPackets;     

希望这会有所帮助。

关于ios - 输出未生成 AudioConverterFillComplexBuffer 以从 AAC 转换为 PCM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31691361/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap