美文网首页
4期_AVFoundation-AVAudioFormat

4期_AVFoundation-AVAudioFormat

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

    本文了解AVAudioFormat,通过这个类,我们可以读取到音频的采样率,通道数,量化数以及音频的setting等属性

    音频格式,可以通过AVAudioFile获取,可以通过初始化AudioStreamBasicDescription得到

    @interface AVAudioFormat : NSObject <NSSecureCoding> {
    @private
        AudioStreamBasicDescription _asbd;
        AVAudioChannelLayout *_layout;
        AVAudioCommonFormat _commonFormat;
        void * _reserved;
    }
    
    
    /*! @property commonFormat
        @abstract An `AVAudioCommonFormat` identifying the format
        ?
    */
    @property (nonatomic, readonly) AVAudioCommonFormat commonFormat;
    
    /*! @property channelCount
        @abstract The number of channels of audio data.
        音频数据的通道数
    */
    @property (nonatomic, readonly) AVAudioChannelCount channelCount;
    
    /*! @property sampleRate
        @abstract A sampling rate in Hertz.
        以赫兹为单位的采样率
    */
    @property (nonatomic, readonly) double sampleRate;
    
    /*! @property streamDescription
        @abstract Returns the AudioStreamBasicDescription, for use with lower-level audio API's.
        较为低级的api,底层结构体
    */
    @property (nonatomic, readonly) const AudioStreamBasicDescription *streamDescription;
    
    /*! @property settings
        @abstract Returns the format represented as a dictionary with keys from AVAudioSettings.h.
        返回表示为带有AVAudioSettings.h中的键的字典的格式
    */
    @property (nonatomic, readonly) NSDictionary<NSString *, id> *settings;
    @end
    
    /*! @property channelLayout
        @abstract The underlying AVAudioChannelLayout, if any.
        @discussion
            Only formats with more than 2 channels are required to have channel layouts.
        只有两个通道的音频才有此属性
    */
    @property (nonatomic, readonly, nullable) AVAudioChannelLayout *channelLayout;
    

    AVAudioCommonFormat

    /*! 
        @enum       AVAudioCommonFormat
        @constant   AVAudioOtherFormat
                        A format other than one of the common ones below.
        @constant   AVAudioPCMFormatFloat32
                        Native-endian floats (this is the standard format).
        @constant   AVAudioPCMFormatFloat64
                        Native-endian doubles.
        @constant   AVAudioPCMFormatInt16
                        Signed 16-bit native-endian integers.
        @constant   AVAudioPCMFormatInt32
                        Signed 32-bit native-endian integers.
    */c
    typedef NS_ENUM(NSUInteger, AVAudioCommonFormat) {
        AVAudioOtherFormat = 0,
        AVAudioPCMFormatFloat32 = 1,
        AVAudioPCMFormatFloat64 = 2,
        AVAudioPCMFormatInt16 = 3,
        AVAudioPCMFormatInt32 = 4
    } NS_ENUM_AVAILABLE(10_10, 8_0);
    

    相关文章

      网友评论

          本文标题:4期_AVFoundation-AVAudioFormat

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