|
@@ -1,66 +1,73 @@
|
1
|
1
|
var tape = require("tape"),
|
2
|
2
|
path = require("path");
|
3
|
3
|
|
4
|
|
-var getWaveform = require("../audiogram/waveform.js");
|
|
4
|
+var getWaveform = require("../audiogram/waveform.js"),
|
|
5
|
+ probe = require("../lib/probe.js");
|
5
|
6
|
|
6
|
7
|
var sample = path.join(__dirname, "data/glazed-donut.mp3");
|
7
|
8
|
|
8
|
9
|
tape("Waveform", function(test) {
|
9
|
10
|
|
10
|
11
|
var options = {
|
11
|
|
- numFrames: 500,
|
|
12
|
+ framesPerSecond: 20,
|
12
|
13
|
samplesPerFrame: 10
|
13
|
14
|
};
|
14
|
15
|
|
15
|
|
- getWaveform(sample, options, function(err, waveform){
|
|
16
|
+ probe(sample, function(e1, data){
|
16
|
17
|
|
17
|
|
- test.error(err);
|
18
|
|
- test.assert(Array.isArray(waveform) && waveform.length === options.numFrames);
|
|
18
|
+ test.error(e1);
|
19
|
19
|
|
20
|
|
- var firstMax = Math.max.apply(null, waveform[0]);
|
|
20
|
+ getWaveform(sample, options, function(e2, waveform){
|
21
|
21
|
|
22
|
|
- test.assert(firstMax <= 1);
|
|
22
|
+ test.error(e2);
|
|
23
|
+ test.assert(Array.isArray(waveform) && waveform.length === Math.floor(data.duration * options.framesPerSecond));
|
23
|
24
|
|
24
|
|
- test.assert(waveform.every(function(frame){
|
25
|
|
- return frame.length === options.samplesPerFrame;
|
26
|
|
- }));
|
|
25
|
+ var firstMax = Math.max.apply(null, waveform[0].map(function(d){ return d[1]; }));
|
27
|
26
|
|
28
|
|
- test.assert(waveform.every(function(frame){
|
29
|
|
- return frame.every(function(val){
|
30
|
|
- return typeof val === "number" && val >= 0 && val <= firstMax;
|
31
|
|
- });
|
32
|
|
- }));
|
|
27
|
+ test.assert(firstMax <= 1);
|
33
|
28
|
|
34
|
|
- test.end();
|
|
29
|
+ test.assert(waveform.every(function(frame){
|
|
30
|
+ return frame.length === options.samplesPerFrame && frame.every(function(f){
|
|
31
|
+ return f.length === 2 && typeof f[0] === "number" && typeof f[1] === "number" && f[0] <= 0 && f[0] >= -1 && f[1] >= 0 && f[1] <= firstMax;
|
|
32
|
+ });
|
|
33
|
+ }));
|
|
34
|
+
|
|
35
|
+ test.end();
|
|
36
|
+
|
|
37
|
+ });
|
35
|
38
|
|
36
|
39
|
});
|
37
|
40
|
|
38
|
41
|
});
|
39
|
42
|
|
40
|
|
-tape("Waveform missing numFrames", function(test) {
|
|
43
|
+tape("Max Duration Error", function(test) {
|
41
|
44
|
|
42
|
45
|
var options = {
|
43
|
|
- samplesPerFrame: 10
|
|
46
|
+ framesPerSecond: 20,
|
|
47
|
+ samplesPerFrame: 10,
|
|
48
|
+ maxDuration: 20
|
44
|
49
|
};
|
45
|
50
|
|
46
|
51
|
getWaveform(sample, options, function(err, waveform){
|
47
|
52
|
|
48
|
|
- test.ok(err);
|
|
53
|
+ test.assert(err);
|
49
|
54
|
test.end();
|
50
|
55
|
|
51
|
56
|
});
|
52
|
57
|
|
53
|
58
|
});
|
54
|
59
|
|
55
|
|
-tape("Waveform missing samplesPerFrame", function(test) {
|
|
60
|
+tape("Max Duration OK", function(test) {
|
56
|
61
|
|
57
|
62
|
var options = {
|
58
|
|
- numFrames: 500,
|
|
63
|
+ framesPerSecond: 20,
|
|
64
|
+ samplesPerFrame: 10,
|
|
65
|
+ maxDuration: 30
|
59
|
66
|
};
|
60
|
67
|
|
61
|
68
|
getWaveform(sample, options, function(err, waveform){
|
62
|
69
|
|
63
|
|
- test.ok(err);
|
|
70
|
+ test.error(err);
|
64
|
71
|
test.end();
|
65
|
72
|
|
66
|
73
|
});
|