-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
55 lines (49 loc) · 1.35 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* global AudioContext */
require('web-audio-test-api')
var test = require('tape')
var Contour = require('.')
test('5 stage envelope', function (t) {
var ac = new AudioContext()
var env = Contour(ac)
t.ok(env)
t.end()
})
test('set options', function (t) {
var ac = new AudioContext()
var env = Contour(ac, { ramp: 'linear', duration: 100,
t1: 1, t2: 2, t3: 3, t4: 4, l1: 10, l2: 20, l3: 30 })
assertOptions(t, env, 'linear', 100, 1, 2, 3, 4, 10, 20, 30)
t.end()
})
test('ignore invalid options', function (t) {
var ac = new AudioContext()
var env = Contour(ac, { ramp: 'blah', color: 'blue' })
t.equal(env.color, undefined)
t.end()
})
test('set adsr options', function (t) {
var ac = new AudioContext()
var env = Contour(ac, { attack: 0.1, decay: 0.2, sustain: 0.8, release: 0.5 })
assertOptions(t, env, 'linear', Infinity, 0.1, 0.2, 0, 0.5, 1, 0.2, 0.8)
t.end()
})
test('onstart event', function (t) {
var ac = new AudioContext()
var times = 0
var env = Contour(ac)
env.onstart = function () { times++ }
env.start()
t.equal(times, 1)
t.end()
})
var assertOptions = function (t, env, r, d, t1, t2, t3, t4, l1, l2, l3) {
t.equal(env.ramp, r)
t.equal(env.duration, d)
t.equal(env.t1, t1)
t.equal(env.t2, t2)
t.equal(env.t3, t3)
t.equal(env.t4, t4)
t.equal(env.l1, l1)
t.equal(env.l2, l2)
t.equal(env.l3, l3)
}