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

Peak Buffer decay #50

Merged
merged 4 commits into from
Apr 20, 2024
Merged

Peak Buffer decay #50

merged 4 commits into from
Apr 20, 2024

Conversation

exa04
Copy link
Owner

@exa04 exa04 commented Apr 20, 2024

Implements decay for the peak buffer.

Changes the peak buffer's enqueueing behavior; It now behaves like a peak meter, by immediately snapping to values greater than its previous value, but decaying in amplitude if the current value is less than the previous one.

Changes:

  • Adds peek() method to the RingBuffer
  • Adds decay and decay weight fields to the PeakBuffer
  • Adds update() method to the PeakBuffer, for updating both the sample delta and decay weight
  • The PeakBuffer's sample rate is now left uninitialized until set_sample_rate is called.

Breaking Change

The parameter list for PeakBuffer::new() has now changed:

- fn new(size: usize, sample_rate: f32, duration: f32)
+ fn new(size: usize, duration:    f32, decay:    f32)

As an example, this is how you could adapt to this new parameter list if you have a PeakBuffer that you initialize inside your plug-in's default() function.

impl Default for DemoPlugin {
    fn default() -> Self {
        Self {
-           peak_buffer: Arc::new(Mutex::new(PeakBuffer::new(800, 44100.0, 10.0)))
+           peak_buffer: Arc::new(Mutex::new(PeakBuffer::new(800, 10.0, 0.)))
        }
    }
}

@exa04 exa04 marked this pull request as ready for review April 20, 2024 14:54
@exa04 exa04 merged commit 250c5e9 into main Apr 20, 2024
2 checks passed
@exa04 exa04 deleted the feature-peak-buffer-decay branch April 20, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant