美文网首页
6期__AVFoundation-AVAudioPCMBuffe

6期__AVFoundation-AVAudioPCMBuffe

作者: 萧修 | 来源:发表于2023-11-09 01:00 被阅读0次

    AVAudioPCMBufferAVAudioBuffer的子类,用于PCM音频格式。其中AVAudioBuffer是苹果最新音频框架AVFAudio中最基础的音频缓存帧结构。

    通过AVAudioFormat和音频采样帧数(等于采样率乘以时长)构建AVAudioPCMBuffer,并且通过AVAudioFile.read把音频数据解码到AVAudioPCMBuffer,获取到解码后的PCM Buffer。

    将音频数据解码到AVAudioPCMBuffer

    - (BOOL)readIntoBuffer:(AVAudioPCMBuffer *)buffer error:(NSError **)outError;
    
    @interface AVAudioPCMBuffer : AVAudioBuffer
    
    /*! @method initWithPCMFormat:frameCapacity:
        @abstract Initialize a buffer that is to contain PCM audio samples.
        初始化一个包含PCM音频样本的缓冲区
        @param format
            The format of the PCM audio to be contained in the buffer.
            要包含在缓冲区中的PCM音频的格式
        @param frameCapacity
            The capacity of the buffer in PCM sample frames.
            PCM采样帧中缓冲区的容量。
        @discussion
            An exception is raised if the format is not PCM.
     
            Returns nil in the following cases:
            - if the format has zero bytes per frame (format.streamDescription->mBytesPerFrame == 0)
            - if the buffer byte capacity (frameCapacity * format.streamDescription->mBytesPerFrame)
              cannot be represented by an uint32_t
    */
    - (nullable instancetype)initWithPCMFormat:(AVAudioFormat *)format frameCapacity:(AVAudioFrameCount)frameCapacity;
    
    /*! @property frameCapacity
        @abstract
            The buffer's capacity, in audio sample frames.
            音频采样帧的容量
    */
    @property (nonatomic, readonly) AVAudioFrameCount frameCapacity;
    @end
    

    相关文章

      网友评论

          本文标题:6期__AVFoundation-AVAudioPCMBuffe

          本文链接:https://www.haomeiwen.com/subject/ocynidtx.html