hedron icon indicating copy to clipboard operation
hedron copied to clipboard

Toggle for advance audio features in the settings menu

Open cale-bradbury opened this issue 5 years ago • 3 comments

You can now disable audio texture generation and full audio spectrum computation from the settings menu, may as well get some speed gains if you aren't using them

cale-bradbury avatar Mar 22 '19 04:03 cale-bradbury

Hey mate, thanks for this! I've made some changes to the way settings are handled. Instead of doing the logic for settings inside of inputs/AudioAnalyzer, I've made a new settings listener. Feel like it's a bit weird to have settings logic next to all that complex audio processing stuff!

When you have time, would it be possible for you to update the docs to explain what these settings do? I'm not entirely sure myself! Would be great to see a working example of how to use these features. :)

Explanation of code changes: In order to achieve this I'm passing the settings into the update method of AudioAnalyzer. So we have the settings logic all happening in one place, updating the state. Then then the newly updated state gets fed into the AudioAnalyzer. It's best to keep to this sort of data flow.

In order to have a listener for settings, I had to create two different types of actions, we've got a U_SETTINGS_UPDATE and an R_SETTINGS_UPDATE. The U is for "user" and R is for "reducer". I'm using this pattern elsewhere in the app. Anything that is a U action doesn't affect the state directly, but instead is handled by a listener (or a saga, but I'm phasing those out eventually!). An action with an R is directly seen by the reducer, so directly updates the state. So the listener handles the user action, and then fires a reducer action after making some changes to the outcome of the payload.

funwithtriangles avatar Aug 16 '19 11:08 funwithtriangles

So right now, you can access the audio data as a 1D texture in I think that you can get it by importing AudioAnalyzer into your sketch and accessing it's .texture (for passing through to shaders) or .data (for accessing each individual sampled frequency), however, it appears that on my own branch I am adding it to the allParams that gets passed through the sketch update function.

I could add that to this branch, but maybe you have thoughts on a better way to make these kind of global objects accessible to a sketch @funwithtriangles

cale-bradbury avatar Nov 15 '19 04:11 cale-bradbury

@cale-bradbury We could either add this as an argument to the relevant methods or perhaps just expose it as a global variable?

Currently we have window.HEDRON which just has a dependencies property. But we could maybe we could also have a data property and put this in there? From my understanding we just need a single reference to it so it doesn't actually needed to be handed over on every update.

So something like this:

const data = window.HEDRON.data

class MySketch {
   ...
   update () {
      this.thingUses(data.audioTexture)
      this.otherThingUses(data.audioData)
   }
}

What do you think?

funwithtriangles avatar Jan 14 '20 14:01 funwithtriangles