Example #1
0
  return function (note, time, duration, options) {
    var f = freq(midi(note))
    if (!f) return

    duration = duration || 0.2

    options = options || {}
    var destination = options.destination || defaultOptions.destination || ctx.destination
    var vcoType = options.vcoType || defaultOptions.vcoType || 'sine'
    var gain = options.gain || defaultOptions.gain || 0.4

    var vco = ctx.createOscillator()
    vco.type = vcoType
    vco.frequency.value = f

    /* VCA */
    var vca = ctx.createGain()
    vca.gain.value = gain

    /* Connections */
    vco.connect(vca)
    vca.connect(destination)

    vco.start(time)
    if (duration > 0) vco.stop(time + duration)
    return vco
  }
  return function (note, time, duration) {
    var m = note > 0 && note < 128 ? note : midi(note)
    var buffer = buffers[m]
    if (!buffer) return
    var source = ctx.createBufferSource()
    source.buffer = buffer

    /* VCA */
    var vca = ctx.createGain()
    vca.gain.value = gain
    source.connect(vca)
    vca.connect(destination)

    source.start(time)
    if (duration > 0) source.stop(time + duration)
    return source
  }
Example #3
0
 var promises = Object.keys(bank.data).map(function (note) {
   // First check is notes are passed by as param
   if (typeof notes !== 'undefined') {
     // convert the notes to midi number
     var notesMidi = notes.map(midi)
     // if the current notes is needed for the instrument.
     if (notesMidi.indexOf(midi(note)) !== -1) {
       return decodeBuffer(bank.ctx, bank.data[note])
         .then(function (buffer) {
           bank.buffers[midi(note)] = buffer
         })
     }
   } else {
     return decodeBuffer(bank.ctx, bank.data[note])
       .then(function (buffer) {
         bank.buffers[midi(note)] = buffer
       })
   }
 })
  return function (note, time, duration) {
    var f = freq(midi(note))
    if (!f) return

    duration = duration || 0.2

    var vco = ctx.createOscillator()
    vco.type = vcoType
    vco.frequency.value = f

    /* VCA */
    var vca = ctx.createGain()
    vca.gain.value = gain

    /* Connections */
    vco.connect(vca)
    vca.connect(destination)

    vco.start(time)
    if (duration > 0) vco.stop(time + duration)
    return vco
  }
Example #5
0
  return function (note, time, duration, options) {
    var m = note > 0 && note < 128 ? note : midi(note)
    var buffer = bank[m]
    if (!buffer) return

    options = options || {}
    var gain = options.gain || defaultOptions.gain || 2
    var destination = options.destination || defaultOptions.destination || ctx.destination

    var source = ctx.createBufferSource()
    source.buffer = buffer

    /* VCA */
    var vca = ctx.createGain()
    vca.gain.value = gain
    source.connect(vca)
    vca.connect(destination)
    if (duration > 0) {
      source.start(time, 0, duration)
    } else {
      source.start(time)
    }
    return source
  }
Example #6
0
 scheduler.schedule(ac, 0, e, function (time, note) {
   console.log(time, note)
   var freq = toFreq(440, toMidi(note.pitch))
   if (freq) player(ac, freq, time, note.duration, note.velocity)
 })
 .then(function (buffer) {
   bank.buffers[midi(note)] = buffer
 })