All Projects → frantic0 → sema-engine

frantic0 / sema-engine

Licence: MIT license
A Signal Engine for a Live Code Language Ecosystem

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sema-engine

Twigl
twigl.app is an online editor for One tweet shader, with gif generator and sound shader, and broadcast live coding.
Stars: ✭ 145 (+383.33%)
Mutual labels:  webaudio
Tinysynth
A drums looper made with React and the WebAudio API
Stars: ✭ 238 (+693.33%)
Mutual labels:  webaudio
flirt
Are you ready to FLIRT with your wearable data?
Stars: ✭ 41 (+36.67%)
Mutual labels:  digital-signal-processing
Signal
A friendly music sequencer built with web technology
Stars: ✭ 166 (+453.33%)
Mutual labels:  webaudio
Babylon.js
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
Stars: ✭ 15,479 (+51496.67%)
Mutual labels:  webaudio
Three.js
JavaScript 3D Library.
Stars: ✭ 78,237 (+260690%)
Mutual labels:  webaudio
Fsynth
Web-based and pixels-based collaborative synthesizer
Stars: ✭ 146 (+386.67%)
Mutual labels:  webaudio
resimulated
1st place at Revision 2020 (PC 64K Intro)
Stars: ✭ 18 (-40%)
Mutual labels:  webaudio
Beact
🎸🎨 DJ and VJ all by yourself in seconds !
Stars: ✭ 223 (+643.33%)
Mutual labels:  webaudio
adsrnode
Advanced ADSR envelope node for WebAudio
Stars: ✭ 33 (+10%)
Mutual labels:  webaudio
Black
World's fastest HTML5 2D game engine   🛸
Stars: ✭ 174 (+480%)
Mutual labels:  webaudio
Pixi Sound
WebAudio API playback library, with filters. Modern audio playback for modern browsers.
Stars: ✭ 201 (+570%)
Mutual labels:  webaudio
webaudio-synth
WebAudio Polyphonic Synthesizer
Stars: ✭ 83 (+176.67%)
Mutual labels:  webaudio
Dynamicaudio.js
An interface for the Web Audio API with a Flash shim for older browsers
Stars: ✭ 164 (+446.67%)
Mutual labels:  webaudio
dspfun
Set of *nix utilities for experimentation and learning about spectral analysis of images
Stars: ✭ 21 (-30%)
Mutual labels:  digital-signal-processing
Guitar Tuner
Browser-based guitar tuner
Stars: ✭ 146 (+386.67%)
Mutual labels:  webaudio
Videojs Wavesurfer
video.js plugin that adds a navigable waveform for audio and video files
Stars: ✭ 242 (+706.67%)
Mutual labels:  webaudio
Shape-Your-Music
A web application for drawing music.
Stars: ✭ 106 (+253.33%)
Mutual labels:  webaudio
MarketCycles.jl
Digital Signal Processing Indicators For Market Data.
Stars: ✭ 26 (-13.33%)
Mutual labels:  digital-signal-processing
elm-audio-graph
Declarative Web Audio in Elm
Stars: ✭ 14 (-53.33%)
Mutual labels:  webaudio

sema-engine

Node.js CI version stability-experimental PRs Welcome Website GitHub license

sema-engine is a Javascript library that provides a high-performance audio engine for modern Web applications, with an easy-to-use API. It was extracted from sema, an app developed by @frantic0, @chriskiefer and @thormagnusson, and refactored for the MIMICproject.com.

sema-engine builds upon the following components:

  • the Maximilian DSP C++ library – from which sema-engine consumes DSP objects, as a git submodule

  • the Web Audio API Audio Worklet – packs a bespoke Audio Worklet node (src/engine.js) and processor (maxi-processor), which loads Maximilian DSP objects and dynamic program specifications

  • the Nearley compiler – generates parsers from an EBNF grammar specification

The sema-engine library exposes ES and UMD modules (works on the browser, with modern native JS modules and older JS module formats—amd, cjs for nodejs applications—think electron!).

sema-engine uses Github Actions workflows for build automation and continuous integration. The development builds propagate source maps (.map files)—so you can have modern debugging features like using breakpoints in the context of the client application. The production build ships all formats optimised and minified.

Usage

The sema-engine is published in the Node Package Manager (NPM) registry. If you are developing a Web application in a modern environment, and using a bundler such as Webpack or Rollup, you can easily add sema-engine as a dependency,

npm install sema-engine

For an advanced use, check how sema-engine integrates with Sema, a full-fledged application from which sema-engine was extracted.

You can use also use the sema-engine library modules in an a HTML file using inline <script> tags (check the published example which is output by the development build).

<script type="module">

    import {
      Engine,
      compile,
      Learner,
      getBlock
    } from "../index.mjs";

</script>

Note the that the script tag for the sema-engine module with index.mjs has type = module.

When initialising sema-engine, you need to pass the origin URL which points to where package dependencies – e.g. maxi-processor.js and maximilian.wasmmodule.js (check the dist/ folder) – should be served from.

  let engine,
      analyser = 0,
      dspCode,
      learner
      ;

  let origin = document.location.origin;

  const $ = (elemId, callback) =>
    document.getElementById(elemId).addEventListener("click", callback);

  $("playButton", "click", () => {
    engine = new Engine();
    engine.init(origin);
    engine.play();
  })

Note that the engine will make its operations depend on the origin URL for instance for loading audio samples, which should be pointed to using a relative path to the origin like so:

  $("loadSamplesButton", "click", () => {
    if(engine){
      try{
        engine.loadSample("909.wav",       "/audio/909.wav");
        engine.loadSample("909b.wav",      "/audio/909b.wav");
        engine.loadSample("909closed.wav", "/audio/909closed.wav");
        engine.loadSample("909open.wav",   "/audio/909closed.wav");
      } catch (error) {
        console.error("ERROR: Failed to compile and eval: ", error);
      }
    }
    else throw new Error('ERROR: Engine not initialized. Press Start engine first.')
  })

  $("learnerButton", "click", async () => {
    if(engine){
      try{
        learner = new Learner();
        await engine.addLearner('l1', learner);
      }catch(error){
        console.error("ERROR: Error creating or initialising learner: ", r);
      }
    }
  });
</script>

To compile the livecode, you need to do it against its grammar language specification, with the compile function. Only then you can inject the resulting code in the engine and evaluate it.

For the JS code, we provide getBlock, an utility function that pulls code from an editor block. Blocks in a Codemirror editor instance are delimited by ____ (3 or more underscores).

  const evalLiveCode = () => {
    if(engine){
      try{
        const { errors, dspCode } = compile( editorGrammar.getValue(), editorLivecode.getValue() );
        if(dspCode){
          console.info(editorLivecode.getValue());
          engine.eval(dspCode);
        }
      } catch (err) {
        console.error("ERROR: Failed to compile and eval: ", err);
      }
    }
    else throw new Error('ERROR: Engine not initialized. Please press Start Engine first.')
  }

  const evalJs = async () => {
    if(learner && editorJS){
      const code = getBlock(editorJS);
      learner.eval(code);
    }
    else throw new Error('ERROR: Learner not initialized. Please press Create Learner first.')
  }

Prerequisites

If you would like to make contributions to the sema-engine custom WAAPI audio worklet processor, there are two compilers required to build it:

Check the Makefile to better understand the compilation workflow.

Build

If you are cloning this library for the first time:

  1. Initialise the Maximilian and the Open303 submodules
git submodule update --init --recursive
  1. Build the WAAPI Audio Worklet processor with Maximilian Pure JS, WebAssembly modules, using CHEERP and Emscripten. Build the sema-engine library into UMD and ES modules.
make
  1. Build the sema-engine library into UMD and ES modules, after changes to any source file
npm run build
  1. Test the sema-engine library in a local example
npm run dev

To update submodule if there are any upgrades

git submodule update --remote --merge

Tests and Examples

The sema-engine library uses Mocha for unit and integration tests.

The development build outputs the example above, which you can use to learn and test out how to work with the engine.

Documentation

The sema-engine has small API surface that you can find more about on this project's wiki.

Contributing

Pull requests are welcome! Fork the the project and submit PRs to the develop branch. Please observe the Contributing guidelines for other ways to contribute (issues, documentation, styles, etc).

Related Publications

Bernardo, F., Kiefer, C., Magnusson, T. (2020). A Signal Engine for a Live Code Language Ecosystem. Journal of Audio Engineering Society, Vol. 68, No. 1, October, DOI: https://doi.org/10.17743/jaes.2020.0016

Funding

This project has received funding from two UKRI/AHRC research grants MIMIC: Musically Intelligent Machines Interacting Creatively (Ref: AH/R002657/1) and Innovating Sema (Ref: AH/V005154/1).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].