JSPM

soundrive

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 4
    • Score
      100M100P100Q30204F
    • License MIT

    A simple but flexible audio oscillator for ECMAScript.

    Package Exports

    • soundrive

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (soundrive) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Soundrive

    A simple but flexible audio oscillator for ECMAScript.

    Preface

    The need for Soundrive came from wanting an oscillator that can smoothly sweep between frequencies while still being easy to use in Node.js and browsers.

    To use in the browser, you will probably have to compile it using Babel and/or a tool like Browserify.

    Installation

    npm install --save soundrive

    Yay! No dependencies!

    Use

    Simplest example:

    const Soundrive  = require('soundrive'),
          oscillator = Soundrive.Oscillator.create({frequency: {value: 12345}}),
          frameSize  = 4096,
          frame      = new Float32Array(frameSize);
    
    let i = 0;
    
    while (i < frameSize) {
      frame[i] = oscillator.process();
      i++;
    }
    

    The following creates a sweep(i.e. chirp) between two frequencies:

    const oscillator = Soundrive.Oscillator.create({
      frequency: {
        value: 1234,
        ease: 0.5
      }
    }),
    
    frameSize = 44100, // one second if that's the sample rate
    frame     = new Float32Array(frameSize);
    
    let i = 0;
    
    oscillator.changeFrequency(2345);
    
    while (i < frameSize) {
      frame[i] = oscillator.process();
      i++;
    }

    The resulting frame of samples will be 1 second with a 0.5 second transition between 1234hz and 2345hz.

    Mix

    You can "mix" oscillators together to produce multiple tones.

    const oscillator1 = Soundrive.Oscillator.create({frequency: {value: 770}}),
          oscillator2 = Soundrive.Oscillator.create({frequency: {value: 852}}),
          frameSize   = 4096,
          frame       = new Float32Array(frameSize),
          mix         = oscillator1.mix(oscillator2);
    
    let i = 0;
    
    while (i < frameSize) {
      frame[i] = mix.process()
      i++;
    }
    

    Testing

    Tests use Mocha. Use npm run test to perform them.