• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

tones

The Web Audio API is pretty amazing. You can actually synthesize audio with JavaScript right in the browser. The only problem is that it's pretty low level and not exactly intuitive to work with. This library is meant to make it as simple as humanly possible to create pleasant sounding musical tones.

See a few demos of tones in action here:

http://bit101.github.io/tones/

The tones api is drop dead simple. One main method: play.

The play method can be used in a few different ways:

  1. Play a tone at a specific frequency.
  2. Play a named note in the default 4th octave.
  3. Play a named note in a specific octave.

Examples:

tones.play(440);		// plays a 440 hz tone
tones.play("c");		// plays a C note in the 4th octave.
tones.play("c#");		// plays a C sharp note in the 4th octave.
tones.play("eb");		// plays an E flat note in the 4th octave.
tones.play("c", 2);		// plays a C note in the 2nd octave.

Named notes are case insensitive. "c" is the same as "C".

There are also a few properties that affect the sound of the tone played. Set these before playing a tone and they will affect all future tones played.

type		// this is the wave form, a string of one of the following: "sine", "square", "sawtooth" or "triangle"
attack 		// sets the attack of the envelope, or the time that the sound takes to reach full volume.
release		// sets the release of the envelope, or the time it takes for the sound to fade out.

Attack and release are numbers which should generally be in the range of around 1 to 300. A low release, and mid-range release will give a bell sound. A long attack and release will sound more like a flute. Combined with different wave form types, this allows you to create all kinds of unique sounds.

Note that attack and release values do not represent discrete times. But roughly speaking your sound will last about 10 times the total of these two in milliseconds. For example, an attack of 100 and release of 200 totals 300, so the tone will last around 3000 milliseconds or 3 seconds before completely fading out.

There is also a getTimeMS function. This returns the current time reported by the audio context, which keeps a very accurate internal timer. Some of the examples use this to set up a sort of sequencer.

There's a whole lot more that could be done to this, and I'll probably add features to this, while trying to make sure that the core functionality remains as simple as possible.

It goes without saying that this library will only work in browsers that support the Web Audio API, which includes Chrome, Firefox and Safari (I think), but not Internet Explorer.

More Repositories

1

CodingMath

JavaScript
1,125
star
2

quicksettings

JavaScript library for making a quick settings panel to control code parameters.
JavaScript
449
star
3

gifloopcoder

HTML/JS Library/App for coding looping gif animations.
JavaScript
306
star
4

ProjectMaker

A Sublime Text 2/3 plugin to allow creating any kind of project from your own custom templates
Python
233
star
5

grid

A library for drawing various types of grids on HTML5's Canvas.
JavaScript
173
star
6

shaky

JavaScript Canvas drawing library for drawing shaky lines and shapes.
JavaScript
105
star
7

lab

Daily visual code experiments.
JavaScript
91
star
8

shapes

JavaScript
63
star
9

version

What version do I have of ___?
Shell
45
star
10

clrs

Color lib for HTML/JS. Lots of easy ways to generate colors for use in CSS or Canvas drawing.
JavaScript
34
star
11

wiki_example

30
star
12

minimalcomps2

A Web UI toolkit for creating rapid prototypes, experiments and proof of concept projects.
JavaScript
30
star
13

tutorials

JavaScript (and other?) tutorials
JavaScript
29
star
14

tinpig

A fast, lightweight command line utility to create projects of any kind from templates.
JavaScript
26
star
15

minicomps

JavaScript
25
star
16

bitlibjs

A collection of useful JS utils. Mostly math and graphics related.
JavaScript
21
star
17

STProjectMaker-templates

Sample templates for STProjectMaker
Makefile
20
star
18

perlin_noise_to_angle

JavaScript
15
star
19

bitlib-rs

A drawing, color, geometry and math library geared towards creating graphics and animation with cairo-rs
Rust
15
star
20

blgo

bitlib library for golang
Go
14
star
21

bljs

New version of bitlib js for 2021
JavaScript
14
star
22

sound-synth-music-resources

11
star
23

steggo

Go
9
star
24

bitlib_c

bitlib graphics library ported to c (gtk/cairo).
C
8
star
25

weave

JavaScript
8
star
26

curlnoise_tutorial

JavaScript
7
star
27

truchet

Go
6
star
28

lcg

Fast and simple Pseudo Random Number Generator
JavaScript
6
star
29

embeds2021

JavaScript
5
star
30

dailies

daily code experiments
Go
5
star
31

go-ansi

ANSI escape sequences for Golang
Go
4
star
32

bitface

Garmin Watch Face
Monkey C
4
star
33

bufkill

Better buffer deletion
Vim Script
4
star
34

tinpig-templates

Useful project templates for the tinpig templating utility.
Go
4
star
35

webgl_egghead

Source code for the WebGL video tutorial lessons on Egghead.io
JavaScript
4
star
36

gesso

Gesso prepares a canvas for painting (and animating).
JavaScript
3
star
37

simpledraw_chrome

A Packaged Chrome Application that is a simple drawing application.
JavaScript
2
star
38

adventofcode-go

All my advent of code submissions.
Go
2
star
39

c_iso

Isocmetric drawing library written in C using Cairo Graphics.
C
2
star
40

blcairo

Go
1
star
41

july2018gifs

a gif a day for july, made in golang
Go
1
star
42

7doc

7 days of code
JavaScript
1
star
43

blgrids

Go
1
star
44

rds

Reaction Diffusion simulation
Go
1
star
45

boxbreath

cli app to guide you through a box breathing session
Go
1
star
46

strange_explorer

Explore strange attractor algorithms.
C
1
star
47

bitlib

Go
1
star
48

omdb-graphql

GraphQL interface for the Open Movie Database API
JavaScript
1
star
49

tinpig2

Go
1
star