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

Implement AnalyserNode #127

Merged
merged 7 commits into from Sep 14, 2018
Next

Add AnalyserNode

  • Loading branch information
Manishearth committed Sep 14, 2018
commit 93fc9df1c0a3ce1d19ceaffbabe3f6a58c308ad6
@@ -0,0 +1,37 @@
use block::{Block, Chunk};
use node::AudioNodeEngine;
use node::BlockInfo;
use node::{AudioNodeType, ChannelInfo, ChannelInterpretation};
use std::sync::mpsc::Sender;


#[derive(AudioNodeCommon)]
pub(crate) struct AnalyserNode {
channel_info: ChannelInfo,
sender: Sender<Block>
}

impl AnalyserNode {
pub fn new(sender: Sender<Block>, channel_info: ChannelInfo) -> Self {
Self { sender, channel_info }
}

}

impl AudioNodeEngine for AnalyserNode {
fn node_type(&self) -> AudioNodeType {
AudioNodeType::AnalyserNode
}

fn process(&mut self, inputs: Chunk, _: &BlockInfo) -> Chunk {
debug_assert!(inputs.len() == 1);

let mut push = inputs.blocks[0].clone();
push.mix(1, ChannelInterpretation::Speakers);

let _ = self.sender.send(push);

// analyser node doesn't modify the inputs
inputs
}
}
@@ -10,6 +10,7 @@ extern crate smallvec;
#[macro_use]
pub mod macros;

pub mod analyser_node;
pub mod block;
pub mod buffer_source_node;
pub mod channel_node;
@@ -11,7 +11,7 @@ use std::sync::mpsc::Sender;
/// Information required to construct an audio node
#[derive(Debug, Clone)]
pub enum AudioNodeInit {
AnalyserNode,
AnalyserNode(Sender<Block>),
BiquadFilterNode,
AudioBuffer,
AudioBufferSourceNode(AudioBufferSourceNodeOptions),
@@ -1,3 +1,4 @@
use analyser_node::AnalyserNode;
use block::{Chunk, Tick, FRAMES_PER_BLOCK};
use buffer_source_node::AudioBufferSourceNode;
use channel_node::{ChannelMergerNode, ChannelSplitterNode};
@@ -129,6 +130,7 @@ impl<B: AudioBackend + 'static> AudioRenderThread<B> {
fn create_node(&mut self, node_type: AudioNodeInit, ch: ChannelInfo) -> NodeId {
let mut needs_listener = false;
let node: Box<AudioNodeEngine> = match node_type {
AudioNodeInit::AnalyserNode(sender) => Box::new(AnalyserNode::new(sender, ch)),
AudioNodeInit::AudioBufferSourceNode(options) => {
Box::new(AudioBufferSourceNode::new(options, ch))
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.