Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,17 @@ <h2>Demo:</h2>
pcm=[];
value=kjmp2_decode_frame(mp2,frame,pcm,l,r);
if (value) {
if (!!(window.AudioContext || window.webkitAudioContext)) {
for(var i=0;i<l.length;i++){
lchannel.push(l[i]);
rchannel.push(r[i]);
};
} else {
for(var i=0;i<l.length;i++){
dec.push(l[i]);
dec.push(r[i]);
};
}
frame=frame.subarray(value);
bytes_left -= value;
t.innerHTML="Bytes left to decode: " +bytes_left;
Expand Down Expand Up @@ -106,9 +113,11 @@ <h2>Demo:</h2>
get_mp2(function(){
s.parentNode.removeChild(s);
dec=[];
lchannel = [];
rchannel = [];
r=[];
l=[];
buffer = xhr.mozResponseArrayBuffer;
buffer = xhr.response ? xhr.response : xhr.mozResponseArrayBuffer;
frame= new Uint8Array(buffer);
bytes_left = frame.length-100;
decode_mp2();
Expand Down Expand Up @@ -179,6 +188,22 @@ <h2>Demo:</h2>
};
}

if (!!(window.AudioContext || window.webkitAudioContext)) {
var context = new (window.AudioContext || window.webkitAudioContext)();
var sndbuffer = context.createBuffer(2, lchannel.length + rchannel.length, sampleRate);
sndbuffer.copyToChannel(new Float32Array(lchannel), 0, 0);
sndbuffer.copyToChannel(new Float32Array(rchannel), 1, 0);
var source = context.createBufferSource();
source.buffer = sndbuffer;
source.connect(context.destination);
var start=function() {
source.start(0);
}

var stop=function() {
source.stop(0);
};
} else {
var audioDestination = new AudioDataDestination(sampleRate, requestSoundData);
var start=function() {
currentSoundSample = 0;
Expand All @@ -189,6 +214,7 @@ <h2>Demo:</h2>
var stop=function() {
frequency = 0;
};
}
var start_button=document.createElement("button");
start_button.innerHTML="Start playback";
start_button.onclick=start;
Expand Down