REF / Music API / Util

Ascene . Agraph . Aengine . Anode
Songbook . Song
WSLoader . Sound Loaders
Random . Rhythm . TimeKeeper
MIDI . OSC . HID . Piano
Plot . Envelope . Util
Music Theory with Tonal

right-click to navigate to page sections


Util offers a small collection of miscellaneous utility functions.

API

These functions reside within the Util namespace.

Function Description
FromDecibels(dB) Returns a linear gain value from a dB value. eg: -5dB->.5, 0dB->1, 3dB->1.4
LogInterp(pct, x1, x2, ctx=null) Linearly interpolate between x1 and x2 in perceptual (log) space. Used to interpolate frequency and loudness. The optional ctx parameter ({}) can be used to cache calculations for inner-loop usage.
GetFileTimestamp() Returns a standard timestamp string of the form: "2025-03-04_12-16-08" for use in filenames for recordings.
TimeIt(f, num) Runs the provided function, f, num times and returns its average runtime.
async SleepMS(ms) async function that can be awaited.
ParseYaml(str) Returns the object or array that results from parsing the provided YAML string.
async FetchURL(url, filetype) * Fetches data from the internet url. Returns a promise that resolves to the string, object or array associated with resourcetype. Types available: (json, xml, text)

Whitelisted URLS

When operating within a web browser, the ability for your scripts to fetch from arbitrary internet resources is constrained for security purposes.

For the purposes of Hz soundscaping and Util.FetchURL, we've whitelisted the following internet locations that can provide useful live fodder for your soundscapes. To use these sites requires knowledge of the various APIs and responses specific to each site.

Weather

News

Finance

Science

Time

Quote of the Day