mirror of https://bitbucket.org/ausocean/av.git
audio-player: decode function completed
This commit is contained in:
parent
8a3eeec59d
commit
2c436b7edf
|
@ -30,6 +30,10 @@ let est, // Estimation of sample based on quantised ADPCM nibble.
|
|||
idx, // Index to step used for estimation.
|
||||
step;
|
||||
|
||||
function decodeSample(nibble) {
|
||||
return new Uint8Array([1, 2])
|
||||
}
|
||||
|
||||
function decode(b) {
|
||||
// b should be a Uint8Array
|
||||
if (!(b instanceof Uint8Array)) {
|
||||
|
@ -49,15 +53,15 @@ function decode(b) {
|
|||
var nib2 = twoNibs >> 4;
|
||||
var nib1 = (nib2 << 4) ^ twoNibs
|
||||
var firstBytes = decodeSample(nib1)
|
||||
concat(result, firstBytes)
|
||||
result = concat(result, firstBytes)
|
||||
|
||||
var secondBytes = decodeSample(nib2)
|
||||
concat(result, secondBytes)
|
||||
result = concat(result, secondBytes)
|
||||
}
|
||||
if (b[3] == 1) {
|
||||
var padNib = b[b.length - 1]
|
||||
var samp = decodeSample(padNib)
|
||||
concat(result, samp)
|
||||
result = concat(result, samp)
|
||||
}
|
||||
|
||||
return result;
|
|
@ -5,6 +5,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Audio Player</title>
|
||||
<script type="text/javascript" src="pcm-player.min.js"></script>
|
||||
<script type="text/javascript" src="adpcm.js"></script>
|
||||
<script type="text/javascript" src="main.js"></script>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
|
||||
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
|
||||
|
|
|
@ -7,14 +7,21 @@ window.onload = function () {
|
|||
reader.onload = event => {
|
||||
bytes = new Uint8Array(event.target.result)
|
||||
|
||||
console.log(bytes.slice(0, 16))
|
||||
|
||||
var decoded = decode(bytes)
|
||||
|
||||
console.log("playing file")
|
||||
var player = new PCMPlayer({
|
||||
encoding: '16bitInt',
|
||||
channels: 1,
|
||||
sampleRate: 48000,
|
||||
flushingTime: 2000
|
||||
});
|
||||
player.feed(bytes)
|
||||
|
||||
console.log(decoded.slice(0, 16))
|
||||
|
||||
// var player = new PCMPlayer({
|
||||
// encoding: '16bitInt',
|
||||
// channels: 1,
|
||||
// sampleRate: 48000,
|
||||
// flushingTime: 2000
|
||||
// });
|
||||
// player.feed(bytes)
|
||||
}
|
||||
reader.onerror = error => reject(error)
|
||||
reader.readAsArrayBuffer(input)
|
||||
|
|
Loading…
Reference in New Issue