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 constant_source #164
Changes from 1 commit
b5e153a
5318fc6
2a794c4
c13e4e3
90891d7
829225c
5d8cdfc
ed2742c
683699d
b0dcf9b
4f7fcc1
2560800
cb52d33
697a456
d9f94d2
0426b9c
1045217
32c37cf
800f684
e437279
5d6fbe8
4047212
4dae6e0
deb3bef
84a517a
76a0a44
3763c61
7ef514a
8392723
99bfd89
221bc4a
87a1351
43b8b20
16f2a98
ac4fb92
3d3c7b6
6be0677
5c2ce7b
8141782
e3b059e
0dfe431
e4a76a4
e4a8d7d
7d2ef49
9c12a50
2f3f2f2
97efbe0
6e3b79a
c08eab6
c42aa15
9b83e94
29f1fd3
87aefce
477c704
af3d76a
50fce97
72f04dc
3121311
e4b7ee2
9086eef
5180cde
611d423
119bd7e
1001525
08e0ae7
64e2655
128a526
96cf7b8
3aa2ce3
ec6fc6c
dd93f56
7e65252
6824ee6
aca99b7
82a63f4
bbd207f
File filter...
Jump to…
Added file constant_node.rs with gain_node code
- Loading branch information
| @@ -0,0 +1,70 @@ | ||
| use block::Chunk; | ||
| use block::Tick; | ||
| use node::AudioNodeEngine; | ||
| use node::BlockInfo; | ||
| use node::{AudioNodeType, ChannelInfo}; | ||
| use param::{Param, ParamType}; | ||
|
|
||
| #[derive(Copy, Clone, Debug)] | ||
| pub struct GainNodeOptions { | ||
| pub gain: f32, | ||
| } | ||
|
|
||
| impl Default for GainNodeOptions { | ||
| fn default() -> Self { | ||
| GainNodeOptions { gain: 1. } | ||
| } | ||
| } | ||
|
|
||
| #[derive(AudioNodeCommon)] | ||
|
||
| pub(crate) struct GainNode { | ||
| channel_info: ChannelInfo, | ||
| gain: Param, | ||
| } | ||
|
|
||
| impl GainNode { | ||
| pub fn new(options: GainNodeOptions, channel_info: ChannelInfo) -> Self { | ||
| Self { | ||
| channel_info, | ||
| gain: Param::new(options.gain), | ||
| } | ||
| } | ||
|
|
||
| pub fn update_parameters(&mut self, info: &BlockInfo, tick: Tick) -> bool { | ||
| self.gain.update(info, tick) | ||
| } | ||
| } | ||
|
|
||
| impl AudioNodeEngine for GainNode { | ||
| fn node_type(&self) -> AudioNodeType { | ||
| AudioNodeType::GainNode | ||
| } | ||
|
|
||
| fn process(&mut self, mut inputs: Chunk, info: &BlockInfo) -> Chunk { | ||
| debug_assert!(inputs.len() == 1); | ||
ferjm
Member
|
||
|
|
||
| if inputs.blocks[0].is_silence() { | ||
ferjm
Member
|
||
| return inputs; | ||
| } | ||
|
|
||
| { | ||
| let mut iter = inputs.blocks[0].iter(); | ||
| let mut gain = self.gain.value(); | ||
|
|
||
| while let Some(mut frame) = iter.next() { | ||
| if self.update_parameters(info, frame.tick()) { | ||
| gain = self.gain.value(); | ||
| } | ||
| frame.mutate_with(|sample, _| *sample = *sample * gain); | ||
| } | ||
| } | ||
| inputs | ||
| } | ||
|
|
||
| fn get_param(&mut self, id: ParamType) -> &mut Param { | ||
| match id { | ||
| ParamType::Gain => &mut self.gain, | ||
| _ => panic!("Unknown param {:?} for GainNode", id), | ||
| } | ||
| } | ||
| } | ||
According to the spec,
ConstantSourceNodeinherits fromAudioScheduledSourceNode. So we need to deriveAudioScheduledSourceNodeas well:Deriving
AudioScheduledSourceNodeadds all these functions (should_play_at,start, etc.), so you will also need to add the parameters used in them:start_at,stop_atandonended_callback.I see that you used
GainNodeas an example to develop this node. I would useOscillatorNodeinstead as a better example, as it inherits fromAudioScheduledSourceNodeas well.