iOS使用Audio Converter 把源格式转换成目标格式,既可以在各种线性PCM音频格式之间转换,也可以在线性PCM格式与其他压缩格式之间转换。支持转换包括如下内容:
PCM bit depth
PCM sample rate
PCM floating point to and from PCM integer
PCM interleaved to and from PCM deinterleaved
PCM to and from compressed formats
管理 Audio Converter 对象
创建 Audio Converter
AudioConverterNew : 根据指定的源格式和目标格式创建 audio converter。
OSStatus AudioConverterNew (
const AudioStreamBasicDescription *inSourceFormat, const AudioStreamBasicDescription *inDestinationFormat, AudioConverterRef *outAudioConverter );
OSStatus AudioConverterNewSpecific ( const AudioStreamBasicDescription *inSourceFormat, const AudioStreamBasicDescription *inDestinationFormat, UInt32 inNumberClassDescriptions, AudioClassDescription *inClassDescriptions, AudioConverterRef *outAudioConverter );
重置Audio Converter
AudioConverterReset: 重新设置 audio converter , 清除了缓冲区。
OSStatus AudioConverterReset ( AudioConverterRef inAudioConverter );
OSStatus AudioConverterDispose ( AudioConverterRef inAudioConverter );
配置 Audio Converter 属性
AudioConverterGetProperty : 根据属性ID获取audo converter 的属性值
OSStatus AudioConverterGetProperty ( AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32 *ioPropertyDataSize, void *outPropertyData );
AudioConverterGetPropertyInfo : 根据属性ID获取 audio converter 信息
OSStatus AudioConverterGetPropertyInfo ( AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32 *outSize, Boolean *outWritable );
AudioConverterSetProperty: 根据属性ID 设置属性值
OSStatus AudioConverterSetProperty ( AudioConverterRef inAudioConverter, AudioConverterPropertyID inPropertyID, UInt32 inPropertyDataSize, const void *inPropertyData );
转码方法
AudioConverterConvertBuffer : 把音频数据从线性PCM转换成其他格式。
OSStatus AudioConverterConvertBuffer ( AudioConverterRef inAudioConverter, UInt32 inInputDataSize, const void *inInputData, UInt32 *ioOutputDataSize, void *outOutputData )
AudioConverterFillComplexBuffer : 使用此方法实现所有音频格式之间的转换。
OSStatus AudioConverterFillComplexBuffer( AudioConverterRef inAudioConverter, AudioConverterComplexInputDataProc inInputDataProc, void *inInputDataProcUserData, UInt32 *ioOutputDataPacketSize, AudioBufferList *outOutputData, AudioStreamPacketDescription *outPacketDescription );
AudioConverterConvertComplexBuffer :把音频数据从线性PCM转换成其他格式,而转换的格式必须具有相同的采样率。
OSStatus AudioConverterConvertComplexBuffer ( AudioConverterRef inAudioConverter, UInt32 inNumberPCMFrames, const AudioBufferList *inInputData, AudioBufferList *outOutputData );
转载于:https://blog.51cto.com/metoo/1314560