Skip to content
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

Add SampleBuffer::clear()? #126

Closed
torokati44 opened this issue May 12, 2022 · 4 comments
Closed

Add SampleBuffer::clear()? #126

torokati44 opened this issue May 12, 2022 · 4 comments
Milestone

Comments

@torokati44
Copy link

I found myself in a situation where clearing an existing SampleBuffer would be really useful.
If I understand it right, that would be only a matter of setting n_written to 0.

However, I found no way of doing this other than assigning a newly created, empty buffer to it.

Is this something that could be added perhaps?

@torokati44
Copy link
Author

And somewhat related: What's the point of storing n_written next to a Vec?
AFAIK Vec has this functionality built in.
That is: it has a separate capacity and len.

@pdeljanov
Copy link
Owner

Hi @torokati44,

Having a clear method is a good idea. I haven't spent much time considering use cases for SampleBuffer outside of just grabbing samples from AudioBuffers.

I've chosen not to resize the vector because it would likely involve extra zeroing operations, and/or extra allocations/deallocations. By managing the buffer myself I can avoid those.

That being said, it should really be a boxed slice of S instead of Vec<S> if the vector methods aren't being used.

@pdeljanov pdeljanov added this to the v0.5.1 milestone May 22, 2022
@torokati44
Copy link
Author

Having a clear method is a good idea.

Thanks for adding this to a milestone!

I haven't spent much time considering use cases for SampleBuffer outside of just grabbing samples from AudioBuffers.

This is how it came up:
torokati44/ruffle@c2ccacd
I hope the surrounding code can provide more context as to why.

I've chosen not to resize the vector because it would likely involve extra zeroing operations

Okay, I see, that makes sense. I only considered the allocation part, which would likely(?) not take place, but the zeroing almost certainly would, yeah.

pdeljanov added a commit that referenced this issue May 29, 2022
@torokati44
Copy link
Author

Fixed by 10e8a2d.
Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants