MCPcopy Index your code
hub / github.com/alemangui/pizzicato

github.com/alemangui/pizzicato @0.6.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.6.4 ↗ · + Follow
44 symbols 58 edges 45 files 3 documented · 7%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Pizzicato.js

Build Status npm Bower CDNJS

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.

Table of contents

Get Pizzicato

npm

npm install pizzicato

bower

bower install pizzicato

cdnjs

Full source code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/pizzicato/0.6.4/Pizzicato.js"></script>

Minified:

<script src="https://cdnjs.cloudflare.com/ajax/libs/pizzicato/0.6.4/Pizzicato.min.js"></script>

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

Build without tests with: npm run build or npm run watch

TL;DR: How does it work?

Include Pizzicato in your site

<script src="https://github.com/alemangui/pizzicato/raw/0.6.4/Pizzicato.js"></script>

Create a sound

var sawtoothWave = new Pizzicato.Sound({ 
    source: 'wave',
    options: {
        type: 'sawtooth'
    }
});

Add effects

var delay = new Pizzicato.Effects.Delay();
sawtoothWave.addEffect(delay);

Play it!

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.

var sound = new Pizzicato.Sound(Object description, [Function callback]);

For example:

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:

{
    source: 'wave',
    options: {
        type: 'sine',
        frequency: 440
    }
}

Sounds can be created from a variety of sources.

Sounds from a wave (example)

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.

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.

var sound = new Pizzicato.Sound();

Sounds from a file (example)

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.

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:

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 that can be played with Pizzicato.

Sounds from the user input (example)

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.

var voice = new Pizzicato.Sound({
    source: 'input',
    options: { volume: 0.8 }
});

Sounds from a function (example)

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()): Function that will be called with the audio processing event. * bufferSize (Optional; number - must be a power of 2.): This value controls how many sample frames will be processed at each audio process event. Lower values will result in lower latency, higher values help prevent glitches. * 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.

For example:

var whiteNoise = Pizzicato.Sound({
    source: 'script',
    options: {
        audioFunction: function(e) {
            var output = e.outputBuffer.getChannelData(0);
            for (var i = 0; i < e.outputBuffer.length; i++)
                output[i] = Math.random();
        }
    }
});

Using sounds

Play (example)

You can play a sound by calling it's play function. It takes two optional parameters:

  • when (number, defaults to 0): Time in seconds to wait before playing the sound.
  • offset (number, defaults to 0): Time in seconds where the sound will start.

For example, the following code will wait two seconds, then play a sound starting from position 00:04:

sound.play(2, 4);

Pause

You can pause a sound by calling it's pause function. Next time the sound is played, it will continue from where it left off.

sound.pause();

Stop

You can stop a sound by calling it's stop function. Next time the sound is played, it will continue from the start of the sound.

sound.stop();

Clone

You can clone a sound object by calling it's clone function. The object returned will have the same parameters as the original sound.

sound.clone();

Add effects (example)

You can add effects to a sound object by calling it's addEffect(effect) function. The function gets as parameter a Pizzicato Effect (see effects).

  • effect (type: Pizzicato.Effect): The effect to add to the sound object.

Example:

var sound = new Pizzicato.Sound();
var delay = new Pizzicato.Effects.Delay();
sound.addEffect(delay);

Remove effects

You can remove effects that have been added to a sound object by calling it's removeEffect(effect) function. The function gets as parameter a Pizzicato Effect (see effects) that is already applied to the sound object.

  • effect (type: Pizzicato.Effect): The effect to remove from the sound object.

Example:

var sound = new Pizzicato.Sound();
var delay = new Pizzicato.Effects.Delay();
sound.addEffect(delay);
...
sound.removeEffect(delay);

Volume

Use the sound's volume property to modify its volume.

  • volume (min: 0, max: 1, defaults to 1): The sound's volume

Example:

var sound = new Pizzicato.Sound();
sound.volume = 0.5;

Attack (example)

Use the sound's attack property to modify its attack (or fade-in) value. This value eases the beginning of the sound, often avoiding unwanted clicks.

  • attack (min: 0, max: 10, defaults to 0.04): The sound's attack.

Example:

var sound = new Pizzicato.Sound();
sound.attack = 0.9;

Release (example)

Use the sound's release property to modify its release (or fade-out) value. This value eases the end of the sound, often avoiding unwanted clicks.

  • release _(min: 0,

Core symbols most depended-on inside this repo

Shape

Function 44

Languages

TypeScript100%

Modules by API surface

site/Pizzicato.js12 symbols
distr/Pizzicato.js12 symbols
src/Sound.js8 symbols
distr/Pizzicato.min.js8 symbols
src/Effects/RingModulator.js1 symbols
src/Effects/Reverb.js1 symbols
src/Effects/Quadrafuzz.js1 symbols
src/Effects/Filters.js1 symbols

For agents

$ claude mcp add pizzicato \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page