npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jfxr

v0.13.0

Published

A library to render the sounds generated by jfxr.

Downloads

11

Readme

jfxr

This library is the core of the jfxr sound effects generator. jfxr generates sounds from a small JSON object containing parameters like pitch, duration and effects.

The library was developed only for running in the browser, but it can be made to work in a Node.js environment as well. If you need that, please file an issue.

Installation

The module is built using UMD, so it should work with AMD, CommonJS, or as a browser global. Use one of these approaches:

  • To use it in the browser without any module system, you can use the minified bundle dist/jfxr.min.js, and include it via a <script> tag:

      <script src="jfxr.js"></script>

    This will expose the API on the global jfxr object.

  • If you want to use it as a proper module:

      npm install --save jfxr

    Then import it and use it using one of:

      var jfxr = require('jfxr');  // Node.js syntax (CommonJS)
      import jfxr from 'jfxr';     // ES2015 module syntax

Example

This shows how you might run the synthesizer, and then play the resulting sound effect using the AudioContext API.

var AudioContext = new AudioContext();

var synth = new jfxr.Synth(mySound);

synth.run(function(clip) {
  var buffer = context.createBuffer(1, clip.array.length, clip.sampleRate);
  buffer.getChannelData(0).set(clip.toFloat32Array());
  context.resume().then(function() {
    var source = context.createBufferSource();
    source.buffer = buffer;
    source.start(0);
  });
});

API

Synth

The Synth class is what produces the sound. Its interface is very simple:

  • new Synth(str) creates a new synth object which can render the sound described by the string str. This must be a valid JSON string as saved from the jfxr app (the contents of a .jfxr file).

  • synth.run(callback) starts synthesis asynchronously. When complete, the callback is invoked with a single parameter, clip, which is a Clip object.

  • synth.cancel() cancels any in-progress synthesis.

Clip

The Clip class represents a rendered sound effect. It's just a wrapper around an array of samples.

  • clip.getNumSamples() returns the number of audio samples in the clip.

  • clip.getSampleRate() returns the sample rate in Hertz, typically 44100.

  • clip.toFloat32Array() returns a Float32Array containing the generated samples (mono). Usually the values will be between -1 and 1.

  • clip.toWavBytes() returns a Uint8Array containing the raw bytes of a WAV file, encoded in 16-bits PCM.