Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@elemaudio/node-renderer
Advanced tools
Official package for rendering Elementary Audio applications in Node.js
The official package for rendering Elementary applications at the command line using Node.js.
Currently, applications using this renderer at the command line must be invoked by Elementary's command line binaries, which are installed separately. The command line binaries are nearly a forked version of Node.js: that is, you can write and run your code as if you're writing a standard Node.js application that just also happens to know how to make sound.
This package will be used alongside @elemaudio/core
. Please see the full
documentation at https://www.elementary.audio/docs
First, the npm package.
npm install --save @elemaudio/node-renderer
Next, the command line binaries.
$ curl -fsSL https://www.elementary.audio/install.sh | sh
Windows binaries must be installed manually. You can download the binaries from the releases page on this repository, and unpack the zip file to a directory of your choosing.
import {el} from '@elemaudio/core';
import {default as core} from '@elemaudio/node-renderer';
core.on('load', function() {
core.render(
el.mul(0.3, el.cycle(440)),
el.mul(0.3, el.cycle(440)),
);
});
core.initialize();
import NodeRenderer from '@elemaudio/node-renderer';
// Or,
import {default as core} from '@elemaudio/node-renderer';
core.initialize()
The default export from the @elemaudio/node-renderer
package is a singleton instance which communicates with the underlying
audio driver. That instance must be initialized after you've added a listener for the load
event.
This method takes no arguments; configuring the audio driver is done at the command line at the time of invocation. Run elementary --help
at your command line for options.
core.render(...args: Array<NodeRepr_t | number>) : RenderStats;
Performs the reconciliation process for rendering your desired audio graph. This method expects one argument
for each available output channel. That is, if you want to render a stereo graph, you will invoke this method
with two arguments: core.render(leftOut, rightOut)
.
The RenderStats
object returned by this call provides some insight into what happened during the reconciliation
process: how many new nodes and edges were added to the graph, how long it took, etc.
The NodeRenderer
singleton instance is an event emitter with an API matching that of the Node.js Event Emitter
class.
The renderer will emit events from underlying audio processing graph for nodes such as el.meter
, el.snapshot
, etc. See
the reference documentation for each such node for details.
When working with the elementary
command line tool, the following help menu is available
by passing the --help
or -h
flag. Here we'll go into more detail about each of the available options.
Usage: elementary [options] [node_options] file.js
Run the given file with elementary.
Examples:
elementary -i 2 -o 2 path/to/flanger.js
elementary --inputs=2 --outputs=2 path/to/flanger.js
Options:
-h, --help Print this help and exit
-i, --inputs Set the number of input channels with which to open the driver. Default: 0.
-o, --outputs Set the number of output channels with which to open the driver. Default: 2.
-s, --stack Set the rendering stack size. Default: 512.
-e, --heap Set the rendering heap size. Default: 512.
-q, --quantize Set the rendering quantization interval. Default: -1 (off).
-f, --file Drive the runtime from an audio file instead of from system input.
-i, --inputs
-o, --outputs
core.render
: e.g. core.render(kick, snare, hat)
, as the arguments
here posititionally correspond with which output channel you're writing to.-s, --stack
-e, --heap
Finally, any options present at the command line that are not consumed while processing for the above list will be passed onto initialize Node.js.
With that, you can always pass Node.js-specific options such as --prof
to enable such behavior in Node.
The Elementary command line application is itself a binary application much like Node.js, designed to execute your scripts to build up audio signal processes. Elementary is in fact built on Node.js itself, hence the tight compatibility.
Specifically, Elementary is currently built on Node.js v16.0.0 (7162e68), therefore the following compatibility constraints apply:
elementary --prof myapp.js
is much the same as writing node --prof myapp.js
If your application has compatibility requirements not addressed here, or must be tied to a different version of Node.js, please open an issue.
Unlike the Web Renderer and the Offline Renderer, the Elementary runtime in the
Node Renderer does have access to your file system. Therefore when you try to reference sample files during your render step, such as
with el.sample({path: '/real/path/on/disk.wav'}, el.train(1), 1)
, Elementary will attempt to find and load that file from your
file system.
Currently, only wav files are supported for this file loading mechanism.
:::info In a near future update, the NodeRenderer will move to using a virtual file system like the Web and Offline renderers. At that time, loading directly from disk inside the runtime will be deprecated. :::
NodeRenderer is currently the only renderer which does support MIDI out of the box. By default, when invoked at the command line, the Elementary runtime will establish listeners to every available MIDI input device on your system.
:::caution In a near future update, MIDI handling will be deprecated from the command line tool. You're encouraged to explore MIDI handling alternatives such as WebMIDI.js, which can already be used with the Elementary command line binaries. :::
The 'midi'
event fires on the singleton renderer instance any time the runtime receives a
MIDI event from any connected and enabled device, which may yield frequent MIDI events.
The 'midi'
event is fired with a single argument: an object describing the event.
For example:
// A noteOn event
{
bytes: '90456a',
noteFrequency: 440,
noteName: 'A3',
noteNumber: 69,
source: 'Moog Grandmother',
type: 'noteOn'
}
// A noteOff event
{
bytes: '80456a',
noteFrequency: 440,
noteName: 'A3',
noteNumber: 69,
source: 'Moog Grandmother',
type: 'noteOff'
}
// A controller event
{
bytes: 'b0082d',
channel: 1,
source: 'Moog Grandmother',
target: 8,
type: 'controller',
value: 45
}
Note: all MIDI events are enumerated with at least a source
, type
, and bytes
property. Events for which
the runtime could not derive a helpful type will show type: "raw"
. The bytes
property is a hexidecimal string
containing the raw MIDI payload for further deserialization in such cases.
Supported events:
FAQs
Official package for rendering Elementary Audio applications in Node.js
We found that @elemaudio/node-renderer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.