Update README.md

This commit is contained in:
Yotam Mann 2024-04-30 09:08:29 -04:00
parent f6526c9aaa
commit 3c9ee76d48

View file

@ -1,13 +1,11 @@
Tone.js
=========
# Tone.js
[![codecov](https://codecov.io/gh/Tonejs/Tone.js/branch/dev/graph/badge.svg)](https://codecov.io/gh/Tonejs/Tone.js)
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 creating web-based audio applications. On the high-level, Tone offers common DAW (digital audio workstation) features like a global transport for synchronizing and scheduling events as well as prebuilt synths and effects. Additionally, Tone provides high-performance building blocks to create your own synthesizers, effects, and complex control signals.
* [API](https://tonejs.github.io/docs/)
* [Examples](https://tonejs.github.io/examples/)
- [API](https://tonejs.github.io/docs/)
- [Examples](https://tonejs.github.io/examples/)
# Installation
@ -21,7 +19,7 @@ npm install tone@next // Or, alternatively, use the 'next' version
Add Tone.js to a project using the JavaScript `import` syntax:
```js
import * as Tone from 'tone';
import * as Tone from "tone";
```
Tone.js is also hosted at unpkg.com. It can be added directly within an HTML document, as long as it precedes any project scripts. [See the example here](https://github.com/Tonejs/Tone.js/blob/master/examples/simpleHtml.html) for more details.
@ -50,11 +48,11 @@ synth.triggerAttackRelease("C4", "8n");
```javascript
const synth = new Tone.Synth().toDestination();
const now = Tone.now()
const now = Tone.now();
// trigger the attack immediately
synth.triggerAttack("C4", now)
synth.triggerAttack("C4", now);
// wait one second before triggering the release
synth.triggerRelease(now + 1)
synth.triggerRelease(now + 1);
```
### triggerAttackRelease
@ -69,10 +67,10 @@ The third (optional) argument of `triggerAttackRelease` is _when_ along the Audi
```javascript
const synth = new Tone.Synth().toDestination();
const now = Tone.now()
synth.triggerAttackRelease("C4", "8n", now)
synth.triggerAttackRelease("E4", "8n", now + 0.5)
synth.triggerAttackRelease("G4", "8n", now + 1)
const now = Tone.now();
synth.triggerAttackRelease("C4", "8n", now);
synth.triggerAttackRelease("E4", "8n", now + 0.5);
synth.triggerAttackRelease("G4", "8n", now + 1);
```
## Time
@ -97,10 +95,10 @@ Tone.js abstracts away the AudioContext time. Instead of defining all values in
```javascript
//attach a click listener to a play button
document.querySelector('button')?.addEventListener('click', async () => {
await Tone.start()
console.log('audio is ready')
})
document.querySelector("button")?.addEventListener("click", async () => {
await Tone.start();
console.log("audio is ready");
});
```
# Scheduling
@ -116,17 +114,17 @@ Multiple events and parts can be arranged and synchronized along the Transport.
const synthA = new Tone.FMSynth().toDestination();
const synthB = new Tone.AMSynth().toDestination();
//play a note every quarter-note
const loopA = new Tone.Loop(time => {
const loopA = new Tone.Loop((time) => {
synthA.triggerAttackRelease("C2", "8n", time);
}, "4n").start(0);
//play another note every off quarter-note, by starting it "8n"
const loopB = new Tone.Loop(time => {
const loopB = new Tone.Loop((time) => {
synthB.triggerAttackRelease("C4", "8n", time);
}, "4n").start("8n");
// all loops start when the Transport is started
Tone.getTransport().start()
Tone.getTransport().start();
// ramp up to 800 bpm over 10 seconds
Tone.Transport.bpm.rampTo(800, 10);
Tone.getTransport().bpm.rampTo(800, 10);
```
Since Javascript callbacks are **not precisely timed**, the sample-accurate time of the event is passed into the callback function. **Use this time value to schedule the events**.
@ -141,7 +139,7 @@ To create a **polyphonic** synthesizer, use `Tone.PolySynth`, which accepts a mo
```javascript
const synth = new Tone.PolySynth(Tone.Synth).toDestination();
const now = Tone.now()
const now = Tone.now();
synth.triggerAttack("D4", now);
synth.triggerAttack("F4", now + 0.5);
synth.triggerAttack("A4", now + 1);
@ -155,7 +153,9 @@ synth.triggerRelease(["D4", "F4", "A4", "C5", "E5"], now + 4);
Sound generation is not limited to synthesized sounds. You can also load a sample and play that back in a number of ways. `Tone.Player` is one way to load and play back an audio file.
```javascript
const player = new Tone.Player("https://tonejs.github.io/audio/berklee/gong_1.mp3").toDestination();
const player = new Tone.Player(
"https://tonejs.github.io/audio/berklee/gong_1.mp3"
).toDestination();
Tone.loaded().then(() => {
player.start();
});
@ -172,10 +172,10 @@ Unlike the other synths, Tone.Sampler is polyphonic so doesn't need to be passed
```javascript
const sampler = new Tone.Sampler({
urls: {
"C4": "C4.mp3",
C4: "C4.mp3",
"D#4": "Ds4.mp3",
"F#4": "Fs4.mp3",
"A4": "A4.mp3",
A4: "A4.mp3",
},
release: 1,
baseUrl: "https://tonejs.github.io/audio/salamander/",
@ -183,7 +183,7 @@ const sampler = new Tone.Sampler({
Tone.loaded().then(() => {
sampler.triggerAttackRelease(["Eb4", "G4", "Bb4"], 4);
})
});
```
# Effects
@ -195,7 +195,7 @@ const player = new Tone.Player({
url: "https://tonejs.github.io/audio/berklee/gurgling_theremin_1.mp3",
loop: true,
autostart: true,
})
});
//create a distortion effect
const distortion = new Tone.Distortion(0.4).toDestination();
//connect a player to the distortion
@ -209,7 +209,7 @@ const player = new Tone.Player({
url: "https://tonejs.github.io/audio/drum-samples/loops/ominous.mp3",
autostart: true,
});
const filter = new Tone.Filter(400, 'lowpass').toDestination();
const filter = new Tone.Filter(400, "lowpass").toDestination();
const feedbackDelay = new Tone.FeedbackDelay(0.125, 0.5).toDestination();
// connect the player to the feedback delay and filter in parallel
@ -263,9 +263,9 @@ If you have questions (or answers) that are not necessarily bugs/issues, please
# References and Inspiration
* [Many of Chris Wilson's Repositories](https://github.com/cwilso)
* [Many of Mohayonao's Repositories](https://github.com/mohayonao)
* [The Spec](http://webaudio.github.io/web-audio-api/)
* [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)
* [standardized-audio-context](https://github.com/chrisguttandin/standardized-audio-context)
- [Many of Chris Wilson's Repositories](https://github.com/cwilso)
- [Many of Mohayonao's Repositories](https://github.com/mohayonao)
- [The Spec](http://webaudio.github.io/web-audio-api/)
- [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)
- [standardized-audio-context](https://github.com/chrisguttandin/standardized-audio-context)