-
Notifications
You must be signed in to change notification settings - Fork 21
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
Iterator-based version of process_into_buffer() #51
Comments
I have been considering something like this and I think it's a good idea. I just didn't find the time to do anything yet. |
Instead of reinventing the wheel, how about using the audio crate? @udoprog is planning on releasing a major rewrite soon with the immanent stabilization of generic associated types. |
I'd be happy to join efforts if you're up for it. I've got a The idea for me is to release the 0.2 versions of all the |
|
Oh yeah that would work! I have my own set of audio signal traits and types in my codebase, but the Buf trait looks simple enough to implement for my types so it would definitely work. |
@udoprog Are you planning to rebase your rubato branch and open a PR? |
That branch started from Rubato in August 2021. Instead of trying to bring it up to date, I've started a new branch in #52 starting from #45. It's not done yet, but I opened the PR early to get preliminary feedback on the API. So far the refactoring has been straightforward albeit tedious. I changed the signature of fn process_into_buffer<In, Out>(
&mut self,
wave_in: &In,
wave_out: &mut Out,
active_channels_mask: Option<&[bool]>,
) -> ResampleResult<(usize, usize)>
where
In: ExactSizeBuf<Sample = T>,
Out: ExactSizeBuf<Sample = T> + BufMut<Sample = T>; The ExactSizeBuf bound is required rather than the base Buf trait for the The audio crate has a nice wrap module which provides wrappers for standard library types (Vecs and slices) that implement its traits without requiring copying. By re-exporting that module, Rubato can accept buffers in a variety of forms (including interleaved buffers) without requiring that Rubato users have to use the audio crate's buffer structs (though I recommend using them; their APIs are quite nice). |
#49 proposes making process_into_buffer() more generic by accepting a slice of mutable references instead of a slice of vectors. However, even this doesn't cater to all use cases. In my codebase, I have a multi-channel signal type which can have an arbitrary number of channels whose number isn't known at compile time. I can't make its interface return
&mut [&mut [f32]]
because that would be unsound: the caller could assign an arbitrary reference to the inner slice instead of using it in the intended way of simply mutating the inner slices. I'm solving the issue by having an interface that returns iterators of slices, so you can still do stuff likefor channel in signal.channels_mut() { for sample in channel { *sample *= 0.1 } }
.At the moment, interfacing my signal type with Rubato requires me to have a temporary buffer which I use to copy to/from my signal type and that's then processed by Rubato. If Rubato had a version of process_into_buffer() that accepted iterators of slices, I could get rid of the extra copies and temporary buffers.
I would be happy to submit a pull request for this if this sounds like something that you would consider accepting.
The text was updated successfully, but these errors were encountered: