From 59c8001592ec4b35c3b50b8d6de2ae840c9fe754 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 10 Jul 2018 14:54:48 -0700 Subject: [PATCH 1/2] Add SetParamRate message type --- servo-media/src/audio/node.rs | 8 ++++++-- servo-media/src/audio/param.rs | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/servo-media/src/audio/node.rs b/servo-media/src/audio/node.rs index 1dfdde48..bbf08194 100644 --- a/servo-media/src/audio/node.rs +++ b/servo-media/src/audio/node.rs @@ -1,4 +1,4 @@ -use audio::param::{Param, ParamType, UserAutomationEvent}; +use audio::param::{Param, ParamType, ParamKind, UserAutomationEvent}; use audio::channel_node::ChannelNodeOptions; use audio::block::{Chunk, Tick}; use audio::buffer_source_node::{AudioBufferSourceNodeMessage, AudioBufferSourceNodeOptions}; @@ -121,6 +121,9 @@ pub(crate) trait AudioNodeEngine: Send + AudioNodeCommon { AudioNodeMessage::SetParam(id, event) => { self.get_param(id).insert_event(event.to_event(sample_rate)) } + AudioNodeMessage::SetParamRate(id, rate) => { + self.get_param(id).set_rate(rate) + } _ => self.message_specific(msg, sample_rate), } } @@ -175,7 +178,8 @@ pub enum AudioNodeMessage { SetChannelCount(u8), SetChannelMode(ChannelCountMode), SetChannelInterpretation(ChannelInterpretation), - SetParam(ParamType, UserAutomationEvent) + SetParam(ParamType, UserAutomationEvent), + SetParamRate(ParamType, ParamKind), } /// This trait represents the common features of the source nodes such as diff --git a/servo-media/src/audio/param.rs b/servo-media/src/audio/param.rs index ea3782a2..52d21b18 100644 --- a/servo-media/src/audio/param.rs +++ b/servo-media/src/audio/param.rs @@ -116,6 +116,10 @@ impl Param { self.val } + pub fn set_rate(&mut self, rate: ParamKind) { + self.kind = rate; + } + pub(crate) fn insert_event(&mut self, event: AutomationEvent) { if let AutomationEvent::SetValue(val) = event { self.val = val; From 38465ffe1b6699f9d6373bd7959ddf07dd025584 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 10 Jul 2018 15:04:44 -0700 Subject: [PATCH 2/2] rename ParamKind -> ParamRate --- servo-media/src/audio/node.rs | 4 ++-- servo-media/src/audio/param.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/servo-media/src/audio/node.rs b/servo-media/src/audio/node.rs index bbf08194..2a8e2402 100644 --- a/servo-media/src/audio/node.rs +++ b/servo-media/src/audio/node.rs @@ -1,4 +1,4 @@ -use audio::param::{Param, ParamType, ParamKind, UserAutomationEvent}; +use audio::param::{Param, ParamType, ParamRate, UserAutomationEvent}; use audio::channel_node::ChannelNodeOptions; use audio::block::{Chunk, Tick}; use audio::buffer_source_node::{AudioBufferSourceNodeMessage, AudioBufferSourceNodeOptions}; @@ -179,7 +179,7 @@ pub enum AudioNodeMessage { SetChannelMode(ChannelCountMode), SetChannelInterpretation(ChannelInterpretation), SetParam(ParamType, UserAutomationEvent), - SetParamRate(ParamType, ParamKind), + SetParamRate(ParamType, ParamRate), } /// This trait represents the common features of the source nodes such as diff --git a/servo-media/src/audio/param.rs b/servo-media/src/audio/param.rs index 52d21b18..6018f8e7 100644 --- a/servo-media/src/audio/param.rs +++ b/servo-media/src/audio/param.rs @@ -15,7 +15,7 @@ pub enum ParamType { #[derive(Debug)] pub struct Param { val: f32, - kind: ParamKind, + kind: ParamRate, events: Vec, current_event: usize, event_start_time: Tick, @@ -23,7 +23,7 @@ pub struct Param { } #[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum ParamKind { +pub enum ParamRate { /// Value is held for entire block KRate, /// Value is updated each frame @@ -35,7 +35,7 @@ impl Param { pub fn new(val: f32) -> Self{ Param { val, - kind: ParamKind::ARate, + kind: ParamRate::ARate, events: vec![], current_event: 0, event_start_time: Tick(0), @@ -47,7 +47,7 @@ impl Param { /// /// Returns true if anything changed pub fn update(&mut self, block: &BlockInfo, tick: Tick) -> bool { - if tick.0 != 0 && self.kind == ParamKind::KRate { + if tick.0 != 0 && self.kind == ParamRate::KRate { return false; } @@ -116,7 +116,7 @@ impl Param { self.val } - pub fn set_rate(&mut self, rate: ParamKind) { + pub fn set_rate(&mut self, rate: ParamRate) { self.kind = rate; }