0.2.1 • Published 5 years ago

@freehand/tssynth v0.2.1

Weekly downloads
1
License
-
Repository
github
Last release
5 years ago

tssynth

I'm just publishing this as a package called @freehand/tssynth temporarily until gundy gets around to publishing the new version himself.

port from jssynth

Notes on TypeScript conversion:

This version of jssynth has been ported to TypeScript. The project now requires the following tools:

NodeJS environment: use Nodenv (not NVM) Build tool: Yarn (not NPM, easiest to install via npm install -g yarn) Test tool: Alsatian (run tests with yarn run unit-tests)

Dev setup steps:

  1. checkout this project and cd into it
  2. Make sure nodenv is installed
  3. npm install -g yarn # Installs yarn globally for current node version
  4. nodenv rehash # Tells nodenv to make the new yarn command available
  5. yarn # Installs all packages
  6. yarn unit-tests # Runs the unit tests
  7. yarn build # Builds the project
  8. yarn package # Generates a release package

IDE:

Recommend using Visual Studio Code with "TypeScript TSLint Plugin"

About:

JSSynth is a pure JavaScript library for dealing with sampled and synthesised digital audio.

It comprises a mixer component and an integration layer to output sampled audio via the web audio API, as supported in most modern browsers.

Here's an example of using the mixer to whet your appetite:

    var sample = new Sample(.....);
    var mixer = new Mixer({ numChannels: 8, volume: 64 });  /* initialise the mixer */
    var audioOut = new WebAudioDriver(mixer);               /* initialise web audio API w/ mixer */
    audioOut.start();                                       /* start audio mixing / playing */
  
    /*
     * at this time audio output has started, mixer.mix() is being called in the background
     * to fill the audio buffers (it's triggered by the web audio layer), and user code
     * is able to start triggering samples, eg.
     */
    
    mixer.triggerSample(0, sample, 440);                        /* play sample, channel 0 @ A440 */

Samples can be either function-based (ie. fully synthetic), or pre-canned sampled digital audio.
JSSynth is able to interpret and playback 8/16/24-bit, signed/unsigned, mono/stereo samples if required.

In order to allow accurate timing, JSSynth provides a "secondsPerMix" property, which sets how many seconds worth of audio data JSSynth will generate in each call to the Mixer.mix() method.

The WebAudioDriver interface allows user-code to register a pre-mix callback. This means that your code can be notified whenever another x seconds worth of audio data is about to be requested, and perform whatever updates to the audio state that you need to. This is very useful for creating applications like synthesised audio players.

After calling the pre-mix callback, WebAudioDriver will call Mixer.mix() to generate the next batch of samples for playback.

Please look at my other projects for an example of a pure JavaScript implementation of a .MOD/.S3M file player that has been built on top of the JSSynth API. This should help to give an idea of what might be possible.

Games, demos, interactive UI's, DSP related apps or prototypes, the sky is the limit.

... and that's all there is to it really.

If you use JSSynth or any of the related example code in any projects, please drop by and let me know.