123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- var tape = require("tape"),
- path = require("path"),
- fs = require("fs"),
- queue = require("d3").queue;
-
- require("mkdirp").sync(path.join(__dirname, "tmp"));
-
- var probe = require("../lib/probe.js"),
- trimAudio = require("../audiogram/trim.js");
-
- tape("MP3 probe", function(test) {
-
- probe(path.join(__dirname, "data/glazed-donut.mp3"), function(err, data){
-
- test.error(err);
- test.equal(typeof data.duration, "number");
- test.equal(data.channels, 2);
- test.assert(Math.abs(data.duration - 26.67) < 0.1);
- test.end();
-
- });
-
- });
-
- 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){
-
- test.error(err);
- test.equal(typeof data.duration, "number");
- test.equal(data.channels, 2);
- test.assert(Math.abs(data.duration - 1.83) < 0.1);
- test.end();
-
- });
-
- });
-
- tape("Mono probe", function(test) {
-
- probe(path.join(__dirname, "data/short.wav"), function(err, data){
-
- test.error(err);
- test.equal(typeof data.duration, "number");
- test.equal(data.channels, 1);
- test.assert(Math.abs(data.duration - 0.01) < 0.01);
- test.end();
-
- });
-
- });
-
- tape("Probe error", function(test) {
-
- probe(path.join(__dirname, "..", "README.md"), function(err){
-
- test.ok(err);
- test.end();
-
- });
-
- });
-
- tape("Trim start", function(test) {
-
- var options = {
- origin: path.join(__dirname, "data/glazed-donut.mp3"),
- destination: path.join(__dirname, "tmp/trim-start.mp3"),
- startTime: 6.67
- };
-
- queue(1)
- .defer(trimAudio, options)
- .defer(probe, options.destination)
- .await(function(err, _, data){
-
- test.error(err);
- test.equal(typeof data.duration, "number");
- test.assert(Math.abs(data.duration - 20) < 0.1);
- test.end();
-
- });
-
- });
-
- tape("Trim end", function(test) {
-
- var options = {
- origin: path.join(__dirname, "data/glazed-donut.mp3"),
- destination: path.join(__dirname, "tmp/trim-end.mp3"),
- startTime: 6.67
- };
-
- queue(1)
- .defer(trimAudio, options)
- .defer(probe, options.destination)
- .await(function(err, _, data){
-
- test.error(err);
- test.equal(typeof data.duration, "number");
- test.assert(Math.abs(data.duration - 20) < 0.1);
- test.end();
-
- });
-
- });
-
- tape("Trim start & end", function(test) {
-
- var options = {
- origin: path.join(__dirname, "data/glazed-donut.mp3"),
- destination: path.join(__dirname, "tmp/trim-start-end.mp3"),
- startTime: 5,
- endTime: 10
- };
-
- queue(1)
- .defer(trimAudio, options)
- .defer(probe, options.destination)
- .await(function(err, _, data){
-
- test.error(err);
- test.equal(typeof data.duration, "number");
- test.assert(Math.abs(data.duration - 5) < 0.1);
- test.end();
-
- });
-
- });
-
-
- tape("Trim invalid", function(test) {
-
- var options = {
- origin: path.join(__dirname, "data/glazed-donut.mp3"),
- destination: path.join(__dirname, "tmp/trim-invalid.mp3"),
- startTime: 5,
- endTime: 4
- };
-
- trimAudio(options, function(err){
- test.ok(err);
- test.end();
- });
-
- });
-
- // Cleanup
- tape.onFinish(function(){
- require("rimraf")(path.join(__dirname, "tmp"), function(err){
- if (err) {
- throw err;
- }
- });
- });
|