Skip to content

Commit

Permalink
Formatted files from previous commit using rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Avanthikaa committed Nov 9, 2018
1 parent 829225c commit 5d8cdfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
40 changes: 17 additions & 23 deletions audio/src/oscillator_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl Default for OscillatorNodeOptions {
}
}


#[derive(AudioScheduledSourceNode, AudioNodeCommon)]
pub(crate) struct OscillatorNode {
channel_info: ChannelInfo,
Expand Down Expand Up @@ -70,8 +69,6 @@ impl OscillatorNode {
pub fn update_parameters(&mut self, info: &BlockInfo, tick: Tick) -> bool {
self.frequency.update(info, tick)
}


}

impl AudioNodeEngine for OscillatorNode {
Expand All @@ -89,7 +86,7 @@ impl AudioNodeEngine for OscillatorNode {
ShouldPlay::No => {
return inputs;
}
ShouldPlay::Between(start, end) => (start, end)
ShouldPlay::Between(start, end) => (start, end),
};

{
Expand All @@ -110,7 +107,7 @@ impl AudioNodeEngine for OscillatorNode {
while let Some(mut frame) = iter.next() {
let tick = frame.tick();
if tick < start_at {
continue
continue;
} else if tick > stop_at {
break;
}
Expand All @@ -126,38 +123,35 @@ impl AudioNodeEngine for OscillatorNode {

OscillatorType::Square => {
if self.phase >= PI && self.phase < two_pi {
value = vol * 1.0;
}
else if self.phase > 0.0 && self.phase < PI {
value = vol * (-1.0);
}
value = vol * 1.0;
} else if self.phase > 0.0 && self.phase < PI {
value = vol * (-1.0);
}
}

OscillatorType::Sawtooth => {
value = vol * ((self.phase as f64) / (PI)) as f32;
}

OscillatorType::Triangle => {
if self.phase >= 0. && self.phase < PI/2.{
if self.phase >= 0. && self.phase < PI / 2. {
value = vol * 2.0 * ((self.phase as f64) / (PI)) as f32;
}
else if self.phase >= PI/2. && self.phase < PI {
value = vol * ( 1. - ( ( (self.phase as f64) - (PI/2.)) * (2./PI) ) as f32 );
}
else if self.phase >= PI && self.phase < (3.* PI/2.) {
value = vol * -1. * ( 1. - ( ( (self.phase as f64) - (PI/2.)) * (2./PI) ) as f32 );
}
else if self.phase >= 3.*PI/2. && self.phase < 2.*PI {
} else if self.phase >= PI / 2. && self.phase < PI {
value =
vol * (1. - (((self.phase as f64) - (PI / 2.)) * (2. / PI)) as f32);
} else if self.phase >= PI && self.phase < (3. * PI / 2.) {
value = vol
* -1.
* (1. - (((self.phase as f64) - (PI / 2.)) * (2. / PI)) as f32);
} else if self.phase >= 3. * PI / 2. && self.phase < 2. * PI {
value = vol * (-2.0) * ((self.phase as f64) / (PI)) as f32;
}
}

OscillatorType::Custom => {

}
OscillatorType::Custom => {}
}

frame.mutate_with(|sample, _| *sample = value);
frame.mutate_with(|sample, _| *sample = value);

self.phase += step;
if self.phase >= two_pi {
Expand Down
6 changes: 2 additions & 4 deletions examples/oscillator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ 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::oscillator_node::OscillatorType::Sawtooth;
use servo_media::audio::oscillator_node::OscillatorType::Triangle;
//use servo_media::audio::oscillator_node::OscillatorType::Sine;
use servo_media::audio::oscillator_node::OscillatorType::Square;
use servo_media::audio::oscillator_node::OscillatorType::Custom;
use servo_media::audio::oscillator_node::OscillatorType::Square;
use servo_media::ServoMedia;
use std::sync::Arc;
use std::{thread, time};
Expand Down Expand Up @@ -58,7 +58,6 @@ fn run_example(servo_media: Arc<ServoMedia>) {
let _ = context.close();
thread::sleep(time::Duration::from_millis(1000));


options.oscillator_type = Triangle;
let context = servo_media.create_audio_context(Default::default());
let dest = context.dest_node();
Expand All @@ -76,7 +75,6 @@ fn run_example(servo_media: Arc<ServoMedia>) {
let _ = context.close();
thread::sleep(time::Duration::from_millis(1000));


options.oscillator_type = Custom;
let context = servo_media.create_audio_context(Default::default());
let dest = context.dest_node();
Expand Down

0 comments on commit 5d8cdfc

Please sign in to comment.