diff --git a/audiogram/waveform.js b/audiogram/waveform.js index 47fc0095..fdbf3a77 100644 --- a/audiogram/waveform.js +++ b/audiogram/waveform.js @@ -76,7 +76,7 @@ function processSamples(samples, numFrames, samplesPerFrame) { var adjusted = unadjusted.map(function(frame){ return frame.map(function(point){ - return [adjustment * point[0], adjustment * point[1]]; + return point.map(function(p){ return adjustment * p; }); }); }); diff --git a/test/probe-test.js b/test/probe-test.js index 2864cac3..e7b0af2c 100644 --- a/test/probe-test.js +++ b/test/probe-test.js @@ -22,6 +22,20 @@ tape("MP3 probe", function(test) { }); +tape("Mono probe", function(test) { + + probe(path.join(__dirname, "data/glazed-donut-mono.mp3"), function(err, data){ + + test.error(err); + test.equal(typeof data.duration, "number"); + test.equal(data.channels, 1); + test.assert(Math.abs(data.duration - 26.67) < 0.1); + test.end(); + + }); + +}); + tape("WAV probe", function(test) { probe(path.join(__dirname, "data/glazed-donut.wav"), function(err, data){ diff --git a/test/waveform-test.js b/test/waveform-test.js index 689e175a..72b966bc 100644 --- a/test/waveform-test.js +++ b/test/waveform-test.js @@ -1,7 +1,8 @@ var tape = require("tape"), path = require("path"); -var getWaveform = require("../audiogram/waveform.js"), +var Audiogram = require("../audiogram/"), + getWaveform = require("../audiogram/waveform.js"), probe = require("../lib/probe.js"); var sample = path.join(__dirname, "data/glazed-donut.mp3"); @@ -17,18 +18,17 @@ tape("Waveform", function(test) { test.error(e1); + options.channels = data.channels; + options.numFrames = Math.floor(data.duration * options.framesPerSecond); + getWaveform(sample, options, function(e2, waveform){ test.error(e2); - test.assert(Array.isArray(waveform) && waveform.length === Math.floor(data.duration * options.framesPerSecond)); - - var firstMax = Math.max.apply(null, waveform[0].map(function(d){ return d[1]; })); - - test.assert(firstMax <= 1); + test.assert(Array.isArray(waveform) && waveform.length === options.numFrames); test.assert(waveform.every(function(frame){ return frame.length === options.samplesPerFrame && frame.every(function(f){ - return f.length === 2 && typeof f[0] === "number" && typeof f[1] === "number" && f[0] <= 0 && f[0] >= -1 && f[1] >= 0 && f[1] <= firstMax; + 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; }); })); @@ -42,33 +42,43 @@ tape("Waveform", function(test) { tape("Max Duration Error", function(test) { - var options = { - framesPerSecond: 20, - samplesPerFrame: 10, - maxDuration: 20 + var audiogram = new Audiogram("xyz"); + audiogram.audioPath = sample; + audiogram.settings = { + theme: { + maxDuration: 20 + } }; - getWaveform(sample, options, function(err, waveform){ - + audiogram.getWaveform(function(err, waveform){ test.assert(err); + test.assert(err.toString().match(/Exceeds max duration/)); test.end(); - }); }); tape("Max Duration OK", function(test) { - var options = { - framesPerSecond: 20, - samplesPerFrame: 10, - maxDuration: 30 + var audiogram = new Audiogram("xyz"); + audiogram.audioPath = sample; + audiogram.settings = { + theme: { + samplesPerFrame: 10, + framesPerSecond: 20 + } }; - getWaveform(sample, options, function(err, waveform){ + probe(sample, function(err, data){ + test.deepEqual(Math.round(data.duration), 27); + test.deepEqual(data.channels, 2); - test.error(err); - test.end(); + audiogram.getWaveform(function(waveformErr, waveform){ + test.error(waveformErr); + test.assert(Array.isArray(waveform)); + test.deepEqual(waveform.length, Math.floor(data.duration * audiogram.settings.theme.framesPerSecond)); + test.end(); + }); });