All Projects β†’ escottalexander β†’ Simpletones.js

escottalexander / Simpletones.js

Licence: mit
The goal of simpleTones.js is to provide every JavaScript developer with a lightweight solution for creating custom sounds in their web applications. This documentation has been written in hopes that the least experienced developer can read, understand and go on to do great things. You can check out several examples at this link:

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Simpletones.js

Gwion
🎡 strongly-timed musical programming language
Stars: ✭ 235 (+422.22%)
Mutual labels:  hacktoberfest, audio, sound
Blueprintsound
A plugin for Unreal Engine 4 that surfaces sound-related functionality to Blueprint.
Stars: ✭ 6 (-86.67%)
Mutual labels:  audio, sound
Sfml
Simple and Fast Multimedia Library
Stars: ✭ 7,316 (+16157.78%)
Mutual labels:  hacktoberfest, audio
Blipkit
C library for creating the beautiful sound of old sound chips
Stars: ✭ 23 (-48.89%)
Mutual labels:  audio, sound
Awesome Android Learning Resources
πŸ‘“ A curated list of awesome android learning resources for android app developers.
Stars: ✭ 753 (+1573.33%)
Mutual labels:  hacktoberfest, beginner-friendly
Oto
β™ͺ A low-level library to play sound on multiple platforms β™ͺ
Stars: ✭ 789 (+1653.33%)
Mutual labels:  audio, sound
Pyo
Python DSP module
Stars: ✭ 904 (+1908.89%)
Mutual labels:  audio, sound
Hacktoberfest 2020
Welcome to Open-source! Simply add your details to contributors | Repo for Hacktoberfest 2020 βœ…
Stars: ✭ 621 (+1280%)
Mutual labels:  hacktoberfest, beginner-friendly
Minimumaudioplugin
Minimum implementation of a native audio plugin for Unity
Stars: ✭ 33 (-26.67%)
Mutual labels:  audio, sound
Hacktoberfest2k19
Hacktoberfest is here! Raise the PR and earn goodies.
Stars: ✭ 34 (-24.44%)
Mutual labels:  hacktoberfest, beginner-friendly
Sound
core sound data structures and interfaces
Stars: ✭ 37 (-17.78%)
Mutual labels:  audio, sound
Modernizr
Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.
Stars: ✭ 25,103 (+55684.44%)
Mutual labels:  hacktoberfest, javascript-library
Roc Toolkit
Real-time audio streaming over the network.
Stars: ✭ 673 (+1395.56%)
Mutual labels:  hacktoberfest, audio
Lasp
Low-latency Audio Signal Processing plugin for Unity
Stars: ✭ 816 (+1713.33%)
Mutual labels:  audio, sound
Plots2
a collaborative knowledge-exchange platform in Rails; we welcome first-time contributors! 🎈
Stars: ✭ 666 (+1380%)
Mutual labels:  hacktoberfest, beginner-friendly
Minimp3
Minimalistic MP3 decoder single header library
Stars: ✭ 898 (+1895.56%)
Mutual labels:  audio, sound
Javascript Mini Projects
Awesome Collection of amazing javascript mini-projects.
Stars: ✭ 42 (-6.67%)
Mutual labels:  hacktoberfest, beginner-friendly
Hello World
Hello World in all possible programmnig languages
Stars: ✭ 558 (+1140%)
Mutual labels:  hacktoberfest, beginner-friendly
Webaudiofont
Use full GM set of musical instruments to play MIDI and single sounds or effects. Support for reverberation and equaliser. No plugins, no Flash. Pure HTML5 implementation compatible with desktop and mobile browser. See live examples.
Stars: ✭ 600 (+1233.33%)
Mutual labels:  audio, sound
Css Art Hacktoberfest Edition
Hacktoberfest Edition - A CSS art challenge, for all skill levels
Stars: ✭ 21 (-53.33%)
Mutual labels:  hacktoberfest, beginner-friendly

simpleTonesLogo

The Premier Library For Easy Browser Based Tones - No Audio Files Required!

The goal of simpleTones.js is to provide every developer with a lightweight solution for creating interactive tones in their web applications. This documentation has been written in hopes that the least experienced developer can read, understand and go on to do great things. This library is based on the Web Audio API and has the same browser limitations. You can check out several examples at SlayApps.com/simpleTones-js.

Table of Contents

  1. Initial Setup
  2. Implementation
  3. Parameters For Sounds
  4. Custom Sounds
  5. Parameters For Tones
  6. Limitations
  7. Contributing

Setup is simple

Just add the simpleTones.js file to your file directory

FileStructure

and include the simpleTones.js file in your header file sources.

<head>
<script src="src/simpleTones.js"></script>
</head>

That's it!!!

Now you are ready to make some noise!

Basic Implementation

You have two options, sounds and tones. Sounds are either predefined noises or you can create a custom sound with any length and variation in frequency. Tones are all predefined (all the keys of a piano).

Super simple implementation - To get started, just use playTone() or playSound("sound name") anywhere in your code where you want it to trigger a sound.

For example:

<button onclick="playTone()">Click me!</button>

<button onclick="playSound("buzzer")">Click me!</button>

or

if (x === true) {
playTone();
}

The Parameters For Sounds

You can use a sound that is shipped with the library

playSound("sound")

Currently, the library is shipped with only a handful of predefined sounds. The names of these sounds can be seen in the soundObj object at the very top of the simpleTones JavaScript file.

