Noah 8 år sedan
förälder
incheckning
38199dc250
3 ändrade filer med 46 tillägg och 22 borttagningar
  1. 1 1
      audiogram/waveform.js
  2. 14 0
      test/probe-test.js
  3. 31 21
      test/waveform-test.js

+ 1 - 1
audiogram/waveform.js Visa fil

@@ -76,7 +76,7 @@ function processSamples(samples, numFrames, samplesPerFrame) {
76 76
 
77 77
   var adjusted = unadjusted.map(function(frame){
78 78
     return frame.map(function(point){
79
-      return [adjustment * point[0], adjustment * point[1]];
79
+      return point.map(function(p){ return adjustment * p; });
80 80
     });
81 81
   });
82 82
 

+ 14 - 0
test/probe-test.js Visa fil

@@ -22,6 +22,20 @@ tape("MP3 probe", function(test) {
22 22
 
23 23
 });
24 24
 
25
+tape("Mono probe", function(test) {
26
+
27
+  probe(path.join(__dirname, "data/glazed-donut-mono.mp3"), function(err, data){
28
+
29
+    test.error(err);
30
+    test.equal(typeof data.duration, "number");
31
+    test.equal(data.channels, 1);
32
+    test.assert(Math.abs(data.duration - 26.67) < 0.1);
33
+    test.end();
34
+
35
+  });
36
+
37
+});
38
+
25 39
 tape("WAV probe", function(test) {
26 40
 
27 41
   probe(path.join(__dirname, "data/glazed-donut.wav"), function(err, data){

+ 31 - 21
test/waveform-test.js Visa fil

@@ -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