From fd4a3b99e5ed8ae929973a04fafb9bd2daee159c Mon Sep 17 00:00:00 2001 From: Jon Lippincott Date: Tue, 7 Aug 2018 01:05:16 -0400 Subject: [PATCH] Because why not, I made the test render the waveform. --- test/render.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/render.js b/test/render.js index 7a6d9cf..9a6f103 100644 --- a/test/render.js +++ b/test/render.js @@ -1,6 +1,14 @@ var render = require('../lib/render') var fs = require('fs') +function msg(s) { + process.stdout.write(s || ''); +} + +function msgnl(s) { + msg(`${(s || '')}\n`); +} + render('Canon.mp3', function (err, buffer) { if (err) return err fs.writeFileSync('out.png', buffer) @@ -16,7 +24,17 @@ render('Canon.mp3', { height: height, normalizedValuesCallback: function(normalizedVals) { - console.log(normalizedVals) + const numLines = 20; + const numSamples = Math.min(process.stdout.columns, normalizedVals.length); + + msgnl(); + for (let line = numLines; line >= 0; --line) { + for (let idx = 0; idx < numSamples; ++idx) { + const val = normalizedVals[idx]; + msg(val >= line/(numLines - 1) ? '|' : ' '); + } + msgnl(); + } } }, function(err, buffer) {