one sample at a time, please.

jsdsp is a small addition to JavaScript that adds operator overloading. The addition overloads many arithmetic operators: +, +=, -, -=, *, *=, /, /=, ^, %, and %=. Consider the following, genish DSP code, which creates a sine oscillator modulating in frequency over 100Hz, and scaled in volume to 15 percent::

a = mul( cycle(.5), 100 )
b = mul( cycle( add( 220, a ), .15 )

Using .jsdsp, the same code can bee expressed as follows:

  'use jsdsp'  
  a = cycle(.5) * 100
  b = cycle( 220 + a ) * .15

The second example is both easier to write (once the boilerplate is out of the way) and easier to read. In addition to placing the 'use jsdsp' directives at the top of any block, you may also place it at the top of a function, similar to how 'use strict' is used. By limiting the scope of operator overloading to individual functions / blocks, jsdsp lets you freely mix regular math and logical operations with operator overloading in the same JavaScript files.

In the genish.js playground, you can turn on use of jsdsp by checking the corresponding box in the top header. jsdsp is realized as a small plugin to babel, a utility library for JavaScript that handles a variety of tasks related to compiling and transpiling.