Skip to content

Commit

Permalink
Because why not, I made the test render the waveform.
Browse files Browse the repository at this point in the history
  • Loading branch information
drone1 committed Aug 7, 2018
1 parent 0b7d776 commit fd4a3b9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/render.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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) {
Expand Down

0 comments on commit fd4a3b9

Please sign in to comment.