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

Fix AudioBuffer::getChannelData implementation #80

Open
b-ma opened this issue Feb 6, 2024 · 1 comment
Open

Fix AudioBuffer::getChannelData implementation #80

b-ma opened this issue Feb 6, 2024 · 1 comment

Comments

@b-ma
Copy link
Collaborator

b-ma commented Feb 6, 2024

This function relies on unsafe to be able to mutate the returned channel, which may be a problem in some situations

I think this inhibits some undefined behaviour - theoretically.

You are asking the compiler for a mutable reference of the AudioBuffer, but then this information is 'erased' via the unsafe slice cast. This means if you call the method twice and mutate one of the copies, the compiler could assume the other copy will not be affected.

I don't have a clear solution though (perhaps return the same TypedArray via set_property??) - should we add an issue to address this later?

Originally posted by @orottier in #79 (comment)

@b-ma
Copy link
Collaborator Author

b-ma commented Feb 22, 2024

Another weird case to handle:

  1. load some AudioBuffer
  2. call getChannelData and store to returned Float32Array to use the buffer as an envelop for example
  3. AudioBuffer is garbage collected at some point
  4. The underlying memory of the Float32Array is somehow reused and the buffer ends up being full of garbage

@b-ma b-ma changed the title Review AudioBuffer::getChannelData implementation Fix AudioBuffer::getChannelData implementation Mar 30, 2024
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

1 participant