-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
64 lines (41 loc) · 1.49 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
56
57
58
59
60
61
62
63
import AudioBuffer from './index.js'
import t from 'tape'
t('options', function (t) {
var b3 = new AudioBuffer({length: 220.5, sampleRate:44100, numberOfChannels:1});
t.equal(b3.length, 220)
var buffer = new AudioBuffer({length: 441, sampleRate: 44100, numberOfChannels: 1});
t.equal(buffer.duration, 0.01);
var buffer = new AudioBuffer({length: 441, sampleRate: 44100*2, numberOfChannels: 1});
t.equal(buffer.duration, 0.005);
t.end()
});
t('getChannelData empty arrays', function (t) {
var buffer = new AudioBuffer({length: 4, sampleRate: 44100, numberOfChannels: 1});
t.deepEqual([...buffer.getChannelData(0)], [0,0,0,0]);
t.end()
});
t('copyToChannel', function (t) {
var a = new AudioBuffer({numberOfChannels: 2, length: 40, sampleRate: 44100});
var arr = new Float32Array(40);
arr.fill(-0.5);
a.copyToChannel(arr, 0, 0);
t.deepEqual(arr, a.getChannelData(0));
a.copyToChannel(arr, 1, 10);
var zeros = new Float32Array(10);
arr.set(zeros);
t.deepEqual(arr, a.getChannelData(1));
t.end()
});
t('copyFromChannel', function (t) {
var a = new AudioBuffer({numberOfChannels: 2, length: 40, sampleRate: 44100});
var arr = new Float32Array(40);
a.getChannelData(0).fill(-0.5);
a.getChannelData(1).fill(0.5);
a.getChannelData(1).set((new Float32Array(20)).fill(-0.5), 20);
a.copyFromChannel(arr, 0);
t.deepEqual(arr, a.getChannelData(0));
a.copyFromChannel(arr, 1, 10);
var fixture = Array(10).fill(0.5).concat(Array(30).fill(-0.5));
t.deepEqual([...arr], fixture);
t.end()
});