Skip to content

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rescript-web-audio

npm

Zero-cost ReScript bindings for the Web Audio API

Installation

pnpm install rescript-web-audio

Then add rescript-web-audio to bs-dependencies in rescript.json.

{
    "name": "my-project",
    "bs-dependencies": ["@rescript/core", "rescript-web-audio"]
}

Usage

This library is heavily inspired by the design of rescript-webapi and ocaml-ffmpeg, which both use phantom types and implementation inheritance to translate an Object Oriented API into the functional paradigm of OCaml. Here is an example of what it looks like in the wild:

open WebAudio

// Constructors become ModuleName.make().
let ctx = AudioContext.make()

let osc = OscillatorNode.make(
  ctx,
  ~options={
    // Strings with a finite number of possible values become polymorphic variants.
    type_: #sine, 
    frequency: 440.0,
  },
)

let gain = GainNode.make(
  ctx,
  ~options={
    gain: 0.3,
  },
)

// Methods become functions.
let _ = OscillatorNode.connectNode(osc, gain)

// Fields become getters (and setters when appropriate).
let _ = GainNode.connectNode(gain, AudioContext.getDestination(ctx))

OscillatorNode.start(osc)

About

Rescript bindings for the Web Audio API

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages