use block::{Block, Chunk};
use node::{AudioNodeEngine, BlockInfo};
use node::{AudioNodeType, ChannelInfo};
use param::{Param, ParamDir, ParamType};
#[derive(AudioNodeCommon)]
pub(crate) struct AudioListenerNode {
channel_info: ChannelInfo,
position_x: Param,
position_y: Param,
position_z: Param,
forward_x: Param,
forward_y: Param,
forward_z: Param,
up_x: Param,
up_y: Param,
up_z: Param,
}
impl AudioListenerNode {
pub fn new() -> Self {
Self {
channel_info: Default::default(),
position_x: Param::new(0.),
position_y: Param::new(0.),
position_z: Param::new(0.),
forward_x: Param::new(0.),
forward_y: Param::new(0.),
forward_z: Param::new(-1.),
up_x: Param::new(0.),
up_y: Param::new(1.),
up_z: Param::new(0.),
}
}
}
impl AudioNodeEngine for AudioListenerNode {
fn node_type(&self) -> AudioNodeType {
AudioNodeType::AudioListenerNode
}
fn process(&mut self, mut inputs: Chunk, info: &BlockInfo) -> Chunk {
debug_assert!(inputs.len() == 0);
let mut block = Block::for_channels_explicit(9);
self.position_x.flush_to_block(info, block.data_chan_mut(0));
self.position_y.flush_to_block(info, block.data_chan_mut(1));
self.position_z.flush_to_block(info, block.data_chan_mut(2));
self.forward_x.flush_to_block(info, block.data_chan_mut(3));
self.forward_y.flush_to_block(info, block.data_chan_mut(4));
self.forward_z.flush_to_block(info, block.data_chan_mut(5));
self.up_x.flush_to_block(info, block.data_chan_mut(6));
self.up_y.flush_to_block(info, block.data_chan_mut(7));
self.up_z.flush_to_block(info, block.data_chan_mut(8));
inputs.blocks.push(block);
inputs
}
fn input_count(&self) -> u32 {
0
}
fn get_param(&mut self, id: ParamType) -> &mut Param {
match id {
ParamType::Position(ParamDir::X) => &mut self.position_x,
ParamType::Position(ParamDir::Y) => &mut self.position_y,
ParamType::Position(ParamDir::Z) => &mut self.position_z,
ParamType::Forward(ParamDir::X) => &mut self.forward_x,
ParamType::Forward(ParamDir::Y) => &mut self.forward_y,
ParamType::Forward(ParamDir::Z) => &mut self.forward_z,
ParamType::Up(ParamDir::X) => &mut self.up_x,
ParamType::Up(ParamDir::Y) => &mut self.up_y,
ParamType::Up(ParamDir::Z) => &mut self.up_z,
_ => panic!("Unknown param {:?} for AudioListenerNode", id),
}
}
}