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

bach.js

v0.3.0-pre1

Published

A modular synthesis library. Nothing works yet.

Downloads

1

Readme

CLJS Bach

A Clojurescript wrapper for the Web Audio API, extracted from Klangmeister. Vanilla javascript support is coming soon.

Build Status

Importing it into your project

CLJS Bach is a Clojurescript library. To include it in your Clojurescript project, you need to include the following in your project.clj or build.boot.

Clojars Project

Once you've done that, you can use it like any other library.

Usage

Firstly, create an audio context. You only need one, and if you keep creating them the browser will run out and error on you.

(defonce context (audio-context))

See Klangmeister for examples of how to build synthesisers. Here's a simple one. Note the use of connect-> to join together simple parts together.

(defn ping [freq]
  (connect->
    (square freq)         ; Try a sawtooth wave.
    (percussive 0.01 0.4) ; Try varying the attack and decay.
    (gain 0.1)))          ; Try a bigger gain.

Once you have a synthesiser, connect it to destination and use run-with to give it an audio context, a time to run at and a duration.

; Play the ping synthesiser now, at 440 hertz.
(-> (ping 440)
    (connect-> destination)
    (run-with context (current-time context) 1.0)))

If you forget to connect a synthesiser to destination, then you'll here no sound, because nothing will be sent to the speakers.

API

Machinery

  • (audio-context) - returns the browser's Audio Context.
  • (current-time context) - returns the current time according to the supplied audio context.
  • (run-with node context at duration) - runs the synthesiser in the supplied context.
  • destination - a node representing the browser's speakers.

Oscillators

  • (sawtooth frequency) - a sawtooth wave oscillating at frequency hertz.
  • (sine frequency) - a sine wave oscillating at frequency hertz.
  • (square frequency) - a square wave oscillating at frequency hertz.
  • (triangle frequency) - a triangle wave oscillating at frequency hertz.
  • white-noise - a node emitting random noise.

Modifiers

  • (adsr attack decay sustain release) - an envelope for shaping a note.
  • (gain level) - a node that multiplies its input by level.
  • (high-pass cutoff) - filter out frequencies below cutoff.
  • (low-pass cutoff) - filter out frequencies above cutoff.
  • (percussive attack decay) - a simple envelope for shaping a note.

Effects

  • (stereo-panner pan) - pan the signal left (-1) or right (1).
  • (delay-line seconds) - delay the signal by seconds.
  • reverb - apply reverb to the signal.

Combinators

  • (connect-> node1 node2) - connect node1's output to node2's input.
  • (add node1 node2) - add together the outputs of node1 and node2.

Getting a REPL

CLJS Bach relies on the Web Audio API, so it will only work if your javascript environment supports that. Fortunately, all major browsers except Internet Explorer do (and it will on next major release).

If you have this project checked out locally, you can use the Figwheel REPL. Firstly, start Figwheel.

lein figwheel

Figwheel will tell you where's running, so you can open it in your browser.

Figwheel: Starting server at http://localhost:3449
....
Prompt will show when Figwheel connects to your application

Once you've done that, the REPL will come to life.

To quit, type: :cljs/quit
cljs.user=>

From then on, you can type commands into the REPL, and they'll be executed by your browser.

Design

CLJS Bach is purely functional. To make synthesiser composition easier, synthesisers are actually functions that take an audio context, a time and a duration and return the synthesis graph.

(defn some-synth [...]
  (fn [context at duration]
    ; Create a graph of synthesis nodes.
  ))

That's why you need run-with to make sound actually happen.