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

Microphone:getData Memory Behavior #158

Closed
bjornbytes opened this issue Oct 10, 2019 · 3 comments
Closed

Microphone:getData Memory Behavior #158

bjornbytes opened this issue Oct 10, 2019 · 3 comments

Comments

@bjornbytes
Copy link
Owner

Currently when you get samples from a Microphone using :getData, it always creates a new SoundData object.

Seemingly this is "bad" because it uses more memory and does more allocation work to create and destroy/garbage-collect all of these objects, even in situations where you only need to use the samples temporarily (performing one-time analysis on chunks, stream it to another API/system, etc.).

Can we add an interface that lets you pass in your own Blob or SoundData object that acts as a destination for the microphone samples? That way one object could be reused as the destination over and over again. It would be optional but gives you the ability to manage the memory better if you're willing to do so.

@bjornbytes
Copy link
Owner Author

If the Blob/SoundData is too small or incompatible with the microphone's capture settings, I think that would be an error.

@nevyn
Copy link
Contributor

nevyn commented Oct 15, 2019

Another alternative design is one of my favorite APIs in iOS, CMSampleBufferPool. Sample buffers are reference counted, and when spawned from a pool, this is overridden so that a count of 0 will return the buffer to the pool. This means the producer of audio sample buffers will create as many in-flight buffers as needed, and the consumer can hold on to them as long or short as they want. by setting a limit on the pool, that also provides a really nice backpressure mechanic.

anyways just my 2c :)

@bjornbytes
Copy link
Owner Author

Microphone:getData now takes ([sampleCount], [soundData], [offset]) !

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