Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Write a song in JavaScript

Write a song in JavaScript

Write a song in JavaScript and play it with Audio API. Now you will can share your song as a package.json

Daijiro Wachi

January 14, 2016
Tweet

More Decks by Daijiro Wachi

Other Decks in Technology

Transcript

  1. $ whoami Daijiro Wachi / @watilde Relocated here ! from

    Japan " Lead JS Developer @BoosterMedia Kapsalon
  2. { “name”: “Super Mario Bros”, “description”: “Main Theme Song”, “author”:

    “Koji Kondo”, “main”: “Main-Song-Data” } 1 2 3 4 5 6 Music Score is……
  3. func([E5, F#5, D5], 1 / 8, 200); // => Convert

    to Audio and Play it! 1 2 Notes Phonetic
 value Tempo in JavaScript
  4. var data = buf.getChannelData(0); for(var i = 0; i <

    length; i++) { data[i] = Math.sin( (2 * Math.PI) * nn * (i / sampleRate) ); } => Sine wave
  5. beeplay({bpm: 50, volume: 0.5}) .play(["E5", "F#4", "D4"], 1/8) .play(["E5", "F#4",

    "D4"], 1/8) .play(null, 1/8) .play(["E5", "F#4", "D4"], 1/8) .play(null, 1/8) .play(["C5", "F#4", "D4"], 1/8) .play(["E5", "F#4", "D4"], 1/8) .play(null, 1/8) .play(["G5", "B4", "G4"], 1/8) .play(null, 3/8) .play(["G4", "G3"], 1/3, "p"); 1 2 3 4 5 6 7 8 9 10 11 12
  6. beeplay({bpm: 50, volume: 0.5}) .play(["E5", "F#4", "D4"], 1/8) .play(["E5", "F#4",

    "D4"], 1/8) .play(null, 1/8) .play(["E5", "F#4", "D4"], 1/8); 1 2 3 4 5 Song == JavaScript
  7. Remember the score data is…… { “name”: “Super Mario Bros”,

    “description”: “Main Theme Song”, “author”: “Koji Kondo”, “main”: “Main-Song-Data” } 1 2 3 4 5 6
  8. { “name”: “Super Mario Bros”, “description”: “Main Theme Song”, “author”:

    “Koji Kondo”, “main”: “Main-Song-Data.js” } 1 2 3 4 5 6 We are JSer
  9. $ npm install awesome-song beeplay $ emacs index.js var beeplay

    = require("beeplay"); var song = require("awesome-song"); beeplay({song: song}); $ node index.js => play music
  10. 3 plans 1.Support Node.js w/ the sox 2.Support Johnny-five syntax

    3.Generate a scaffolding from package.json