美文网首页
1期_AVAudioEngine

1期_AVAudioEngine

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

    比较高级的音频播放API.
    1.管理所有的音频节点(audio nodes) 2.连接所有的音频节点使其运作形成链条(active chains) 3.动态的获取(attach)和配置所有音频的节点。
    4.开启和停止API

    涉及的类AVAudioPlayerNodeAVAudioUnitTimePitchAVAudioUnitVarispeedAVAudioUnitDelay

    功能:
    设置音量可以使用AVAudioPlayerNode中volume属性0~1,也可以使用AVAudioUnitTimePitch

    速率:
    AVAudioUnitTimePitch:rate:1/32~32.0
    AVAudioUnitVarispeed: rate:0.25 -> 4.0

    AVAudioUnit继承AVAudioNode

    AVAudioUnitEffect继承AVAudioUnit
    AVAudioUnitDelay继承AVAudioUnitEffect

    AVAudioPlayerNode继承

    AVAudioPlayerNode

    播放节点,继承自AVAudioNode,实现了AVAudioMixing协议

    @available(iOS 8.0, *)
    open class AVAudioPlayerNode : AVAudioNode, AVAudioMixing {
    
        public init()
    

    音效框架

    节点介绍

    iOS的AVAudioUnit提到的音效包括:混响,延迟,失真,混衡器,变速,变调等

    按照类型分为Audio effecttime effect

    AVAudioUnitEffect

    音效节点,继承自AVAudioUnit

    @interface AVAudioUnitEffect : AVAudioUnit
    
    @end
    

    AVAudioUnitDistortion

    失真

    @available(iOS 8.0, *)
    open class AVAudioUnitDistortion : AVAudioUnitEffect {
    
        
        /** @method loadFactoryPreset:
            @abstract Load a distortion preset.
            Default:    AVAudioUnitDistortionPresetDrumsBitBrush
        */
        open func loadFactoryPreset(_ preset: AVAudioUnitDistortionPreset)
    
        
        /** @property preGain
            @abstract 失真前增益
            Range:      -80 -> 20
            Default:    -6
            Unit:       dB
        */
        open var preGain: Float
    
        /** 干湿比
            Range:      0 (all dry) -> 100 (all distorted)
            Default:    50
            Unit:       Percent
        */
        open var wetDryMix: Float
        
    }
    

    AVAudioUnitReverb

    混响增强音质,混响支持预设环境

    @available(iOS 8.0, *)
    open class AVAudioUnitReverb : AVAudioUnitEffect {
    
        
        /** @method loadFactoryPreset:
            @abstract load a reverb preset
            Default:    AVAudioUnitReverbPresetMediumHall
        */
        open func loadFactoryPreset(_ preset: AVAudioUnitReverbPreset)
    
        
        /** @property wetDryMix
            @abstract
            Blend of the wet and dry signals
            Range:      0 (all dry) -> 100 (all wet)
            Unit:       Percent
        */
        open var wetDryMix: Float
    }
    
    

    AVAudioUnitDelay

    一个实现延迟效果的AVAudioUnitEffect,延时单元按规定的时间间隔延时输入信号,然后将其与输入信号混合
    还可以控制滚降,以模拟的效果,磁带延迟。

    @available(iOS 8.0, *)
    open class AVAudioUnitDelay : AVAudioUnitEffect {
        
        /** 延迟时间
            Range:      0 -> 2
            Default:    1
            Unit:       Seconds
         */
        open var delayTime: TimeInterval
        
        /** 衰减系数
            Range:      -100 -> 100
            Default:    50
            Unit:       Percent
        */
        open var feedback: Float
        
        /** 低通截断
            Range:      10 -> (samplerate/2)
            Default:    15000
            Unit:       Hertz
        */
        open var lowPassCutoff: Float
        
        /** 干湿比
            Range:      0 (all dry) -> 100 (all wet)
            Default:    100
            Unit:       Percent
        */
        open var wetDryMix: Float
    }
    

    AVAudioUnitTimeEffect

    时间音效节点,继承自AVAudioUnit

    • AVAudioUnitTimePitch

    变速变调效果器,调整声音音高

    @available(iOS 8.0, *)
    open class AVAudioUnitTimePitch : AVAudioUnitTimeEffect {
        
        /** 输入信号的播放速率
            Range:      1/32 -> 32.0
            Default:    1.0
            Unit:       Generic
        */
        open var rate: Float
        
        /** @property pitch
            @abstract amount by which the input signal is pitch shifted
            @discussion
                      1 octave  = 1200 cents
            1 musical semitone  = 100 cents
         
            Range:      -2400 -> 2400
            Default:    0.0
            Unit:       Cents
        */
        open var pitch: Float
    }
    
    • AVAudioUnitVarispeed
      调节播放速率
    @available(iOS 8.0, *)
    open class AVAudioUnitVarispeed : AVAudioUnitTimeEffect {
        //因为这个单元重新采样输入信号,改变播放率也改变音高。
         /**Range:      0.25 -> 4.0
            Default:    1.0
            Unit:       Generic
        */
        open var rate: Float
    }
    

    音频播放器demo

    相关文章

      网友评论

          本文标题:1期_AVAudioEngine

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