Skip to content

Instantly share code, notes, and snippets.

@autotel
Created May 3, 2019 13:55
Show Gist options
  • Save autotel/bc89bd98190e552d33b8551f95f876c9 to your computer and use it in GitHub Desktop.
Save autotel/bc89bd98190e552d33b8551f95f876c9 to your computer and use it in GitHub Desktop.

PS (...)\node-aubio-test> nodemon . [nodemon] 1.17.5 [nodemon] to restart at any time, enter rs [nodemon] watching: . [nodemon] starting node . (...)node-aubio-test\node_modules\ffi\lib\dynamic_library.js:74 throw new Error('Dynamic Linking Error: ' + err) ^

Error: Dynamic Linking Error: Win32 error 126 at new DynamicLibrary ((...)\node-aubio-test\node_modules\ffi\lib\dynamic_library.js:74:11) at Object.Library ((...)\node-aubio-test\node_modules\ffi\lib\library.js:45:12) at Object. ((...)\node-aubio-test\node_modules\node-aubio\index.js:7:17) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) [nodemon] app crashed - waiting for file changes before starting...

const aubio=require('node-aubio');
var ref = require('ref');
var filter_source = function(inputfile, outputfile, params) {
// open input file for reading
var source = aubio.new_aubio_source(inputfile, params.samplerate, params.hop_s);
try {
source.readPointer();
} catch (e) {
console.log('failed opening ' + inputfile + ' for reading');
return;
}
// get the real samplerate of the input file in case 0 was passed as params.samplerate
var samplerate = aubio.aubio_source_get_samplerate(source);
// open output file for writing
var sink = aubio.new_aubio_sink(outputfile, samplerate);
try {
sink.readPointer();
} catch (e) {
console.log('failed opening ' + outputfile + ' for writing');
return;
}
// create filter
var filter = aubio.new_aubio_filter_a_weighting(samplerate);
// start processing
var total_frames = 0;
var readPtr = ref.alloc('int');
var samples = aubio.new_fvec(params.hop_s);
while (true) {
aubio.aubio_source_do(source, samples, readPtr);
aubio.aubio_filter_do(filter, samples);
aubio.aubio_sink_do(sink, samples, readPtr.deref());
total_frames += readPtr.deref();
if (readPtr.deref() != params.hop_s) { break; }
}
var cur_time = total_frames / samplerate;
console.log('read %d seconds (%d frames) from %s', cur_time.toFixed(3),
total_frames, inputfile);
console.log('wrote filtered version to %s', outputfile);
// clean up
aubio.del_aubio_sink(sink);
aubio.del_aubio_source(source);
}
if (process.argv[2] && process.argv[3]) {
var inputfile = process.argv[2];
var outputfile = process.argv[3];
} else {
console.error('command line arguments are required.');
console.log('usage examples:');
console.log(' ' + process.argv[0] + ' ' + process.argv[1] + ' <fileinput.wav> <fileoutput.wav');
console.log(' ' + process.argv[0] + ' ' + process.argv[1] + ' <anotherfile.mp3> <fileoutput.wav>');
return;
}
filter_source(inputfile, outputfile, {
samplerate: 44100,
hop_s : 512,
});
{
"name": "node-aubio-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"node-aubio": "0.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment