Skip to content
/ 8bit.js Public
forked from meenie/8bit.js

8Bit.js Audio Library - Write music using 8bit oscillation sounds.

License

Notifications You must be signed in to change notification settings

num87/8bit.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

8Bit.js Audio Library

Write music using 8bit oscillation sounds. Supports rhythms, multiple instruments, repeating sections, and complex time signatures.

Get Started

  1. Include 8bit.min.js in the head of your document.

  2. Create an new instance: var music = new EightBit();

  3. Give it a Time Signature: music.setTimeSignature(4,4);

  4. Set the tempo: music.setTempo(120);

  5. Create an instrument: var piano = music.createInstrument();

  6. Start adding notes:

    piano.note('C4', 'quarter');
    piano.note('D4', 'quarter');
    piano.note('E4', 'quarter');
    piano.note('F4', 'quarter');
  7. Mark the piano instrument as finished: piano.finish();

  8. Tell the music everything is done: music.end();

  9. Start playing the music: music.play()

Examples

API

EightBit Class
Method Params Description
setTimeSignature(top, bottom) top: 4
bottom: 4
This will set the Time Signature for the music. Any number of top numbers (how many beats per bar) can be set, but the bottom number (which note gets the beat) can only be 2, 4, or 8.
setTempo(tempo) tempo: 120 Set the tempo (BPM) of the music
setMasterVolume(volume) volume: 100 Set the master volume of the music. From 0 to 100
pause() n/a Pause the music.
stop(fadeOut) fadeOut: true Stop the music with a slight fade out. If you don't want the fade, pass in false.
play() n/a Play the music.
end() n/a Collects all of the notes of each finished instrument and creates the oscillators in preperation to play.
mute(callback) n/a Mutes the music. You can pass in a function as a callback when the music completely faded.
unmute(callback) n/a Unmute the music. You can pass in a function as a callback when the music is completely faded up.
onFinished(callback) n/a Pass in a function that will be called when the music has completed
loop(loop) loop: false Pass in true if you want the music to keep looping forever.
createInstrument(waveForm) waveForm: sine Creates an instrument that you can add notes/rests with. The possible instrument types are: sine, square, sawtooth, and triangle
load(json) json: JSON Load a song into 8bit.js using JSON. Format is:
{
    timeSignature: [4, 4],
    tempo: 100,
    instruments: {
        rightHand: 'square',
        leftHand: 'sawtooth'
    },
    notes: {
        // Shorthand notation
        rightHand: [
            'E5, F#4|quarter|tie',
            'rest|quarter',
            'E5, F#4|quarter',
            'rest|quarter'
        ],
        // More verbose notation
        leftHand: [
            {
                type: 'note',
                pitch: 'D3',
                rhythm: 'quarter'
            }
        ]
    }
}
Instrument Class - Created by using the EightBit:createInstrument() method.
Method Params Description
note(pitch, note, tie) pitch Must be set
note Must be set
tie: false
Adds a note to the stack of notes for the particular instrument.
pitch can be any note between C0 and C8 (e.x. Bb3 or G#7)
note can be any from the list below
  • whole
  • dottedHalf
  • half
  • dottedQuarter
  • tripletHalf
  • quarter
  • dottedEighth
  • tripletQuarter
  • eighth
  • dottedSixteenth
  • tripletEighth
  • sixteenth
  • tripletSixteenth
  • thirtySecond
tie can tie two notes together without any gap. By default the library puts in an articulation gap of about a tenth of the length of the note.
rest(note) note Must be set Adds a rest to the list of notes. Use the note list above for the type of rest you can use.
setVolume(volume) volume: 25 Sets the volume for this particular instrument. From 0 to 100. You can call this multiple times before notes to change their volume at that point of the music.
repeatStart() n/a Puts in a marker where a section of music should be repeated from.
repeat(times) times: 1 Used in conjunction with repeatStart(). Pass in how many times the section should be repeated. If no repeatStart() is set, it goes from the beginning.
finish() n/a This will mark the instrument as complete and add it's notes to the master list. If this is missing, the instrument will not be played.

Copyright and License

Copyright 2013 Cody Lundquist under the MIT License (MIT).

About

8Bit.js Audio Library - Write music using 8bit oscillation sounds.

Resources

License

Stars

Watchers

Forks

Packages

No packages published