Skip to content

Commit

Permalink
spectrusty-audio: BandLimited: num_samples_ended_frame method added a…
Browse files Browse the repository at this point in the history
…nd BandLimitedExt::num_samples_ended_frame_ext, guard render_audio_map_interleaved
  • Loading branch information
royaltm committed Jul 22, 2023
1 parent 90249da commit a0d1000
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spectrusty-audio/src/synth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ impl<T: Copy + Default, O> BandLimited<T, O> {
pub fn is_frame_ended(&self) -> bool {
self.last_nsamples.is_some()
}
/// Returns a number of samples of the last frame if [BandLimited::end_frame_at] or
/// [Blep::end_frame] has been called before the call to [BandLimited::next_frame].
///
/// The returned `Some(..)` indicates that audio samples can be produced from the last frame data.
#[inline]
pub fn num_samples_ended_frame(&self) -> Option<usize> {
self.last_nsamples
}
/// Ensures the frame buffer length is large enough to fit data for the specified `frame_time`
/// with additional `margin_time`.
///
Expand Down
18 changes: 18 additions & 0 deletions spectrusty-audio/src/synth/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub trait BandLimitedExt<T, S>: Blep<SampleDelta=T> {
fn shrink_to_fit_ext(&mut self);
/// Forwards to [BandLimited::is_frame_ended].
fn is_frame_ended_ext(&self) -> bool;
/// Forwards to [BandLimited::num_samples_ended_frame].
fn num_samples_ended_frame_ext(&self) -> Option<usize>;
/// Forwards to [BandLimited::next_frame].
fn next_frame_ext(&mut self);
/// A helper method for producing audio samples from a specific channel.
Expand Down Expand Up @@ -118,6 +120,10 @@ impl<D, B, T, S> BandLimitedExt<T, S> for D
(**self).is_frame_ended_ext()
}
#[inline]
fn num_samples_ended_frame_ext(&self) -> Option<usize> {
(**self).num_samples_ended_frame_ext()
}
#[inline]
fn next_frame_ext(&mut self) {
(**self).next_frame_ext()
}
Expand Down Expand Up @@ -158,6 +164,11 @@ impl<T, O, S> BandLimitedExt<T, S> for BandLimited<T, O>
(*self).is_frame_ended()
}

#[inline]
fn num_samples_ended_frame_ext(&self) -> Option<usize> {
(*self).num_samples_ended_frame()
}

#[inline]
fn next_frame_ext(&mut self) {
(*self).next_frame()
Expand All @@ -177,6 +188,9 @@ impl<T, O, S> BandLimitedExt<T, S> for BandLimited<T, O>
where S: FromSample<T>
{
for (nchan, ochan) in channel_map.into_iter().copied().enumerate() {
if ochan >= output_nchannels {
continue;
}
for (p, sample) in output[ochan..].iter_mut()
.step_by(output_nchannels)
.zip(self.sum_iter::<S>(nchan))
Expand Down Expand Up @@ -234,6 +248,10 @@ impl<T, S> BandLimitedExt<T, S> for BandLimitedAny<T>
implement_any! { self, b, b.is_frame_ended() }
}
#[inline]
fn num_samples_ended_frame_ext(&self) -> Option<usize> {
implement_any! { self, b, b.num_samples_ended_frame() }
}
#[inline]
fn next_frame_ext(&mut self) {
implement_any! { self, b, b.next_frame() }
}
Expand Down

0 comments on commit a0d1000

Please sign in to comment.