Decode audio files with AudioContext
This commit is contained in:
parent
a4f975b5e5
commit
4f005e86c2
33
js/ngfile.js
33
js/ngfile.js
@ -128,8 +128,8 @@ app.controller('mainController', function ($scope, $http, wave) {
|
||||
}
|
||||
|
||||
|
||||
reader.onload = function (e) {
|
||||
var x = reader.result.split(/[\s,;\t\r\n]+/);
|
||||
function parseTextData(inputText) {
|
||||
var x = inputText.split(/[\s,;\t\r\n]+/);
|
||||
|
||||
var j = 0;
|
||||
|
||||
@ -158,15 +158,44 @@ app.controller('mainController', function ($scope, $http, wave) {
|
||||
wave.sigData.splice(j, rm);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
async function parseAudioData(inputBuffer) {
|
||||
console.log("Converting a", inputBuffer.byteLength,
|
||||
"bytes audio buffer to linear PCM");
|
||||
|
||||
var audioCtx = new AudioContext({ sampleRate: 44100 });
|
||||
var pcmData = await audioCtx.decodeAudioData(inputBuffer);
|
||||
var pcmSamples = pcmData.getChannelData(0); // Float32Array
|
||||
|
||||
wave.sigData = new Float64Array(pcmSamples);
|
||||
wave.sigLength = pcmSamples.length;
|
||||
}
|
||||
|
||||
reader.onload = async function (e) {
|
||||
var input = reader.result;
|
||||
|
||||
if (input instanceof ArrayBuffer)
|
||||
await parseAudioData(input);
|
||||
else
|
||||
parseTextData(input);
|
||||
|
||||
console.log("Input wave:", wave.sigLength, "samples");
|
||||
|
||||
if (wave.transform == 1) {
|
||||
location.href = '#/display';
|
||||
} else if (wave.transform == 2) {
|
||||
location.href = '#/cdisplay';
|
||||
} else if (wave.transform == 4) {
|
||||
location.href = '#/denoise';
|
||||
} else {
|
||||
location.href = '#/cdisplay';
|
||||
}
|
||||
}
|
||||
|
||||
if (finp1.type == "audio/mpeg")
|
||||
reader.readAsArrayBuffer(finp1);
|
||||
else
|
||||
reader.readAsText(finp1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user