Tone.js/README.md

119 lines
5.9 KiB
Markdown
Raw Normal View History

2014-03-19 21:26:22 +00:00
Tone.js
2014-03-15 02:56:44 +00:00
=========
2014-09-11 18:12:25 +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, prebuilt synths and effects, as well as presets for those 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
2015-05-13 04:04:42 +00:00
[Examples](http://tonejs.org/examples/)
2014-09-09 04:40:33 +00:00
2015-02-26 17:25:27 +00:00
[API](http://tonejs.org/docs/Tone.html)
# Demos
2015-06-07 16:11:38 +00:00
* [Jazz.Computer - Yotam Mann](http://jazz.computer/)
2015-02-26 17:25:27 +00:00
* [motionEmotion - emotion & gesture-based arpeggiator and synthesizer](http://motionemotion.herokuapp.com/)
* [A Tone.js Plugin Architecture with GUIs](https://github.com/billautomata/Tone.js.Plugins)
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-06-07 16:11:38 +00:00
* [João Costa - Wind](http://wind.joaocosta.co)
* [Abe Rubenstein - Block Chords](http://dev.abe.sh/block-chords/)
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:
* Download Tone.js from Github - [full](https://raw.githubusercontent.com/TONEnoTONE/Tone.js/master/build/Tone.js) | [min](https://raw.githubusercontent.com/TONEnoTONE/Tone.js/master/build/Tone.min.js)
* [bower](http://bower.io/) - `bower install tone`
* [npm](https://www.npmjs.org/) - `npm install tone`
2014-04-06 21:05:58 +00:00
2015-01-06 02:56:11 +00:00
The fastest way to include Tone.js on your page is to use the CDN (not for production use, please):
```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-02-26 17:28:57 +00:00
[Full Installation Instruction](https://github.com/TONEnoTONE/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
//create one of Tone's built-in synthesizers
var synth = new Tone.MonoSynth();
2014-04-06 21:05:58 +00:00
2014-12-04 03:30:46 +00:00
//connect the synth to the master output channel
synth.toMaster();
2014-04-06 21:05:58 +00:00
2014-12-04 03:30:46 +00:00
//create a callback which is invoked every quarter note
Tone.Transport.setInterval(function(time){
//trigger middle C for the duration of an 8th note
synth.triggerAttackRelease("C4", "8n", time);
}, "4n");
2014-09-11 18:12:25 +00:00
2014-12-04 03:30:46 +00:00
//start the transport
Tone.Transport.start();
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
A unique feature of the library is the oscillator-based Transport which allows for application-wide synchronization of sources and signals. 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. Additionally, because the Transport is implemented with an oscillator, it is capable of elaborate tempo curves and automation.
2015-02-26 17:28:57 +00:00
[Read more](https://github.com/TONEnoTONE/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
2015-02-26 17:28:57 +00:00
[Read more about Tone.Time](https://github.com/TONEnoTONE/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-02-26 17:28:57 +00:00
[Read more](https://github.com/TONEnoTONE/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-02-26 17:25:27 +00:00
Tone has a few prebuilt synthesizers.
2014-04-16 16:53:51 +00:00
2015-02-26 17:28:57 +00:00
[Read more about how to use them](https://github.com/TONEnoTONE/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-02-26 17:25:27 +00:00
Tone.js also has a few stereo and mono effects some of which also have their own presets.
2014-04-16 16:53:51 +00:00
2015-02-26 17:28:57 +00:00
[Read more](https://github.com/TONEnoTONE/Tone.js/wiki/Effects).
2014-04-16 16:53:51 +00:00
2015-02-26 17:26:37 +00:00
# Components
2014-04-16 16:53:51 +00:00
2015-02-26 17:25:27 +00:00
Tone.js provides a number number of useful components for building synthesizers and effects.
2014-04-16 17:13:42 +00:00
2015-02-26 17:28:57 +00:00
[Read more](https://github.com/TONEnoTONE/Tone.js/wiki/Components).
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-02-26 17:28:57 +00:00
Read more about [signals](https://github.com/TONEnoTONE/Tone.js/wiki/Signals) and [signal operators](https://github.com/TONEnoTONE/Tone.js/wiki/Signal Math).
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
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/)