> [!NOTE]
> Due to lack of time to focus on this project, **I'm actively looking for maintainers** who might be interested in working on Pizzicato. Don't hesitate to contact me! In the meantime, consider the project deprecated.
[](https://travis-ci.org/alemangui/pizzicato) [](https://www.npmjs.com/package/pizzicato) [](https://bower.io/) [](https://cdnjs.com/libraries/pizzicato)
## A Web Audio library
Pizzicato aims to simplify the way you create and manipulate sounds via the Web Audio API. Take a look at the [demo site here](https://alemangui.github.io/pizzicato/).
## Table of contents
- [Get Pizzicato](#get-pizzicato)
- [npm](#npm)
- [bower](#bower)
- [cdnjs](#cdnjs)
- [Installing and testing](#installing-and-testing)
- [TL;DR: How does it work?](#tldr)
- [Create a sound](#create-a-sound)
- [Sounds from a wave](#sounds-from-a-wave)
- [Sounds from a file](#sounds-from-a-file)
- [Sounds from input](#sounds-from-input)
- [Sounds from a function](#sounds-from-a-function)
- [Using sounds](#using-sounds)
- [play()](#sounds-play)
- [pause()](#sounds-pause)
- [stop()](#sounds-stop)
- [clone()](#sounds-clone)
- [addEffect()](#sounds-add-effect)
- [removeEffect()](#sounds-remove-effect)
- [volume](#sounds-volume)
- [attack](#sounds-attack)
- [release](#sounds-release)
- [frequency](#sounds-frequency)
- [Events](#sounds-events)
- [play](#sounds-events-play)
- [pause](#sounds-events-pause)
- [stop](#sounds-events-stop)
- [end](#sounds-events-end)
- [Connecting sounds to AudioNodes](#sounds-connect)
- [Grouping sounds](#groups)
- [Create a group](#create-a-group)
- [addSound()](#group-add-sound)
- [removeSound()](#group-remove-sound)
- [addEffect()](#group-add-effect)
- [removeEffect()](#group-remove-effect)
- [play()](#group-play)
- [pause()](#group-pause)
- [stop()](#group-stop)
- [volume](#group-volume)
- [Effects](#effects)
- [Delay](#delay)
- [Ping Pong Delay](#pingpongdelay)
- [Dub Delay](#dubdelay)
- [Distortion](#distortion)
- [Quadrafuzz](#quadrafuzz)
- [Flanger](#flanger)
- [Compressor](#compressor)
- [Low-pass filter](#low-pass-filter)
- [High-pass filter](#high-pass-filter)
- [Stereo Panner](#stereo-panner)
- [Convolver](#convolver)
- [Reverb](#reverb)
- [Ring Modulator](#ring-modulator)
- [Tremolo](#tremolo)
- [Connecting effects to and from AudioNodes](#effects-connect)
- [Advanced](#advanced)
- [Accessing the audio context](#accessing-the-context)
- [Using Pizzicato objects in a web audio graph](#using-graph)
- [General volume](#general-volume)
- [Memory management](#memory-management)
- [Support](#support)
- [Browsers](#browsers)
- [Audio formats](#audio-formats)
## Get Pizzicato
### npm
```
npm install pizzicato
```
### bower
```
bower install pizzicato
```
### cdnjs
Full source code:
```html
```
Minified:
```html
```
### Installing and testing
*Ensure you have gulp installed:* ```npm install -g gulp```.
Checkout the project and install dependencies with :
```
npm install
```
Run tests with:
```
npm run test
```
By default, Firefox is used for local testing. If you'd like to use Chrome you can use the setting active in TravisCI. To do so, go to ```karma.conf.js```, line 5, and change the browsers array to :
```
browsers: ['Chrome_travis_ci'],
```
Build without tests with:
```npm run build``` or ```npm run watch```
## TL;DR: How does it work?
Include Pizzicato in your site
```html
```
Create a sound
```javascript
var sawtoothWave = new Pizzicato.Sound({
source: 'wave',
options: {
type: 'sawtooth'
}
});
```
Add effects
```javascript
var delay = new Pizzicato.Effects.Delay();
sawtoothWave.addEffect(delay);
```
Play it!
```javascript
sawtoothWave.play();
```
## Create a sound
To create a new sound, use the ```Pizzicato.Sound``` constructor, which takes an object with the sound's ```description``` as argument and a callback that will be executed when the sound is ready to be used. If an error occurs, the callback will be called with the error as a parameter.
```javascript
var sound = new Pizzicato.Sound(Object description, [Function callback]);
```
For example:
```javascript
var click = new Pizzicato.Sound({ source: 'wave' }, function(error) {
if (!error)
console.log('Sound ready to use!');
});
```
Typically, the ```description``` object contains a string ```source``` and an object ```options```. The ```options``` object varies depending on the source of the sound being created.
For example, this objects describes a sine waveform with a frequency of 440:
```javascript
{
source: 'wave',
options: {
type: 'sine',
frequency: 440
}
}
```
Sounds can be created from a variety of sources.
### Sounds from a wave ([example](https://alemangui.github.io/pizzicato/#sound-from-waveform))
To create a sound from an oscillator with a certain waveform, use the ```source: wave``` in your description. Additionally, the following optional parameters are possible inside the ```options``` object:
* ```type``` _(Optional; ```sine```, ```square```, ```triangle``` or ```sawtooth```, defaults to ```sine```)_: Specifies the type of waveform.
* ```frequency``` _(Optional; defaults to 440)_: Indicates the frequency of the wave (i.e., a 440 value will yield an A note).
* ```volume``` _(Optional; min: 0, max: 1, defaults to 1)_: Loudness of the sound.
* ```release``` _(Optional; defaults to 0.4)_: Value in seconds that indicates the fade-out time when the sound is stopped.
* ```attack``` _(Optional; defaults to 0.4)_: Value in seconds that indicates the fade-in time when the sound is played.
* ```detached``` _(Optional; defaults to false)_: If true, the sound will not be connected to the context's destination, and thus, will not be audible.
```javascript
var sound = new Pizzicato.Sound({
source: 'wave',
options: { type: 'sawtooth', frequency: 440 }
});
```
Creating a Pizzicato Sound with an empty constructor will create a sound with a sine wave and a frequency of 440.
```javascript
var sound = new Pizzicato.Sound();
```
### Sounds from a file ([example](https://alemangui.github.io/pizzicato/#sound-from-file))
In order to load a sound from a file, include the ```source: file``` in your description. Additionally, the following parameters are possible inside the ```options``` object:
* ```path``` _(Mandatory; string or array of strings)_: Specifies the path of the sound file. It is also possible to have an array of paths to fallback on. Pizzicato will attempt to load the paths in order, passing on to the next one in case of failure.
* ```loop``` _(Optional; boolean, defaults to false)_: If set, the file will start playing again after the end.
* ```volume``` _(Optional; min: 0, max: 1, defaults to 1)_: Loudness of the sound.
* ```release``` _(Optional; defaults to 0)_: Value in seconds that indicates the fade-out time once the sound is stopped.
* ```attack``` _(Optional; defaults to 0.4)_: Value in seconds that indicates the fade-in time when the sound is played.
* ```detached``` _(Optional; defaults to false)_: If true, the sound will not be connected to the context's destination, and thus, will not be audible.
```javascript
var sound = new Pizzicato.Sound({
source: 'file',
options: { path: './audio/sound.wav' }
}, function() {
console.log('sound file loaded!');
});
```
It is possible to pass several paths to fallback in case of error:
```javascript
var sound = new Pizzicato.Sound({
source: 'file',
options: { path: ['./audio/sound-special-format.wav', './audio/sound.wav'] }
}, function() {
console.log('sound file loaded!');
});
```
Alternatively, you can also simply pass a string to the constructor with the path of the sound file.
```
var sound = new Pizzicato.Sound('./audio/sound.wav', function() {...});
```
Check the [supported audio files](#audio-formats) that can be played with Pizzicato.
### Sounds from the user input ([example](https://alemangui.github.io/pizzicato/#sound-from-input))
It is also possible to use the sound input from the computer. This is usually the microphone, but it could also be a line-in input. To use this, add ```source: input``` in your description. The following optional parameters are possible inside ```options``` object:
* ```volume``` _(Optional; min: 0, max: 1, defaults to 1)_: Loudness of the sound.
* ```release``` _(Optional; defaults to 0)_: Value in seconds that indicates the fade-out time once the sound is stopped.
* ```attack``` _(Optional; defaults to 0.4)_: Value in seconds that indicates the fade-in time when the sound is played.
* ```detached``` _(Optional; defaults to false)_: If true, the sound will not be connected to the context's destination, and thus, will not be audible.
```javascript
var voice = new Pizzicato.Sound({
source: 'input',
options: { volume: 0.8 }
});
```
### Sounds from a function ([example](https://alemangui.github.io/pizzicato/#sound-from-function))
For more creative freedom, Pizzicato also allows direct audio processing. Sounds can be created from a Javascript function by including ```source: script``` in the description. The following parameters are possible in the ```options``` object:
* ```audioFunction``` _(Mandatory; function(