Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
xasopheno committed Aug 8, 2023
1 parent 1688223 commit 3eee40f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
19 changes: 15 additions & 4 deletions instrument/src/renderable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,29 @@ pub fn point_op_to_gains(
return (0.0, 0.0);
}

let f = m_a_and_basis_to_f64(basis.f, point_op.fm, point_op.fa);
// let f = m_a_and_basis_to_f64(basis.f, point_op.fm, point_op.fa);

let pm = r_to_f64(point_op.pm);
let pa = r_to_f64(point_op.pa);
let g = r_to_f64(point_op.g);
let base_p = r_to_f64(basis.p);
let base_g = r_to_f64(basis.g);

let ild = calculate_ild(angle, f);
// let ild = calculate_ild(angle, f);

let l_gain = g * (((pa.mul_add(pm, 1.0 + ild)) + base_p) / 2.0) * base_g;
let r_gain = g * (((pa.mul_add(pm, -1.0 - ild)) + base_p) / -2.0) * base_g;
// let l_gain = g * (((pa.mul_add(pm, 1.0 + ild)) + base_p) / 2.0) * base_g;
// let r_gain = g * (((pa.mul_add(pm, -1.0 - ild)) + base_p) / -2.0) * base_g;
let l_gain = if *point_op.g.numer() == 0 {
0.0
} else {
g * (((pa.mul_add(pm, 1.0)) + r_to_f64(basis.p)) / 2.0) * r_to_f64(basis.g)
};

let r_gain = if *point_op.g.numer() == 0 {
0.0
} else {
g * (((pa.mul_add(pm, -1.0)) + r_to_f64(basis.p)) / -2.0) * r_to_f64(basis.g)
};

(l_gain, r_gain)
}
Expand Down
4 changes: 4 additions & 0 deletions instrument/src/renderable/render_voice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ impl RenderVoice {
}
}

pub fn push_ops(&mut self, ops: &[RenderOp]) {
self.ops.extend_from_slice(ops);
}

/// Recursive function to prepare a batch of RenderOps for rendering
/// Initially pass in None as result
pub fn get_batch(
Expand Down
29 changes: 28 additions & 1 deletion src/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use weresocool::manager::prepare_render_outside;
use weresocool::manager::RenderManager;
use weresocool::portaudio::real_time_render_manager;
use weresocool::ui::were_so_cool_logo;
use weresocool::RenderVoice;
use weresocool_core::portaudio::real_time_render_manager::real_time_audio_visual_render_manager;

pub enum Play {
Expand All @@ -31,6 +32,32 @@ pub fn play_file(filename: String, working_path: PathBuf, play: Play) -> Result<
}
}

pub fn play_once_render_voices(render_voices: Vec<RenderVoice>) -> Result<(), Error> {
let (tx, rx) = std::sync::mpsc::channel::<bool>();
let render_manager = Arc::new(Mutex::new(RenderManager::init(None, Some(tx), true, None)));

render_manager
.lock()
.unwrap()
.push_render(render_voices, true);

let mut stream = real_time_render_manager(Arc::clone(&render_manager))?;

stream.start()?;
// rx.recv blocks until it receives data and
// after that, the function will complete,
// stream will be dropped, and the application
// will exit
match rx.recv() {
Ok(_) => {}
Err(e) => {
println!("{}", e);
std::process::exit(1);
}
};
Ok(())
}

pub fn play_once(filename: String, working_path: PathBuf) -> Result<(), Error> {
were_so_cool_logo(Some("Playing"), Some(filename.clone()));

Expand All @@ -50,7 +77,7 @@ pub fn play_once(filename: String, working_path: PathBuf) -> Result<(), Error> {
// rx.recv blocks until it receives data and
// after that, the function will complete,
// stream will be dropped, and the application
// will exit.
// will exit
match rx.recv() {
Ok(_) => {}
Err(e) => {
Expand Down

0 comments on commit 3eee40f

Please sign in to comment.