RustAudio / dasp

The fundamentals for Digital Audio Signal Processing. Formerly `sample`.
Other
883 stars 64 forks source link

Make IntoInterleavedSamples(Iterator) stop yielding samples on exhaustion #178

Closed AlexTMjugador closed 2 years ago

AlexTMjugador commented 2 years ago

IntoInterleavedSamples, especially its companion IntoInterleavedSamplesIterator type, is, in my opinion, very useful to easily process samples from an audio signal with elegance.

However, these helper types do not handle the source signal being exhausted at all. When the signal is exhausted, they always return equilibrium-valued samples, turning finite signals into infinite ones in an arguably counter-intuitive manner. I also think that quirk, even though it is documented, is somewhat hard to discover, because it is indirectly mentioned in the description of the IntoInterleavedSamplesIterator type, which is not shown when using the features of most IDEs.

In particular, I think the following reasons justify this change to achieve a better API:

dasp_signal::from_interleaved_samples_iter::<_, Stereo<f32>>(signal.into_interleaved_samples().into_iter().map(|s| s * 2)))

To address this situation, these changes modify how the related methods are implemented and their signatures. cargo test runs successfully, and I have updated the related examples and documentation accordingly.