Rename Buffer::len() to Buffer::samples()
To reduce ambiguity.
This commit is contained in:
parent
9e1a888b38
commit
cb827d18dd
|
@ -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
|
chronological order. If a new feature did not require any changes to existing
|
||||||
code then it will not be listed here.
|
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]
|
## [2022-11-17]
|
||||||
|
|
||||||
- The `Params` derive macro now also properly supports persistent fields in
|
- The `Params` derive macro now also properly supports persistent fields in
|
||||||
|
|
|
@ -311,7 +311,7 @@ impl Crossover {
|
||||||
fn process_fir(&mut self, buffer: &mut Buffer, aux: &mut AuxiliaryBuffers) {
|
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
|
// In theory we could do smoothing in between processed blocks, but this hsould be fine
|
||||||
if self.should_update_filters() {
|
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;
|
let aux_outputs = &mut aux.outputs;
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl Plugin for PolyModSynth {
|
||||||
// num_remaining_samples, next_event_idx - block_start_idx)`. Because blocks also need to be
|
// 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
|
// split on note events, it's easier to work with raw audio here and to do the splitting by
|
||||||
// hand.
|
// hand.
|
||||||
let num_samples = buffer.len();
|
let num_samples = buffer.samples();
|
||||||
let sample_rate = context.transport().sample_rate;
|
let sample_rate = context.transport().sample_rate;
|
||||||
let output = buffer.as_slice();
|
let output = buffer.as_slice();
|
||||||
|
|
||||||
|
|
|
@ -84,10 +84,12 @@ impl DryWetMixer {
|
||||||
|
|
||||||
assert_eq!(buffer.channels(), self.delay_line.len());
|
assert_eq!(buffer.channels(), self.delay_line.len());
|
||||||
let delay_line_len = self.delay_line[0].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_before_wrap = buffer
|
||||||
let num_samples_after_wrap = buffer.len() - num_samples_before_wrap;
|
.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
|
for (buffer_channel, delay_line) in buffer
|
||||||
.as_slice_immutable()
|
.as_slice_immutable()
|
||||||
|
@ -101,7 +103,7 @@ impl DryWetMixer {
|
||||||
.copy_from_slice(&buffer_channel[num_samples_before_wrap..]);
|
.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
|
/// 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());
|
assert_eq!(buffer.channels(), self.delay_line.len());
|
||||||
let delay_line_len = self.delay_line[0].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 =
|
let read_position =
|
||||||
(self.next_write_position + delay_line_len - buffer.len() - latency) % delay_line_len;
|
(self.next_write_position + delay_line_len - buffer.samples() - latency)
|
||||||
let num_samples_before_wrap = buffer.len().min(delay_line_len - read_position);
|
% delay_line_len;
|
||||||
let num_samples_after_wrap = buffer.len() - num_samples_before_wrap;
|
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())
|
for (buffer_channel, delay_line) in buffer.as_slice().iter_mut().zip(self.delay_line.iter())
|
||||||
{
|
{
|
||||||
|
|
|
@ -449,7 +449,7 @@ impl Plugin for SpectralCompressor {
|
||||||
.global
|
.global
|
||||||
.dry_wet_ratio
|
.dry_wet_ratio
|
||||||
.smoothed
|
.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
|
// The dry and wet signals are in phase, so we can do a linear mix
|
||||||
dry_wet_mixer::MixingStyle::Linear,
|
dry_wet_mixer::MixingStyle::Linear,
|
||||||
self.stft.latency_samples() as usize,
|
self.stft.latency_samples() as usize,
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub struct Buffer<'a> {
|
||||||
impl<'a> Buffer<'a> {
|
impl<'a> Buffer<'a> {
|
||||||
/// Returns the number of samples per channel in this buffer.
|
/// Returns the number of samples per channel in this buffer.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn len(&self) -> usize {
|
pub fn samples(&self) -> usize {
|
||||||
self.num_samples
|
self.num_samples
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl<'a> Buffer<'a> {
|
||||||
SamplesIter {
|
SamplesIter {
|
||||||
buffers: self.output_slices.as_mut_slice(),
|
buffers: self.output_slices.as_mut_slice(),
|
||||||
current_sample: 0,
|
current_sample: 0,
|
||||||
samples_end: self.len(),
|
samples_end: self.samples(),
|
||||||
_marker: PhantomData,
|
_marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ struct NoSidechain;
|
||||||
impl StftInput for Buffer<'_> {
|
impl StftInput for Buffer<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn num_samples(&self) -> usize {
|
fn num_samples(&self) -> usize {
|
||||||
self.len()
|
self.samples()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -407,7 +407,7 @@ impl Cpal {
|
||||||
|
|
||||||
// TODO: Handle MIDI output events
|
// TODO: Handle MIDI output events
|
||||||
|
|
||||||
num_processed_samples += buffer.len() as i64;
|
num_processed_samples += buffer.samples() as i64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl Backend for Dummy {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
num_processed_samples += buffer.len() as i64;
|
num_processed_samples += buffer.samples() as i64;
|
||||||
|
|
||||||
let period_end = Instant::now();
|
let period_end = Instant::now();
|
||||||
std::thread::sleep((period_start + interval).saturating_duration_since(period_end));
|
std::thread::sleep((period_start + interval).saturating_duration_since(period_end));
|
||||||
|
|
Loading…
Reference in a new issue