sc0ttj / component

A tiny library for isomorphic JavaScript components
MIT License
2 stars 1 forks source link

Feature: audio add-on #36

Closed sc0ttj closed 3 years ago

sc0ttj commented 3 years ago

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:

import { Component, htmel, useAudio } from '@scottjarvis/component'

// setup a cached audio library
const audio = useAudio({
  ok: 'sounds/ok.mp3',
  back: 'sounds/back.mp3',
})

...which should provide the following:

Example usage:

// define a component 
const Foo = new Component({ ... })

// optionally, extract each sound to its own variable
const { ok, cancel } = audio

Foo.view = htmel`
  <div>
    <button onclick="${ok.play}">OK</button>
    <button onclick="${back.play}">Cancel</button>
  </div>`
sc0ttj commented 3 years ago

Component Audio add-ons

Also 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.

sc0ttj commented 3 years ago

See the forked project (https://github.com/sc0ttj/audioFX) for snippets, ideas and features:

More reading and examples:

sc0ttj commented 3 years ago

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.

sc0ttj commented 3 years ago

Done the main useAudio add-on (not done any audioUI add-ons though..)

See https://github.com/sc0ttj/component/#using-the-useaudio-module