【问题标题】:CoreAudio: how to retrieve actual sampling rate of raw data?CoreAudio:如何检索原始数据的实际采样率?
【发布时间】:2014-08-13 11:28:14
【问题描述】:

当尝试在 mp4 容器中播放 AAC-HE 内容时,在 mp4 容器中发现的报告采样率似乎是实际采样率的一半。

例如,它显示为 24kHz 而不是 48kHz。

使用 FFmpeg AAC 解码器,可以通过简单地使用解码音频包来检索实际采样率

avcodec_decode_audio4

并查看AVCodecContext::sample_rate,它将适当更新。从中很容易调整输出。

使用 CoreAudio 解码器,我会使用 AudioConverterRef 设置输入和输出 AudioStreamBasicDescription 并致电AudioConverterFillComplexBuffer

由于转换器执行所有必需的内部转换,包括重新采样,这很好。但它会在将内容重新采样到 24kHz 后播放内容(因为这就是输入 AudioStreamBasicDescription 所包含的内容。

是否有一种方法可以以与使用 FFmpeg 类似的方式检索解码器(而不是解复用器)中发现的实际采样率?

希望尽可能避免丢失音频质量,而不是缩混数据

谢谢

【问题讨论】:

    标签: ffmpeg core-audio


    【解决方案1】:

    找到这个: https://developer.apple.com/library/ios/qa/qa1639/_index.html

    解释如何检索更高质量的流..

    结果代码如下:

    AudioStreamBasicDescription inputFormat;
    AudioFormatListItem* formatListPtr = NULL;
    UInt32 propertySize;
    OSStatus rv = noErr;
    
    rv = AudioFileStreamGetPropertyInfo(mStream,
                                        kAudioFileStreamProperty_FormatList,
                                        &propertySize,
                                        NULL);
    if (rv == noErr) {
      // allocate memory for the format list items
      formatListPtr = static_cast<AudioFormatListItem*>(malloc(propertySize));
      if (!formatListPtr) {
        LOG("Error %d constructing AudioConverter", rv);
        mCallback->Error();
        return;
      }
    
      // get the list of Audio Format List Item's
      rv = AudioFileStreamGetProperty(mStream,
                                      kAudioFileStreamProperty_FormatList,
                                      &propertySize,
                                      formatListPtr);
      if (rv == noErr) {
        UInt32 itemIndex;
        UInt32 indexSize = sizeof(itemIndex);
    
        // get the index number of the first playable format -- this index number will be for
        // the highest quality layer the platform is capable of playing
        rv = AudioFormatGetProperty(kAudioFormatProperty_FirstPlayableFormatFromList,
                                    propertySize,
                                    formatListPtr,
                                    &indexSize,
                                    &itemIndex);
        if (rv != noErr) {
          free(formatListPtr);
          LOG("Error %d retrieving best format for AudioConverter", rv);
          return;
        }
        // copy the format item at index we want returned
        inputFormat =  formatListPtr[itemIndex].mASBD;
      }
      free(formatListPtr);
    } else {
      // Fill in the input format description from the stream.
      nsresult rv = AppleUtils::GetProperty(mStream,
                                            kAudioFileStreamProperty_DataFormat,
                                            &inputFormat);
      if (NS_FAILED(rv)) {
        LOG("Error %d retrieving default format for AudioConverter", rv);
        return;
      }
    }
    
    // Fill in the output format manually.
    PodZero(&mOutputFormat);
    mOutputFormat.mFormatID = kAudioFormatLinearPCM;
    mOutputFormat.mSampleRate = inputFormat.mSampleRate;
    mOutputFormat.mChannelsPerFrame = inputFormat.mChannelsPerFrame;
    

    【讨论】:

      猜你喜欢
      • 2018-10-09
      • 2012-05-21
      • 2022-01-15
      • 2011-01-11
      • 2017-06-04
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多