Skip to content

Commit

Permalink
wip no alloc on the audio thread for the new arch
Browse files Browse the repository at this point in the history
only plays the first tap, with bad filter params
it does draw the other tpas
  • Loading branch information
magnetophon committed Nov 19, 2024
1 parent 22828f1 commit 886939b
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 128 deletions.
53 changes: 51 additions & 2 deletions src/delay_tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::sync::Arc;
use synfx_dsp::fh_va::FilterParams;
use synfx_dsp::fh_va::LadderFilter;

use crate::{MAX_BLOCK_SIZE, NO_LEARNED_NOTE};

#[derive(Debug, Clone)]
pub struct DelayTap {
pub delayed_audio_l: Box<[f32]>,
Expand All @@ -11,6 +13,8 @@ pub struct DelayTap {
pub filter_params: Arc<FilterParams>,
pub ladders: LadderFilter,
pub mute_in_delayed: Box<[bool]>,
/// Fades between 0 and 1 with timings based on the global attack and release settings.
pub amp_envelope: Smoother<f32>,

/// The delay taps internal ID. Each delay tap has an internal delay tap ID one higher than the previous
/// delay tap. This is used to steal the last delay tap in case all 16 delay taps are in use.
Expand All @@ -25,9 +29,54 @@ pub struct DelayTap {
/// Whether the key has been released and the delay tap is in its release stage. The delay tap will be
/// terminated when the amplitude envelope hits 0 while the note is releasing.
pub releasing: bool,
/// Fades between 0 and 1 with timings based on the global attack and release settings.
pub amp_envelope: Smoother<f32>,

/// Are we currently muting? To determine if we need to trigger the amp envelope,
pub is_muted: bool,
/// Is set to true when the tap is created and false is created
/// and false when the amplitude envelope hits 0 while the note is releasing.
pub is_alive: bool,
}

impl DelayTap {
pub fn new(
filter_params: Arc<FilterParams>,
// should_update_filter: Arc<AtomicBool>,
// enabled_actions: Arc<AtomicBoolArray>,
// learned_notes: Arc<AtomicByteArray>,
) -> Self {
Self {
delayed_audio_l: vec![0.0; MAX_BLOCK_SIZE].into_boxed_slice(),
delayed_audio_r: vec![0.0; MAX_BLOCK_SIZE].into_boxed_slice(),
filter_params: filter_params.clone(),
ladders: LadderFilter::new(filter_params),
mute_in_delayed: vec![false; MAX_BLOCK_SIZE].into_boxed_slice(),
amp_envelope: Smoother::new(SmoothingStyle::Linear(13.0)),
internal_id: 0,
delay_time: 0,
note: NO_LEARNED_NOTE,
velocity: 0.0,
releasing: false,
is_muted: false,
is_alive: false,
}
}

pub fn init(
&mut self,
amp_envelope: Smoother<f32>,
internal_id: u64,
delay_time: u32,
note: u8,
velocity: f32,
releasing: bool,
is_muted: bool,
) {
self.amp_envelope = amp_envelope;
self.internal_id = internal_id;
self.delay_time = delay_time;
self.note = note;
self.velocity = velocity;
self.releasing = releasing;
self.is_muted = is_muted;
}
}
Loading

0 comments on commit 886939b

Please sign in to comment.