@@ -68,10 +68,17 @@ <h2>Demo:</h2>
6868pcm = [ ] ;
6969value = kjmp2_decode_frame ( mp2 , frame , pcm , l , r ) ;
7070if ( value ) {
71+ if ( ! ! ( window . AudioContext || window . webkitAudioContext ) ) {
72+ for ( var i = 0 ; i < l . length ; i ++ ) {
73+ lchannel . push ( l [ i ] ) ;
74+ rchannel . push ( r [ i ] ) ;
75+ } ;
76+ } else {
7177for ( var i = 0 ; i < l . length ; i ++ ) {
7278dec . push ( l [ i ] ) ;
7379dec . push ( r [ i ] ) ;
7480} ;
81+ }
7582frame = frame . subarray ( value ) ;
7683bytes_left -= value ;
7784t . innerHTML = "Bytes left to decode: " + bytes_left ;
@@ -106,6 +113,8 @@ <h2>Demo:</h2>
106113get_mp2 ( function ( ) {
107114s . parentNode . removeChild ( s ) ;
108115dec = [ ] ;
116+ lchannel = [ ] ;
117+ rchannel = [ ] ;
109118r = [ ] ;
110119l = [ ] ;
111120buffer = xhr . response ? xhr . response : xhr . mozResponseArrayBuffer ;
@@ -179,6 +188,22 @@ <h2>Demo:</h2>
179188} ;
180189 }
181190
191+ if ( ! ! ( window . AudioContext || window . webkitAudioContext ) ) {
192+ var context = new ( window . AudioContext || window . webkitAudioContext ) ( ) ;
193+ var sndbuffer = context . createBuffer ( 2 , lchannel . length + rchannel . length , sampleRate ) ;
194+ sndbuffer . copyToChannel ( new Float32Array ( lchannel ) , 0 , 0 ) ;
195+ sndbuffer . copyToChannel ( new Float32Array ( rchannel ) , 1 , 0 ) ;
196+ var source = context . createBufferSource ( ) ;
197+ source . buffer = sndbuffer ;
198+ source . connect ( context . destination ) ;
199+ var start = function ( ) {
200+ source . start ( 0 ) ;
201+ }
202+
203+ var stop = function ( ) {
204+ source . stop ( 0 ) ;
205+ } ;
206+ } else {
182207 var audioDestination = new AudioDataDestination ( sampleRate , requestSoundData ) ;
183208var start = function ( ) {
184209 currentSoundSample = 0 ;
@@ -189,6 +214,7 @@ <h2>Demo:</h2>
189214var stop = function ( ) {
190215 frequency = 0 ;
191216 } ;
217+ }
192218var start_button = document . createElement ( "button" ) ;
193219start_button . innerHTML = "Start playback" ;
194220start_button . onclick = start ;
0 commit comments