   faceCanvasContext = null
   faceLoaded = false
 
+  synth = null
+
 
   Meteor.startup ->
     window.AudioContext = window.AudioContext or window.webkitAudioContext
-    audioContext = new AudioContext()
-
-  playSound = (x, y) ->
-    oscillator = audioContext.createOscillator()
-    oscillator.type = oscillator.SINE
-    midiNote = Math.round(y * NUM_KEYBOARD_NOTES)
-    freq =27.5 * Math.pow(2, ((midiNote - 21)/12))
-    oscillator.frequency.value = freq
-    oscillator.connect(audioContext.destination)
-    oscillator.noteOn && oscillator.noteOn(0)
-    window.setTimeout((->
-      oscillator.disconnect()), 50)
-
+    synth = new Synth(new AudioContext())
 
   Template.controller.rendered = ->
     keyboardCanvas = @find '.keyboard'

    @canvasContext = canvas.getContext '2d'

  drawKeys: ->
    freqR = 0.05
    freqG = 0.05
    freqB = 0.05
    phaseR = 4
    phaseG = 5
    phaseB = 0
    width = 128
    center = 127
    yInc = @height / NUM_KEYBOARD_NOTES


IMAGE_SIZE = 64
FACE_SIZE = 128
NUM_KEYBOARD_NOTES = 60
KEYBOARD_START = 60

rgb2Color = (r,g,b) ->
  "rgb(#{r},#{g},#{b})"