//Sound Storage 
var soundObj = {
	bump:["triangle",100,0.8,333,0.2,100,0.4,80,0.7],
	buzzer:["sawtooth",40,0.8, 100,0.3 ,110, 0.5],
	zip:["sawtooth",75,0.8,85,0.2,95,0.4,110,0.6,120,0.7,100,0.8],
	powerdown:["sine", 300, 1.2, 150, 0.5,1,0.9],
	powerup:["sine", 30, 1, 150, 0.4,350,0.9],
	bounce:["square", 75, 0.5, 150, 0.4],
	siren:["sawtooth",900,2.5, 400,0.5 ,900, 1, 400,1.4, 900, 2, 400, 2.5]
}

Creating Custom Sounds

You can make any sound you can imagine

playSound(waveType, initialFrequency, fullLength, frequencyChange1, timingOfFrequencyChange1...)

waveType

There are four wave types to choose from:

  • Sine
  • Square
  • Triangle
  • Sawtooth

These wave types are based on the sound wave pattern and are somewhat explained by this chart:

Chart

initialFrequency

This is the frequency with which your sound will start. The number should be in Hertz. For reference, on the piano an A played on the fourth scale is 440hz.

fullLength

fullLength is the entire duration of your sound in seconds. Be very careful that you make it long enough to sustain until all the following freqency changes are carried through. For instance, if fullLength is set to 2 seconds and your next set of frequency change instructions are set to go off at 2.5 seconds, you will never hear the second set of frequency instructions.

frequencyChange1 or 2, 3, 4 etc.

and

timingOfFrequencyChange1 or 2, 3, 4 etc.

This is where you will give the sound its instructions to change frequency (frequencyChange1) and what time to do it (timingOfFrequencyChange1). You can chain together an unlimited quantity of these instructions to achieve the desired sound.

Here is an example

This is a sound that has the "sine" wave type and will start playing at 440Hz, it's set to end at 2.5 seconds but at 0.8 seconds the frequency will change to 220Hz.

playSound("sine", 440, 2.5, 220, 0.8);

We can easily add another frequency change at another time interval by adding the following:

playSound("sine", 440, 2.5, 220, 0.8, 440, 1.4);

Now after playing the original instructions it will go back to 440Hz at the 1.4 second interval.

Adding your custom sounds to soundObj for easy reference

At the very top of the simpleTones JavaScript file there is an object called soundObj.

//Sound Storage 
var soundObj = {
	bump:["triangle",100,0.8,333,0.2,100,0.4,80,0.7],
	buzzer:["sawtooth",40,0.8, 100,0.3 ,110, 0.5],
	zip:["sawtooth",75,0.8,85,0.2,95,0.4,110,0.6,120,0.7,100,0.8],
	powerdown:["sine", 300, 1.2, 150, 0.5,1,0.9],
	powerup:["sine", 30, 1, 150, 0.4,350,0.9],
	bounce:["square", 75, 0.5, 150, 0.4],
	siren:["sawtooth",900,2.5, 400,0.5 ,900, 1, 400,1.4, 900, 2, 400, 2.5]
}

You can place your sound instructions here and give them a name so that you can easily reference them in your project. Please consider giving this project a pull request if you make some awesome sounds you want to share.

The Parameters For Tones

playTone(tone or chord or frequency, waveType, duration)

You can select any tone that is on the piano, for reals

Tones are stored in an object and can be accessed with

playTone(tone["C1"])

Or, luckily, simpleTones.js is smart enough to know what you mean if you just use "C1" as the parameter.

For example:

playTone("C1")

Now "C1" means, "play a C on the first scale". To play a Eb on the eighth scale you would use "Eb8". Or A# on the third scale would be "A#3". It's that simple. Numbers range from 0 to 8. The higher the scale, the higher the pitch. Every tone has a #(sharp) except E and B which have b(flat).

Now if I haven't lost you yet in the musical jargon, lets look at another way to make sounds.

Chord

For a fuller sound, chords are a sure pick!

Chords are stored in an object and can be accessed with

playTone(chord["C"])

Or you just use "C" as the parameter.

For example:

playTone("C")

The way chords work is that they play three tones that together equal "C". Currently all chords available are based on tones in the fourth scale. Chords from other scales coming in a later release. You can play major chords like "G", "E" and "A", sharp chords such as "C#", "D# and "G# or even minor chords like "Em", "Cm" and "Am"!

Frequency

For a tone that isn't predefined you can specify the Hz

To use a frequency, just type the quantity of Hz as a number:

playTone(440)

For reference, 440 Hz is the equivalent of playing "A4"

waveType

There are four wave types to choose from:

  • Sine
  • Square
  • Triangle
  • Sawtooth

These wave types are based on the sound wave pattern and are somewhat explained by this chart:

Chart

When these are used as parameters they should look like this:

playTone("Cm", "sine");
playTone("Eb4", "square");
playTone("A#6", "triangle");
playTone("E", "sawtooth");

Play around with them and see which one you like best for your project.

When you don't specify which one to use it will default to "sine".

Duration

How long the tone will play

The default duration is 1.3 seconds. You can change it to any other number.

BuzzerHit() {
//Annoyingly long tone
playTone("A#2", "sawtooth", 5.4)
}

Limitations

The simpleTones.js library has been built on top of the WebAudioAPI which currently has issues with older browsers. Keep this in mind as you use the library.

Helpful Resources For Contributing

There are lots of ways that simpleTones.js could be improved and optimized. If you have an idea or would like to learn and apply the Web Audio API to more of the codebase, we would love to come along side you and help you leave your mark on this project.

Please keep in mind that we want this project to stay as simple as possible so that new developers can easily learn and utilize browser based sounds without having to fully understand the Web Audio API.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].