|
@@ -1,7 +1,8 @@
|
1
|
1
|
var tape = require("tape"),
|
2
|
2
|
path = require("path");
|
3
|
3
|
|
4
|
|
-var getWaveform = require("../audiogram/waveform.js"),
|
|
4
|
+var Audiogram = require("../audiogram/"),
|
|
5
|
+ getWaveform = require("../audiogram/waveform.js"),
|
5
|
6
|
probe = require("../lib/probe.js");
|
6
|
7
|
|
7
|
8
|
var sample = path.join(__dirname, "data/glazed-donut.mp3");
|
|
@@ -17,18 +18,17 @@ tape("Waveform", function(test) {
|
17
|
18
|
|
18
|
19
|
test.error(e1);
|
19
|
20
|
|
|
21
|
+ options.channels = data.channels;
|
|
22
|
+ options.numFrames = Math.floor(data.duration * options.framesPerSecond);
|
|
23
|
+
|
20
|
24
|
getWaveform(sample, options, function(e2, waveform){
|
21
|
25
|
|
22
|
26
|
test.error(e2);
|
23
|
|
- test.assert(Array.isArray(waveform) && waveform.length === Math.floor(data.duration * options.framesPerSecond));
|
24
|
|
-
|
25
|
|
- var firstMax = Math.max.apply(null, waveform[0].map(function(d){ return d[1]; }));
|
26
|
|
-
|
27
|
|
- test.assert(firstMax <= 1);
|
|
27
|
+ test.assert(Array.isArray(waveform) && waveform.length === options.numFrames);
|
28
|
28
|
|
29
|
29
|
test.assert(waveform.every(function(frame){
|
30
|
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;
|
|
31
|
+ return f.length === 3 && f.every(function(d){ return typeof d === "number"; }) && f[0] <= 0 && f[0] >= -1 && f[1] >= 0 && f[1] <= 1 && f[2] >= -1 && f[2] <= 1;
|
32
|
32
|
});
|
33
|
33
|
}));
|
34
|
34
|
|
|
@@ -42,33 +42,43 @@ tape("Waveform", function(test) {
|
42
|
42
|
|
43
|
43
|
tape("Max Duration Error", function(test) {
|
44
|
44
|
|
45
|
|
- var options = {
|
46
|
|
- framesPerSecond: 20,
|
47
|
|
- samplesPerFrame: 10,
|
48
|
|
- maxDuration: 20
|
|
45
|
+ var audiogram = new Audiogram("xyz");
|
|
46
|
+ audiogram.audioPath = sample;
|
|
47
|
+ audiogram.settings = {
|
|
48
|
+ theme: {
|
|
49
|
+ maxDuration: 20
|
|
50
|
+ }
|
49
|
51
|
};
|
50
|
52
|
|
51
|
|
- getWaveform(sample, options, function(err, waveform){
|
52
|
|
-
|
|
53
|
+ audiogram.getWaveform(function(err, waveform){
|
53
|
54
|
test.assert(err);
|
|
55
|
+ test.assert(err.toString().match(/Exceeds max duration/));
|
54
|
56
|
test.end();
|
55
|
|
-
|
56
|
57
|
});
|
57
|
58
|
|
58
|
59
|
});
|
59
|
60
|
|
60
|
61
|
tape("Max Duration OK", function(test) {
|
61
|
62
|
|
62
|
|
- var options = {
|
63
|
|
- framesPerSecond: 20,
|
64
|
|
- samplesPerFrame: 10,
|
65
|
|
- maxDuration: 30
|
|
63
|
+ var audiogram = new Audiogram("xyz");
|
|
64
|
+ audiogram.audioPath = sample;
|
|
65
|
+ audiogram.settings = {
|
|
66
|
+ theme: {
|
|
67
|
+ samplesPerFrame: 10,
|
|
68
|
+ framesPerSecond: 20
|
|
69
|
+ }
|
66
|
70
|
};
|
67
|
71
|
|
68
|
|
- getWaveform(sample, options, function(err, waveform){
|
|
72
|
+ probe(sample, function(err, data){
|
|
73
|
+ test.deepEqual(Math.round(data.duration), 27);
|
|
74
|
+ test.deepEqual(data.channels, 2);
|
69
|
75
|
|
70
|
|
- test.error(err);
|
71
|
|
- test.end();
|
|
76
|
+ audiogram.getWaveform(function(waveformErr, waveform){
|
|
77
|
+ test.error(waveformErr);
|
|
78
|
+ test.assert(Array.isArray(waveform));
|
|
79
|
+ test.deepEqual(waveform.length, Math.floor(data.duration * audiogram.settings.theme.framesPerSecond));
|
|
80
|
+ test.end();
|
|
81
|
+ });
|
72
|
82
|
|
73
|
83
|
});
|
74
|
84
|
|