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

Use a callback function

  • Loading branch information
Manishearth committed Sep 14, 2018
commit fe882349dd84b705e4729a312891707be0cdae4b
@@ -3,18 +3,17 @@ use node::AudioNodeEngine;
use node::BlockInfo;
use node::{AudioNodeType, ChannelInfo, ChannelInterpretation};
use std::f32::consts::PI;
use std::sync::mpsc::Sender;
use std::{cmp, mem};

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

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

}
@@ -30,7 +29,7 @@ impl AudioNodeEngine for AnalyserNode {
let mut push = inputs.blocks[0].clone();
push.mix(1, ChannelInterpretation::Speakers);

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

// analyser node doesn't modify the inputs
inputs
@@ -9,9 +9,8 @@ use param::{Param, ParamRate, ParamType, UserAutomationEvent};
use std::sync::mpsc::Sender;

/// Information required to construct an audio node
#[derive(Debug, Clone)]
pub enum AudioNodeInit {
AnalyserNode(Sender<Block>),
AnalyserNode(Box<FnMut(Block) + Send>),
BiquadFilterNode,
AudioBuffer,
AudioBufferSourceNode(AudioBufferSourceNodeOptions),
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.