我可以轻松地在其频率上建立一个带有信封的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!