AudioKit:如何在其音高上构建一个可反转信封的VCO?

时间:2018-03-10 11:31:14

标签: ios swift audiokit akoperationgenerator

我可以轻松地在其频率上建立一个带有信封的VCO,如

let generator = AKOperationGenerator { parameters in

    let oscillator = AKOperation.squareWave(
       frequency: PitchEnvVCO.frequency.triggeredWithEnvelope(
           trigger: PitchEnvVCO.gate,
           attack: 0.01,
           hold: 0.0,
           release: PitchEnvVCO.freqDecayTime
       ),
        amplitude: PitchEnvVCO.amplitude.triggeredWithEnvelope(
            trigger: PitchEnvVCO.gate,
            attack: 0.01,
            hold: 0.0,
            release: PitchEnvVCO.ampDecayTime
        )
    )
    return oscillator
}

enum PitchEnvVCOSynthParameter: Int {
    case frequency, amplitude, freqDecayLevel, freqDecayTime, ampDecayTime, gate
}

struct PitchEnvVCO {
    static var frequency: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.frequency.rawValue]
    }
    static var amplitude: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.amplitude.rawValue]
    }
    static var freqDecayLevel: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.freqDecayLevel.rawValue]
    }
    static var freqDecayTime: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.freqDecayTime.rawValue]
    }
    static var ampDecayTime: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.ampDecayTime.rawValue]
    }
    static var gate: AKOperation {
        return AKOperation.parameters[PitchEnvVCOSynthParameter.gate.rawValue]
    }
}

extension AKOperationGenerator {
    var frequency: Double {
        get {
            let frq = self.parameters[PitchEnvVCOSynthParameter.frequency.rawValue]
            return frq
        }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.frequency.rawValue] = newValue }
    }
    var amplitude: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.amplitude.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.amplitude.rawValue] = newValue }
    }
    var freqDecayLevel: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.freqDecayLevel.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.freqDecayLevel.rawValue] = newValue }
    }
    var freqDecayTime: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.freqDecayTime.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.freqDecayTime.rawValue] = newValue }
    }
    var ampDecayTime: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.ampDecayTime.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.ampDecayTime.rawValue] = newValue }
    }
    var gate: Double {
        get { return self.parameters[PitchEnvVCOSynthParameter.gate.rawValue] }
        set(newValue) { self.parameters[PitchEnvVCOSynthParameter.gate.rawValue] = newValue }
    }
}

但是这样我无法控制信封的数量而且它是不可逆的。我怎么能解决这个问题? 日Thnx!

0 个答案:

没有答案