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

waveform-test.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var tape = require("tape"),
  2. path = require("path");
  3. var getWaveform = require("../audiogram/waveform.js");
  4. var sample = path.join(__dirname, "data/glazed-donut.mp3");
  5. tape("Waveform", function(test) {
  6. var options = {
  7. numFrames: 500,
  8. samplesPerFrame: 10
  9. };
  10. getWaveform(sample, options, function(err, waveform){
  11. test.error(err);
  12. test.assert(Array.isArray(waveform) && waveform.length === options.numFrames);
  13. var firstMax = Math.max.apply(null, waveform[0]);
  14. test.assert(firstMax <= 1);
  15. test.assert(waveform.every(function(frame){
  16. return frame.length === options.samplesPerFrame;
  17. }));
  18. test.assert(waveform.every(function(frame){
  19. return frame.every(function(val){
  20. return typeof val === "number" && val >= 0 && val <= firstMax;
  21. });
  22. }));
  23. test.end();
  24. });
  25. });
  26. tape("Waveform missing numFrames", function(test) {
  27. var options = {
  28. samplesPerFrame: 10
  29. };
  30. getWaveform(sample, options, function(err, waveform){
  31. test.ok(err);
  32. test.end();
  33. });
  34. });
  35. tape("Waveform missing samplesPerFrame", function(test) {
  36. var options = {
  37. numFrames: 500,
  38. };
  39. getWaveform(sample, options, function(err, waveform){
  40. test.ok(err);
  41. test.end();
  42. });
  43. });