Turn audio into a shareable video. forked from nypublicradio/audiogram

waveform-test.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var tape = require("tape"),
  2. path = require("path");
  3. var getWaveform = require("../audiogram/waveform.js"),
  4. probe = require("../lib/probe.js");
  5. var sample = path.join(__dirname, "data/glazed-donut.mp3");
  6. tape("Waveform", function(test) {
  7. var options = {
  8. framesPerSecond: 20,
  9. samplesPerFrame: 10
  10. };
  11. probe(sample, function(e1, data){
  12. test.error(e1);
  13. getWaveform(sample, options, function(e2, waveform){
  14. test.error(e2);
  15. test.assert(Array.isArray(waveform) && waveform.length === Math.floor(data.duration * options.framesPerSecond));
  16. var firstMax = Math.max.apply(null, waveform[0].map(function(d){ return d[1]; }));
  17. test.assert(firstMax <= 1);
  18. test.assert(waveform.every(function(frame){
  19. return frame.length === options.samplesPerFrame && frame.every(function(f){
  20. return f.length === 2 && typeof f[0] === "number" && typeof f[1] === "number" && f[0] <= 0 && f[0] >= -1 && f[1] >= 0 && f[1] <= firstMax;
  21. });
  22. }));
  23. test.end();
  24. });
  25. });
  26. });
  27. tape("Max Duration Error", function(test) {
  28. var options = {
  29. framesPerSecond: 20,
  30. samplesPerFrame: 10,
  31. maxDuration: 20
  32. };
  33. getWaveform(sample, options, function(err, waveform){
  34. test.assert(err);
  35. test.end();
  36. });
  37. });
  38. tape("Max Duration OK", function(test) {
  39. var options = {
  40. framesPerSecond: 20,
  41. samplesPerFrame: 10,
  42. maxDuration: 30
  43. };
  44. getWaveform(sample, options, function(err, waveform){
  45. test.error(err);
  46. test.end();
  47. });
  48. });