From 1865ff9c7918f225694ef9740d7983a18314ae16 Mon Sep 17 00:00:00 2001 From: Trek H Date: Sun, 11 Aug 2019 16:54:30 +0930 Subject: [PATCH] audio-player: formatting --- cmd/audio-player/main.js | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/cmd/audio-player/main.js b/cmd/audio-player/main.js index 00d0eab6..1d893bb3 100644 --- a/cmd/audio-player/main.js +++ b/cmd/audio-player/main.js @@ -23,35 +23,36 @@ LICENSE */ window.onload = function () { + document.getElementById('input').addEventListener('change', processData) +} - document.getElementById('input').addEventListener('change', function () { - const input = event.target.files[0] - const reader = new FileReader() +function processData() { + const input = event.target.files[0] + const reader = new FileReader() - reader.onload = event => { - bytes = new Uint8Array(event.target.result) + reader.onload = event => { + bytes = new Uint8Array(event.target.result) - // decode adpcm to pcm - var decoded = decode(Array.from(bytes)) + // decode adpcm to pcm + var decoded = decode(Array.from(bytes)) - // convert raw pcm to wav - var wav = pcmToWav(decoded, 48000, 1, 16); + // 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' - }); - const url = URL.createObjectURL(blob); + // play wav data in player + const blob = new Blob([Uint8Array.from(wav)], { + type: 'audio/wav' + }); + const url = URL.createObjectURL(blob); - const audio = document.getElementById('audio'); - const source = document.getElementById('source'); + const audio = document.getElementById('audio'); + const source = document.getElementById('source'); - source.src = url; - audio.load(); - audio.play(); - } - reader.onerror = error => reject(error) - reader.readAsArrayBuffer(input) + source.src = url; + audio.load(); + audio.play(); + } + reader.onerror = error => reject(error) + reader.readAsArrayBuffer(input) - }) } \ No newline at end of file