diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md index 045b3415..9722955e 100644 --- a/BREAKING_CHANGES.md +++ b/BREAKING_CHANGES.md @@ -6,6 +6,11 @@ new and what's changed, this document lists all breaking changes in reverse chronological order. If a new feature did not require any changes to existing code then it will not be listed here. +## [2023-01-05] + +- `Buffer::len()` has been renamed to `Buffer::samples()` to make this less + ambiguous. + ## [2022-11-17] - The `Params` derive macro now also properly supports persistent fields in diff --git a/plugins/crossover/src/lib.rs b/plugins/crossover/src/lib.rs index b4a6b2a8..bb4147e4 100644 --- a/plugins/crossover/src/lib.rs +++ b/plugins/crossover/src/lib.rs @@ -311,7 +311,7 @@ impl Crossover { fn process_fir(&mut self, buffer: &mut Buffer, aux: &mut AuxiliaryBuffers) { // In theory we could do smoothing in between processed blocks, but this hsould be fine if self.should_update_filters() { - self.update_filters(buffer.len() as u32); + self.update_filters(buffer.samples() as u32); } let aux_outputs = &mut aux.outputs; diff --git a/plugins/examples/poly_mod_synth/src/lib.rs b/plugins/examples/poly_mod_synth/src/lib.rs index 9505588b..02b366ac 100644 --- a/plugins/examples/poly_mod_synth/src/lib.rs +++ b/plugins/examples/poly_mod_synth/src/lib.rs @@ -183,7 +183,7 @@ impl Plugin for PolyModSynth { // num_remaining_samples, next_event_idx - block_start_idx)`. Because blocks also need to be // split on note events, it's easier to work with raw audio here and to do the splitting by // hand. - let num_samples = buffer.len(); + let num_samples = buffer.samples(); let sample_rate = context.transport().sample_rate; let output = buffer.as_slice(); diff --git a/plugins/spectral_compressor/src/dry_wet_mixer.rs b/plugins/spectral_compressor/src/dry_wet_mixer.rs index 4a068992..4d3e0c14 100644 --- a/plugins/spectral_compressor/src/dry_wet_mixer.rs +++ b/plugins/spectral_compressor/src/dry_wet_mixer.rs @@ -84,10 +84,12 @@ impl DryWetMixer { assert_eq!(buffer.channels(), self.delay_line.len()); let delay_line_len = self.delay_line[0].len(); - assert!(buffer.len() <= delay_line_len); + assert!(buffer.samples() <= delay_line_len); - let num_samples_before_wrap = buffer.len().min(delay_line_len - self.next_write_position); - let num_samples_after_wrap = buffer.len() - num_samples_before_wrap; + let num_samples_before_wrap = buffer + .samples() + .min(delay_line_len - self.next_write_position); + let num_samples_after_wrap = buffer.samples() - num_samples_before_wrap; for (buffer_channel, delay_line) in buffer .as_slice_immutable() @@ -101,7 +103,7 @@ impl DryWetMixer { .copy_from_slice(&buffer_channel[num_samples_before_wrap..]); } - self.next_write_position = (self.next_write_position + buffer.len()) % delay_line_len; + self.next_write_position = (self.next_write_position + buffer.samples()) % delay_line_len; } /// Mix the dry signal into the buffer. The ratio is a `[0, 1]` integer where 0 results in an @@ -134,12 +136,13 @@ impl DryWetMixer { assert_eq!(buffer.channels(), self.delay_line.len()); let delay_line_len = self.delay_line[0].len(); - assert!(buffer.len() + latency <= delay_line_len); + assert!(buffer.samples() + latency <= delay_line_len); let read_position = - (self.next_write_position + delay_line_len - buffer.len() - latency) % delay_line_len; - let num_samples_before_wrap = buffer.len().min(delay_line_len - read_position); - let num_samples_after_wrap = buffer.len() - num_samples_before_wrap; + (self.next_write_position + delay_line_len - buffer.samples() - latency) + % delay_line_len; + let num_samples_before_wrap = buffer.samples().min(delay_line_len - read_position); + let num_samples_after_wrap = buffer.samples() - num_samples_before_wrap; for (buffer_channel, delay_line) in buffer.as_slice().iter_mut().zip(self.delay_line.iter()) { diff --git a/plugins/spectral_compressor/src/lib.rs b/plugins/spectral_compressor/src/lib.rs index 816115c9..0b4ecb02 100644 --- a/plugins/spectral_compressor/src/lib.rs +++ b/plugins/spectral_compressor/src/lib.rs @@ -449,7 +449,7 @@ impl Plugin for SpectralCompressor { .global .dry_wet_ratio .smoothed - .next_step(buffer.len() as u32), + .next_step(buffer.samples() as u32), // The dry and wet signals are in phase, so we can do a linear mix dry_wet_mixer::MixingStyle::Linear, self.stft.latency_samples() as usize, diff --git a/src/buffer.rs b/src/buffer.rs index 1e086fd5..f49f8871 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -34,7 +34,7 @@ pub struct Buffer<'a> { impl<'a> Buffer<'a> { /// Returns the number of samples per channel in this buffer. #[inline] - pub fn len(&self) -> usize { + pub fn samples(&self) -> usize { self.num_samples } @@ -69,7 +69,7 @@ impl<'a> Buffer<'a> { SamplesIter { buffers: self.output_slices.as_mut_slice(), current_sample: 0, - samples_end: self.len(), + samples_end: self.samples(), _marker: PhantomData, } } diff --git a/src/util/stft.rs b/src/util/stft.rs index 4362a4e6..9d34bdfc 100644 --- a/src/util/stft.rs +++ b/src/util/stft.rs @@ -63,7 +63,7 @@ struct NoSidechain; impl StftInput for Buffer<'_> { #[inline] fn num_samples(&self) -> usize { - self.len() + self.samples() } #[inline] diff --git a/src/wrapper/standalone/backend/cpal.rs b/src/wrapper/standalone/backend/cpal.rs index 02cd3179..7bb6cd4c 100644 --- a/src/wrapper/standalone/backend/cpal.rs +++ b/src/wrapper/standalone/backend/cpal.rs @@ -407,7 +407,7 @@ impl Cpal { // TODO: Handle MIDI output events - num_processed_samples += buffer.len() as i64; + num_processed_samples += buffer.samples() as i64; } } } diff --git a/src/wrapper/standalone/backend/dummy.rs b/src/wrapper/standalone/backend/dummy.rs index 9baa7fb8..acad8b6c 100644 --- a/src/wrapper/standalone/backend/dummy.rs +++ b/src/wrapper/standalone/backend/dummy.rs @@ -64,7 +64,7 @@ impl Backend for Dummy { break; } - num_processed_samples += buffer.len() as i64; + num_processed_samples += buffer.samples() as i64; let period_end = Instant::now(); std::thread::sleep((period_start + interval).saturating_duration_since(period_end));