2019-08-03 11:32:39 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
main.js
|
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
Trek Hopton <trek@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
This file is Copyright (C) 2018 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License in gpl.txt.
|
|
|
|
If not, see [GNU licenses](http://www.gnu.org/licenses).
|
|
|
|
*/
|
|
|
|
|
2019-07-23 11:27:03 +03:00
|
|
|
window.onload = function () {
|
|
|
|
|
|
|
|
document.getElementById('input').addEventListener('change', function () {
|
|
|
|
const input = event.target.files[0]
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
|
|
|
reader.onload = event => {
|
|
|
|
bytes = new Uint8Array(event.target.result)
|
2019-07-23 07:58:43 +03:00
|
|
|
|
2019-08-03 11:32:39 +03:00
|
|
|
// decode adpcm to pcm
|
2019-07-25 08:28:39 +03:00
|
|
|
var decoded = decode(Array.from(bytes))
|
2019-07-24 11:25:02 +03:00
|
|
|
|
2019-08-03 11:32:39 +03:00
|
|
|
// convert raw pcm to wav
|
|
|
|
var wav = pcmToWav(decoded, 48000, 1, 16);
|
|
|
|
|
|
|
|
// play wav data in player
|
|
|
|
const blob = new Blob([Uint8Array.from(wav)], {
|
|
|
|
type: 'audio/wav'
|
2019-07-25 07:02:53 +03:00
|
|
|
});
|
2019-08-03 11:32:39 +03:00
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
|
|
|
const audio = document.getElementById('audio');
|
|
|
|
const source = document.getElementById('source');
|
|
|
|
|
|
|
|
source.src = url;
|
|
|
|
audio.load();
|
|
|
|
audio.play();
|
2019-07-23 11:27:03 +03:00
|
|
|
}
|
|
|
|
reader.onerror = error => reject(error)
|
|
|
|
reader.readAsArrayBuffer(input)
|
2019-07-23 07:58:43 +03:00
|
|
|
|
2019-07-23 11:27:03 +03:00
|
|
|
})
|
2019-07-18 09:34:50 +03:00
|
|
|
}
|