Add custom sound effect Lua API #185
Draft
+174
−0
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.
Proof-of-concept sound effect API
Adds following functions:
this:create_sfx(sample_array: table, name: string?) -> sfx
Creates a sound effect. Sample array is an array of samples (floating-point, 2 channels at 44khz)
Each sample must be a floating point number in range:
-1.0..1.0
(out-of-range values are clamped)Number of samples must be a multiple of number of channels (2)
Ordering is as follows:
[right ch. sample 1][left ch. sample 1][right ch. sample 2][left ch. sample 2]...
and so onsfx:play(volume: number?)
sfx:play(volume: number?, x: number, y: number)
If position is omitted: Play sound effect globally with specified volume (full volume if nil/omitted)
If position is specified: Plays the sound effect locally at the specified coordinates with the specified volume (full volume if nil)
TODO:
sfx:play(...)
)extend
function to append extra chunks to the sfx__gc
gets called randomly?MAYBE:
create_sfx
.SfxMT
userdatas? which would allow this api to also play built-in ones