Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Oscillator node example to exercise different oscillator types #163

Merged
merged 7 commits into from Nov 9, 2018
Next

added oscillator.rs

  • Loading branch information
rkolhe
rkolhe committed Nov 2, 2018
commit b5e153ad1db36f7f3726803a7e27e1e429733d5d
@@ -72,3 +72,7 @@ path = "player/main.rs"
[[bin]]
name = "simple_player"
path = "simple_player.rs"

[[bin]]
name = "oscillator"
path = "oscillator.rs"
@@ -0,0 +1,44 @@
extern crate servo_media;

use servo_media::audio::node::{AudioNodeInit, AudioNodeMessage, AudioScheduledSourceNodeMessage};
use servo_media::audio::oscillator_node::OscillatorNodeOptions;
use servo_media::audio::oscillator_node::OscillatorType::Triangle;
use servo_media::audio::param::{ParamType, RampKind, UserAutomationEvent};
use servo_media::ServoMedia;
use std::sync::Arc;
use std::{thread, time};

fn run_example(servo_media: Arc<ServoMedia>) {
let context = servo_media.create_audio_context(Default::default());
let dest = context.dest_node();
let mut options = OscillatorNodeOptions::default();
options.freq = 150.;
//options.oscillator_type = Sawtooth;
let osc1 = context.create_node(AudioNodeInit::OscillatorNode(options), Default::default());
options.oscillator_type = Triangle;
//options.freq = 800.;
let osc2 = context.create_node(AudioNodeInit::OscillatorNode(options), Default::default());
context.connect_ports(osc1.output(0), dest.input(0));

let _ = context.resume();
context.message_node(
osc1,
AudioNodeMessage::AudioScheduledSourceNode(AudioScheduledSourceNodeMessage::Start(0.)),
);

thread::sleep(time::Duration::from_millis(3000));
context.connect_ports(osc2.output(0), dest.input(0));
context.message_node(
osc2,
AudioNodeMessage::AudioScheduledSourceNode(AudioScheduledSourceNodeMessage::Start(0.)),
);
thread::sleep(time::Duration::from_millis(3000));
}

fn main() {
if let Ok(servo_media) = ServoMedia::get() {
run_example(servo_media);
} else {
unreachable!();
}
}
@@ -171,6 +171,7 @@ fn run_example(servo_media: Arc<ServoMedia>) {
}

fn main() {
println!("Hello from panner");
if let Ok(servo_media) = ServoMedia::get() {
run_example(servo_media);
} else {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.