Closed sc0ttj closed 3 years ago
sfx('filename').play({ volume: 50 })
Sound
object, can assign volume and panningAlso see these:
The two above have a similar API to Component/useAudio - you pass in nice, descriptive objects, using a setState like method to update or create your sound stuff.
See the forked project (https://github.com/sc0ttj/audioFX) for snippets, ideas and features:
More reading and examples:
Do a useAudioUI
add-on for the useAudio
add-on: which provides auto-generated UI controls for each sound object for easy access to all the settings of the sound object.
Each control would contain the maths required to make the sliders/inputs etc change the settings nicely... for example, to adjust volume you need an exponential scale as 0.5 is not half as loud as 1.0:
if (rotation == -140) gain = 0; else gain = Math.pow(10, (rotation - 140) / 200);
Example:
Create a sound object with the following adjustable settings: volume
, pan
and lowpass filter
.
With the useAudioUI
enabled, you would just do mysound.render('.some-container')
and you will get HTML based UI added to the page, with inputs and sliders for volume, pan and the low pass filter settings.
When you update the controls, the sound properties will change "on the fly", as the sound is being played.
...Auto generating these UIs for each sound object should make it pretty easy to debug, play with, manage & monitor you applications sounds... It should also be a decent starting point for audio-focused web applications.
Done the main useAudio
add-on (not done any audioUI
add-ons though..)
See https://github.com/sc0ttj/component/#using-the-useaudio-module
Do an audio add-on, so adding fast & responsive audio to components is as easy as possible.
..Need to find some examples of good, lightweight (game related) audio libraries that can handle the job.
Example usage would be something like:
...which should provide the following:
audio.ok.fn()
- wherefn()
is one of these:play()
,pause()
,cancel()
,remove()
,effect()
audio.ok.volume = num
- set volume for left and right togetheraudio.ok.volume = [num, num]
- set volume for left and right separatelyExample usage: