0 Replies
      Latest reply on May 31, 2019 1:14 PM by digitalheaven
      digitalheaven Level 1 Level 1 (0 points)

        I'm having no luck trying to get scheduleParameterBlock working on the gain of first input AVAudioEngine main mixer node. It just doesn't do anything. Am I missing something here?

         

        // CLASS VARS
        var inputGain : AUParameter?
        var mixerParameterBlock : AUScheduleParameterBlock?
        let rampTime :AUAudioFrameCount = AUAudioFrameCount(10 * 44100) // ramp over 10 seconds
        
        
        
        // IN PLAY FUNCTION
        // set gain on input of mixer which will be the first parameter in the tree
        let parameterTree = engine.mainMixerNode.auAudioUnit.parameterTree
        inputGain = (parameterTree?.parameter(withAddress: 0x2000000000000000))!
        
        // set initial gain to 1.0
        inputGain!.value = 1.0
        
        // reduces gain after 1 second delay
        // THIS WORKS
        delay(1.0) {
            print("reducing gain to 0.5")
            self.inputGain!.value = 0.5
        }
        
        if (inputGain?.flags.contains(.flag_CanRamp))! {
            // inputGain says it is rampable
            print("inputGain parameter is rampable")
        }
        
        mixerParameterBlock = engine.mainMixerNode.auAudioUnit.scheduleParameterBlock
        
        // THIS DOES NOT WORK
        mixerParameterBlock!(AUEventSampleTimeImmediate, rampTime, inputGain!.address, 0.0)
        
        player?.play()
        player?.scheduleFile(audioFile, at: nil)