operator_adsr
Convert trigger signals into an ADSR envelope driven by the scheduler.
See Also
- DebounceTimeOperator - Emit the most recent value after a period of silence.
- DelayOperator - Shift emissions forward in time using the scheduler.
- FallbackWhenSilentOperator - Emit a fallback value on ticks where the source stayed silent.
- ThrottleTimeOperator - Limit the frequency of downstream emissions.
Example
cargo run -p rx_core --example operator_adsr_example
use std::time::Duration;
use rx_core::prelude::*;
use rx_core_testing::MockExecutor;
fn main() {
let mut executor = MockExecutor::default();
let scheduler = executor.get_scheduler_handle();
let envelope = AdsrEnvelope {
attack_time: Duration::from_millis(10),
decay_time: Duration::from_millis(10),
sustain_volume: 0.5,
release_time: Duration::from_millis(15),
..Default::default()
};
let mut source = PublishSubject::<AdsrTrigger>::default();
let mut subscription = source
.clone()
.adsr(
AdsrOperatorOptions {
envelope,
..Default::default()
},
scheduler.clone(),
)
.subscribe(PrintObserver::new("adsr"));
source.next(true.into());
executor.tick(Duration::from_millis(10));
executor.tick(Duration::from_millis(10));
source.next(false.into());
executor.tick(Duration::from_millis(15));
subscription.unsubscribe();
}
adsr - next: AdsrSignal { adsr_envelope_phase: Attack, phase_transition: AdsrEnvelopePhaseTransition(1), t: 0ns, value: 0.0 }
adsr - next: AdsrSignal { adsr_envelope_phase: Decay, phase_transition: AdsrEnvelopePhaseTransition(2), t: 10ms, value: 1.0 }
adsr - next: AdsrSignal { adsr_envelope_phase: None, phase_transition: AdsrEnvelopePhaseTransition(16), t: 0ns, value: 0.0 }
adsr - unsubscribed