Create an audio block pre-filled with silence #746
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.