audio-slot
Advanced tools
Comparing version 3.8.0 to 3.9.0
@@ -121,3 +121,3 @@ var Observ = require('observ') | ||
offEvents.push([source, releaseDuration]) | ||
source.triggerOff(at) | ||
}) | ||
@@ -124,0 +124,0 @@ |
@@ -41,2 +41,5 @@ var interpolate = require('./interpolate.js') | ||
descriptor.at = Math.max(descriptor.at, context.audio.currentTime) | ||
toTime = Math.max(toTime, context.audio.currentTime) | ||
var fromValue = getValueAt(descriptor.at) | ||
@@ -43,0 +46,0 @@ |
@@ -5,2 +5,3 @@ var Observ = require('observ') | ||
var Property = require('../property.js') | ||
var Transform = require('./transform.js') | ||
var Event = require('geval') | ||
@@ -21,6 +22,19 @@ | ||
var broadcast = null | ||
obs.onSchedule = Event(function(b){ | ||
broadcast = b | ||
}) | ||
var eventSource = { | ||
onSchedule: Event(function(b){ | ||
broadcast = b | ||
}), | ||
getValueAt: function(at){ | ||
return 0 | ||
} | ||
} | ||
var outputValue = Transform(context, [ | ||
{ param: obs.value }, | ||
{ param: eventSource, transform: multiply } | ||
]) | ||
obs.getValueAt = outputValue.getValueAt | ||
obs.onSchedule = outputValue.onSchedule | ||
obs.context = context | ||
@@ -32,13 +46,7 @@ | ||
var peakTime = at + (obs.attack() || 0.005) | ||
var value = obs.value.getValueAt(at+peakTime) | ||
if (obs.release() && obs.attack()){ | ||
broadcast({ mode: 'init', value: 0, at: at }) | ||
} else { | ||
broadcast({ value: 0, at: at }) | ||
} | ||
if (obs.attack()){ | ||
broadcast({ | ||
value: value, | ||
fromValue: 0, | ||
value: 1, | ||
at: at, | ||
@@ -49,3 +57,3 @@ duration: obs.attack(), | ||
} else { | ||
broadcast({ value: value, at: at }) | ||
broadcast({ value: 1, at: at }) | ||
} | ||
@@ -55,3 +63,3 @@ | ||
broadcast({ | ||
value: obs.sustain()*value, | ||
value: obs.sustain(), | ||
at: peakTime, | ||
@@ -73,2 +81,4 @@ duration: obs.decay(), | ||
}) | ||
} else { | ||
broadcast({ value: 0, at: at }) | ||
} | ||
@@ -92,2 +102,6 @@ | ||
return start + phase * difference | ||
} | ||
function multiply (a,b) { | ||
return a * b | ||
} |
@@ -90,3 +90,3 @@ var Event = require('geval') | ||
broadcast({ | ||
broadcastIfValid({ | ||
at: descriptor.at, | ||
@@ -100,5 +100,4 @@ mode: descriptor.mode, | ||
if (endTime > toTime){ | ||
broadcast({ | ||
broadcastIfValid({ | ||
at: toTime, | ||
//mode: descriptor.mode, | ||
value: getValueAt(endTime), | ||
@@ -110,2 +109,8 @@ duration: endTime - toTime | ||
function broadcastIfValid(descriptor) { | ||
if (descriptor && isFinite(descriptor.value)) { | ||
broadcast(descriptor) | ||
} | ||
} | ||
function truncate(index, at){ | ||
@@ -153,3 +158,2 @@ var events = channels[index] | ||
if (typeof lastValue == 'number' && isNaN(lastValue)){ | ||
debugger | ||
getChannelValueAt(i, time) | ||
@@ -156,0 +160,0 @@ transforms[i](l, value) |
{ | ||
"name": "audio-slot", | ||
"version": "3.8.0", | ||
"version": "3.9.0", | ||
"description": "Web Audio API FRP wrapper for creating, routing, and triggering AudioNodes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,3 +19,3 @@ var Observ = require('observ') | ||
var oscillator = context.audio.createOscillator() | ||
var oscillator = null | ||
var power = context.audio.createGain() | ||
@@ -26,3 +26,2 @@ var amp = context.audio.createGain() | ||
oscillator.connect(power) | ||
choker.gain.value = 0 | ||
@@ -34,5 +33,4 @@ amp.gain.value = 0 | ||
oscillator.start() | ||
var releaseSchedule = context.scheduler.onSchedule(handleSchedule) | ||
var releaseSync = [] | ||
@@ -55,5 +53,2 @@ var obs = ObservStruct({ | ||
Apply(context, amp.gain, obs.amp) | ||
Apply(context, oscillator.detune, obs.detune) | ||
var frequency = Transform(context, [ 440, | ||
@@ -69,16 +64,6 @@ { param: obs.octave, transform: transformOctave }, | ||
Apply(context, oscillator.frequency, frequency) | ||
Apply(context, amp.gain, obs.amp) | ||
Apply(context, power.gain, powerRolloff) | ||
var lastShape = 'sine' | ||
obs.shape(function(shape){ | ||
if (shape !== lastShape) { | ||
if (context.periodicWaves && context.periodicWaves[shape]) { | ||
oscillator.setPeriodicWave(context.periodicWaves[shape]) | ||
} else { | ||
oscillator.type = shape | ||
} | ||
lastShape = shape | ||
} | ||
}) | ||
obs.shape(refreshShape) | ||
@@ -126,3 +111,2 @@ obs.getReleaseDuration = Param.getReleaseDuration.bind(this, obs) | ||
frequency.destroy() | ||
releaseSchedule&&releaseSchedule() | ||
@@ -135,2 +119,3 @@ releaseSchedule = null | ||
resync() | ||
return obs | ||
@@ -144,12 +129,37 @@ | ||
choker.disconnect() | ||
resync() | ||
} | ||
} | ||
function flush(at){ | ||
if (hasTriggered){ | ||
var to = at + 0.2 | ||
choker.connect(output) | ||
if ((!maxTime || maxTime < to) && lastOn < lastOff){ | ||
maxTime = to | ||
function resync () { | ||
while (releaseSync.length) { | ||
releaseSync.pop()() | ||
} | ||
if (oscillator) { | ||
oscillator.disconnect() | ||
} | ||
oscillator = context.audio.createOscillator() | ||
oscillator.lastShape = 'sine' | ||
refreshShape() | ||
oscillator.connect(power) | ||
oscillator.start() | ||
releaseSync.push( | ||
Apply(context, oscillator.detune, obs.detune), | ||
Apply(context, oscillator.frequency, frequency) | ||
) | ||
} | ||
function refreshShape () { | ||
var shape = obs.shape() | ||
if (shape !== oscillator.lastShape) { | ||
if (context.periodicWaves && context.periodicWaves[shape]) { | ||
oscillator.setPeriodicWave(context.periodicWaves[shape]) | ||
} else { | ||
oscillator.type = shape | ||
} | ||
oscillator.lastShape = shape | ||
} | ||
@@ -156,0 +166,0 @@ } |
72362
33
2371