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

Create an audio block pre-filled with silence #746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

h4yn0nnym0u5e
Copy link
Contributor

In theory passing a NULL pointer to an audio block implies a silent block, i.e. all zeroes. In many cases this can be dealt with simply, but on other occasions code is significantly simplified if a genuine audio block pre-filled with silent data is available. An example is a reverb tail when its source suddenly starts emitting NULL blocks; there are also multiple instances where hardware output objects have private zerodata[] arrays which could be replaced by using this common structure.

This modification adds an AudioStream::allocate_silent() function, which yields a "genuine" silent block for use on such occasions. It has the restriction that its data are read-only, but it can be transmitted and released as with any other block, so no special treatment is needed by "downstream" code. Any number of copies may be allocated at one time (the reference count is never modified), even if the block pool is exhausted.

At the time of writing this extension is not used within the (separately maintained) Audio library, but once part of the cores it will be possible to update the Audio library to make use of it, hopefully improving its clarity and efficiency.

In theory passing a NULL pointer to an audio block implies a silent block, i.e. all zeroes. In many cases this can be dealt with simply, but on other occasions code is significantly simplified if a genuine audio block pre-filled with silent data is available. An example is a reverb tail when its source suddenly starts emitting NULL blocks; there are also multiple instances where hardware output objects have private zerodata[] arrays which could be replaced by using this common structure.

This modification adds an AudioStream::allocate_silent() function, which yields a "genuine" silent block for use on such occasions. It has the restriction that its data are read-only, but it can be transmitted and released as with any other block, so no special treatment is needed by "downstream" code. Any number of copies may be allocated at one time (the reference count is never modified), even if the block pool is exhausted.

At the time of writing this extension is not used within the (separately maintained) Audio library, but once part of the cores it will be possible to update the Audio library to make use of it, hopefully improving its clarity and efficiency.
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

Successfully merging this pull request may close these issues.

1 participant