1- import decode , { decodeStream } from './audio-decode.js' ;
1+ import decode from './audio-decode.js' ;
22import wav from 'audio-lena/wav' ;
33import mp3 from 'audio-lena/mp3' ;
44import ogg from 'audio-lena/ogg' ;
@@ -294,7 +294,7 @@ t('concurrent decoding', async () => {
294294} )
295295
296296t ( 'concurrent stream decoders' , async ( ) => {
297- let [ d1 , d2 ] = await Promise . all ( [ decode . mp3 . stream ( ) , decode . flac . stream ( ) ] )
297+ let [ d1 , d2 ] = await Promise . all ( [ decode . mp3 ( ) , decode . flac ( ) ] )
298298 let [ r1 , r2 ] = await Promise . all ( [
299299 d1 ( new Uint8Array ( mp3 ) ) ,
300300 d2 ( new Uint8Array ( flac ) ) ,
@@ -318,60 +318,60 @@ t('minimal invalid buffer', async () => {
318318 is ( threw , true )
319319} )
320320
321- // -- decodeStream --
321+ // -- chunked decode --
322322
323- t ( 'decodeStream mp3' , async ( ) => {
323+ t ( 'decode mp3' , async ( ) => {
324324 let chunks = [ new Uint8Array ( mp3 ) ]
325325 async function * gen ( ) { for ( let c of chunks ) yield c }
326326 let total = 0
327- for await ( let r of decodeStream ( gen ( ) , 'mp3' ) ) {
327+ for await ( let r of decode ( gen ( ) , 'mp3' ) ) {
328328 is ( r . sampleRate > 0 , true )
329329 total += r . channelData [ 0 ] . length
330330 }
331331 is ( total > 0 , true , 'decoded samples' )
332332} )
333333
334- t ( 'decodeStream ReadableStream' , async ( ) => {
334+ t ( 'decode ReadableStream' , async ( ) => {
335335 let data = new Uint8Array ( wav )
336336 let stream = new ReadableStream ( {
337337 start ( ctrl ) { ctrl . enqueue ( data ) ; ctrl . close ( ) }
338338 } )
339339 let total = 0
340- for await ( let r of decodeStream ( stream , 'wav' ) ) {
340+ for await ( let r of decode ( stream , 'wav' ) ) {
341341 is ( r . sampleRate , 44100 )
342342 total += r . channelData [ 0 ] . length
343343 }
344344 is ( total > 0 , true )
345345} )
346346
347- t ( 'decodeStream m4a' , async ( ) => {
347+ t ( 'decode m4a' , async ( ) => {
348348 async function * gen ( ) { yield new Uint8Array ( m4a ) }
349349 let total = 0
350- for await ( let r of decodeStream ( gen ( ) , 'm4a' ) ) {
350+ for await ( let r of decode ( gen ( ) , 'm4a' ) ) {
351351 is ( r . sampleRate , 44100 )
352352 total += r . channelData [ 0 ] . length
353353 }
354354 is ( total > 0 , true )
355355} )
356356
357- t ( 'decodeStream m4a chunked' , async ( ) => {
357+ t ( 'decode m4a chunked' , async ( ) => {
358358 // M4A needs full file (moov atom), so chunked streaming must buffer until flush
359359 let buf = new Uint8Array ( m4a ) , chunkSize = 16384
360360 async function * gen ( ) {
361361 for ( let off = 0 ; off < buf . length ; off += chunkSize )
362362 yield buf . subarray ( off , Math . min ( off + chunkSize , buf . length ) )
363363 }
364364 let total = 0
365- for await ( let r of decodeStream ( gen ( ) , 'm4a' ) ) {
365+ for await ( let r of decode ( gen ( ) , 'm4a' ) ) {
366366 total += r . channelData [ 0 ] . length
367367 }
368368 let ref = await decode ( m4a )
369369 is ( total , ref . channelData [ 0 ] . length , 'chunked M4A matches one-shot' )
370370} )
371371
372- t ( 'decodeStream unknown format' , async ( ) => {
372+ t ( 'decode unknown format' , async ( ) => {
373373 let threw = false
374- try { for await ( let _ of decodeStream ( [ ] , 'xyz' ) ) { } } catch { threw = true }
374+ try { for await ( let _ of decode ( [ ] , 'xyz' ) ) { } } catch { threw = true }
375375 is ( threw , true )
376376} )
377377
@@ -432,7 +432,7 @@ async function* chunked(buf, size = 4096) {
432432function streamTotal ( gen , fmt ) {
433433 return ( async ( ) => {
434434 let total = 0 , sr = 0
435- for await ( let r of decodeStream ( gen , fmt ) ) {
435+ for await ( let r of decode ( gen , fmt ) ) {
436436 sr = r . sampleRate ; total += r . channelData [ 0 ] . length
437437 }
438438 return { total, sr }
@@ -533,6 +533,6 @@ t('chunked stream tiny chunks wav', async () => {
533533t ( 'chunked stream yields multiple results' , async ( ) => {
534534 // verify streaming actually yields multiple chunks (not one big blob)
535535 let count = 0
536- for await ( let r of decodeStream ( chunked ( wav , 4096 ) , 'wav' ) ) count ++
536+ for await ( let r of decode ( chunked ( wav , 4096 ) , 'wav' ) ) count ++
537537 is ( count > 1 , true , 'multiple yields from stream' )
538538} )
0 commit comments