Tone.js/README.md

115 lines
6.3 KiB
Markdown
Raw Normal View History

2014-03-19 21:26:22 +00:00
Tone.js
2014-03-15 02:56:44 +00:00
=========
Tone.js is a Web Audio framework for creating interactive music in the browser. The architecture of Tone.js aims to be familiar to both musicians and audio programmers looking to create web-based audio applications. On the high-level, Tone offers common DAW (digital audio workstation) features like a global transport for scheduling and timing events and prebuilt synths and effects. For signal-processing programmers (coming from languages like Max/MSP), Tone provides a wealth of high performance, low latency building blocks and DSP modules to build your own synthesizers, effects, and complex control signals.
2014-09-09 04:40:33 +00:00
[API](http://tonejs.org/docs/)
2014-09-09 04:40:33 +00:00
[Examples](http://tonejs.org/examples/)
2015-02-26 17:25:27 +00:00
# Demos
2015-06-07 16:11:38 +00:00
* [Jazz.Computer - Yotam Mann](http://jazz.computer/)
2015-08-24 15:16:53 +00:00
* [motionEmotion - Karen Peng, Jason Sigal](http://motionemotion.herokuapp.com/)
2015-06-07 16:11:38 +00:00
* [p5.sound - build with Tone.js](https://github.com/processing/p5.js-sound)
2015-02-26 17:25:27 +00:00
* [Hypercube by @eddietree](http://eddietree.github.io/hypercube/)
* [randomcommander.io by Jake Albaugh](http://randomcommander.io/)
* [Tone.js + NexusUI by taylorbf](http://taylorbf.github.io/Tone-Rack/)
2015-03-09 14:47:51 +00:00
* [Solarbeat - Luke Twyman](http://www.whitevinyldesign.com/solarbeat/)
2015-08-24 15:16:53 +00:00
* [Wind - João Costa](http://wind.joaocosta.co)
* [Block Chords - Abe Rubenstein](http://dev.abe.sh/block-chords/)
2015-08-15 21:26:32 +00:00
* [This is Not a Machine Learning - David Karam](http://posttool.github.io/)
2015-08-24 15:16:53 +00:00
* [Airjam - Seth Kranzler, Abe Rubenstein, and Teresa Lamb](http://airjam.band/)
* [Calculaural - Matthew Hasbach](https://github.com/mjhasbach/calculaural)
* [Scratch + Tone.js - Eric Rosenbaum](http://ericrosenbaum.github.io/tone-synth-extension/)
2015-09-30 17:29:30 +00:00
* [Game of Reich - Ben Taylor](http://nexusosc.com/gameofreich/)
2015-02-26 17:25:27 +00:00
Using Tone.js? I'd love to hear it: yotammann@gmail.com
2014-04-16 16:17:17 +00:00
# Installation
2015-02-01 18:45:02 +00:00
Tone can be installed in a few of ways:
2015-07-24 13:43:44 +00:00
* Download Tone.js from Github - [full](https://raw.githubusercontent.com/Tonejs/Tone.js/master/build/Tone.js) | [min](https://raw.githubusercontent.com/Tonejs/Tone.js/master/build/Tone.min.js)
2015-02-01 18:45:02 +00:00
* [bower](http://bower.io/) - `bower install tone`
* [npm](https://www.npmjs.org/) - `npm install tone`
2014-04-06 21:05:58 +00:00
2015-08-15 21:26:32 +00:00
The fastest way to include Tone.js on your page is to use the CDN (hosted by [github pages](https://pages.github.com/)).
2015-01-06 02:56:11 +00:00
```html
<script type="text/javascript" src="http://cdn.tonejs.org/latest/Tone.min.js"></script>
```
2015-02-26 17:25:27 +00:00
It's always much safer to use a specific version rather than just "latest".
2015-07-24 13:43:44 +00:00
[Full Installation Instruction](https://github.com/Tonejs/Tone.js/wiki/Installation)
2014-09-11 18:12:25 +00:00
2014-12-04 03:30:46 +00:00
# Hello World
2014-09-11 18:12:25 +00:00
2014-12-04 03:30:46 +00:00
```javascript
2015-06-26 05:22:16 +00:00
//create one of Tone's built-in synthesizers and connect it to the master output
var synth = new Tone.SimpleSynth().toMaster();
2014-04-06 21:05:58 +00:00
2015-06-26 05:22:16 +00:00
//play a middle c for the duratino of an 8th note
synth.triggerAttackRelease("C4", "8n");
2014-04-06 21:05:58 +00:00
```
2014-04-16 16:17:17 +00:00
2014-09-04 18:04:02 +00:00
# Tone.Transport
2015-09-30 17:29:30 +00:00
A unique feature of the library is the Transport which allows for application-wide synchronization of sources and signals with tempo curves and automation. The Transport allows you to register callbacks at precise moments along the timeline which are invoked right before the event with the exact time of the event.
2014-09-04 18:04:02 +00:00
2015-07-24 13:43:44 +00:00
[Read more](https://github.com/Tonejs/Tone.js/wiki/Transport).
2014-09-04 18:04:02 +00:00
2014-06-23 17:28:55 +00:00
### Time
2014-04-16 16:53:51 +00:00
2014-12-04 03:30:46 +00:00
In the Tone library, time can be described in a number of ways. Any method which takes a time as a parameter will accept the number in seconds as well as a tempo-relative form.
2014-04-16 16:53:51 +00:00
For example to `"4n"` is a quarter-note and "4:2:0" is the third beat of the fifth measure (remember we're counting from 0).
2015-09-30 17:29:30 +00:00
[Read more](https://github.com/Tonejs/Tone.js/wiki/Time).
2014-04-16 16:53:51 +00:00
2015-02-26 17:26:37 +00:00
# Sources
2014-04-16 16:53:51 +00:00
2015-02-26 17:25:27 +00:00
Aside from the 4 basic oscillator types (sine, square, triangle, sawtooth), Tone.js provides a few other sources such as a buffer player (Tone.Player), a noise generator, and two additional oscillator types (pwm, pulse).
2014-04-16 16:53:51 +00:00
2015-07-24 13:43:44 +00:00
[Read more](https://github.com/Tonejs/Tone.js/wiki/Sources).
2014-04-16 16:53:51 +00:00
2015-02-26 17:26:37 +00:00
# Instruments
2014-04-16 16:53:51 +00:00
2015-09-30 17:29:30 +00:00
Tone has a number of instruments which all inherit from Tone.Instrument, giving them the same API for triggering notes. These instruments are all monophonic and can be made polyphonic if they are passed into the second argument of [Tone.PolySynth](http://tonejs.org/docs/#PolySynth).
[Read more](https://github.com/Tonejs/Tone.js/wiki/Instruments).
2014-09-04 18:04:02 +00:00
2015-02-26 17:26:37 +00:00
# Effects
2014-04-16 16:53:51 +00:00
2015-09-30 17:29:30 +00:00
Tone.js also has many stereo and mono effects. Each effect lets you change the ratio between the dry (unaffected) and wet signal.
[Read more](https://github.com/Tonejs/Tone.js/wiki/Effects).
2014-04-16 17:13:42 +00:00
2015-02-26 17:26:37 +00:00
# Signals
2014-04-16 17:13:42 +00:00
2015-02-26 17:25:27 +00:00
Like the underlying Web Audio API, Tone.js is built with audio-rate signal control over nearly everything. This is a powerful feature which allows for sample-accurate synchronization of multiple parameters with a single signal. Signals are built entirely without the ScriptProcessorNode so they do not introduce much latency and processing overhead. Instead, all signal math and logic let GainNodes and WaveShaperNodes do all of the work so that all processing is done in the underlying Assembly/C/C++ provided by the API. Signals are used extensively internally and are also useful for general DSP and control signal logic and transformations.
2014-04-16 17:13:42 +00:00
2015-07-24 13:43:44 +00:00
Read more about [signals](https://github.com/Tonejs/Tone.js/wiki/Signals).
2014-04-16 17:13:42 +00:00
2015-02-26 17:25:27 +00:00
# AudioContext
2014-09-04 18:04:02 +00:00
2015-02-26 17:25:27 +00:00
Tone.js creates an AudioContext when it loads and shims it for maximum browser compatibility. The AudioContext can be found at `Tone.context` or from within any Object extending Tone as `this.context`.
2014-09-04 18:04:02 +00:00
2015-02-26 17:25:27 +00:00
Tone also let's you set your own AudioContext using `Tone.setContext`.
2014-09-04 18:04:02 +00:00
2015-09-30 17:29:30 +00:00
# MIDI
To use MIDI files, you'll first need to convert them into a JSON format which Tone.js can understand using [MidiConvert](tonejs.github.io/MidiConvert/).
2014-07-04 03:00:51 +00:00
# Performance
2015-04-05 14:19:44 +00:00
Tone.js uses very few ScriptProcessorNodes. Nearly all of the Tone Modules find a native Web Audio component workaround, making extensive use of the GainNode and WaveShaperNode especially, which enables Tone.js to work well on both desktop and mobile browsers. While the ScriptProcessorNode is extremely powerful, it introduces a lot of latency and the potential for glitches more than any other node.
2014-04-16 16:53:51 +00:00
2014-09-04 18:04:02 +00:00
# References and Inspiration
2014-09-05 05:38:11 +00:00
* [Tuna.js](https://github.com/Dinahmoe/tuna)
2014-09-04 18:04:02 +00:00
* [Many of Chris Wilson's Repositories](https://github.com/cwilso)
2014-09-05 05:38:11 +00:00
* [The Spec](http://webaudio.github.io/web-audio-api/)
2015-08-15 21:26:32 +00:00
* [Sound on Sound - Synth Secrets](http://www.soundonsound.com/sos/may99/articles/synthsec.htm)
* [Miller Puckette - Theory and Techniques of Electronic Music](http://msp.ucsd.edu/techniques.htm)