@@ -90,7 +90,11 @@ export function SoundTouchPlayground({
9090 const pitchSemitonesListId = `${ idPrefix } -pitch-semitones` ;
9191
9292 const ensureGraph = async ( ) : Promise < void > => {
93- if ( audioContextRef . current && soundTouchNodeRef . current && gainNodeRef . current ) {
93+ if (
94+ audioContextRef . current &&
95+ soundTouchNodeRef . current &&
96+ gainNodeRef . current
97+ ) {
9498 return ;
9599 }
96100
@@ -118,7 +122,8 @@ export function SoundTouchPlayground({
118122 if ( sourceMode === 'buffer' ) {
119123 const response = await fetch ( track . url ) ;
120124 const arrayBuffer = await response . arrayBuffer ( ) ;
121- audioBufferRef . current = await audioContextRef . current ! . decodeAudioData ( arrayBuffer ) ;
125+ audioBufferRef . current =
126+ await audioContextRef . current ! . decodeAudioData ( arrayBuffer ) ;
122127 setDuration ( audioBufferRef . current . duration ) ;
123128 setCurrentTime ( 0 ) ;
124129 sourceOffsetRef . current = 0 ;
@@ -136,9 +141,8 @@ export function SoundTouchPlayground({
136141 elementRef . current . playbackRate = rate ;
137142
138143 if ( ! elementSourceNodeRef . current ) {
139- elementSourceNodeRef . current = audioContextRef . current ! . createMediaElementSource (
140- elementRef . current ,
141- ) ;
144+ elementSourceNodeRef . current =
145+ audioContextRef . current ! . createMediaElementSource ( elementRef . current ) ;
142146 elementSourceNodeRef . current . connect ( soundTouchNodeRef . current ! ) ;
143147 }
144148
@@ -198,8 +202,12 @@ export function SoundTouchPlayground({
198202 if ( sourceMode === 'buffer' ) {
199203 const elapsed =
200204 sourceOffsetRef . current +
201- ( audioContextRef . current ! . currentTime - startAtContextTimeRef . current ) * rate ;
202- const next = loopEnabled && duration > 0 ? elapsed % duration : Math . min ( elapsed , duration ) ;
205+ ( audioContextRef . current ! . currentTime - startAtContextTimeRef . current ) *
206+ rate ;
207+ const next =
208+ loopEnabled && duration > 0
209+ ? elapsed % duration
210+ : Math . min ( elapsed , duration ) ;
203211 setCurrentTime ( next ) ;
204212 if ( ! loopEnabled && elapsed >= duration ) {
205213 setIsPlaying ( false ) ;
@@ -262,7 +270,8 @@ export function SoundTouchPlayground({
262270 setStatus ( 'Playing' ) ;
263271 rafIdRef . current = window . requestAnimationFrame ( tick ) ;
264272 } catch ( error ) {
265- const message = error instanceof Error ? error . message : 'Unknown audio error' ;
273+ const message =
274+ error instanceof Error ? error . message : 'Unknown audio error' ;
266275 setStatus ( `Error: ${ message } ` ) ;
267276 }
268277 } ;
@@ -271,7 +280,9 @@ export function SoundTouchPlayground({
271280 if ( sourceMode === 'buffer' ) {
272281 if ( isPlaying ) {
273282 sourceOffsetRef . current +=
274- ( audioContextRef . current ! . currentTime - startAtContextTimeRef . current ) * rate ;
283+ ( audioContextRef . current ! . currentTime -
284+ startAtContextTimeRef . current ) *
285+ rate ;
275286 }
276287 if ( duration > 0 ) {
277288 sourceOffsetRef . current = loopEnabled
@@ -294,7 +305,10 @@ export function SoundTouchPlayground({
294305 }
295306
296307 const bounds = event . currentTarget . getBoundingClientRect ( ) ;
297- const ratio = Math . min ( 1 , Math . max ( 0 , ( event . clientX - bounds . left ) / bounds . width ) ) ;
308+ const ratio = Math . min (
309+ 1 ,
310+ Math . max ( 0 , ( event . clientX - bounds . left ) / bounds . width ) ,
311+ ) ;
298312 const nextTime = ratio * duration ;
299313
300314 if ( sourceMode === 'buffer' ) {
@@ -355,18 +369,40 @@ export function SoundTouchPlayground({
355369 } , [ ] ) ;
356370
357371 return (
358- < div style = { { fontFamily : 'ui-sans-serif, system-ui, sans-serif' , padding : '1rem' , maxWidth : 920 } } >
372+ < div
373+ style = { {
374+ fontFamily : 'ui-sans-serif, system-ui, sans-serif' ,
375+ padding : '1rem' ,
376+ maxWidth : 920 ,
377+ } }
378+ >
359379 < h3 style = { { marginTop : 0 } } > { title } </ h3 >
360380 < p style = { { marginTop : 0 , color : '#4b5563' } } >
361- Source: < strong > { sourceMode === 'buffer' ? 'Manual buffer load' : 'HTML audio element' } </ strong > | Buffer:
381+ Source:{ ' ' }
382+ < strong >
383+ { sourceMode === 'buffer'
384+ ? 'Manual buffer load'
385+ : 'HTML audio element' }
386+ </ strong > { ' ' }
387+ | Buffer:
362388 < strong > { sampleBufferType } </ strong > | Interpolation:
363389 < strong > { interpolationStrategy } </ strong >
364390 </ p >
365391
366- < div style = { { display : 'grid' , gap : '0.75rem' , gridTemplateColumns : 'repeat(auto-fit,minmax(240px,1fr))' } } >
392+ < div
393+ style = { {
394+ display : 'grid' ,
395+ gap : '0.75rem' ,
396+ gridTemplateColumns : 'repeat(auto-fit,minmax(240px,1fr))' ,
397+ } }
398+ >
367399 < label >
368400 Track
369- < select value = { selectedTrackId } onChange = { onTrackChange } style = { { display : 'block' , width : '100%' } } >
401+ < select
402+ value = { selectedTrackId }
403+ onChange = { onTrackChange }
404+ style = { { display : 'block' , width : '100%' } }
405+ >
370406 { TRACKS . map ( ( item ) => (
371407 < option key = { item . id } value = { item . id } >
372408 { item . label }
@@ -499,11 +535,22 @@ export function SoundTouchPlayground({
499535 </ label >
500536 </ div >
501537
502- < div style = { { display : 'flex' , gap : '0.5rem' , marginTop : '1rem' , flexWrap : 'wrap' } } >
538+ < div
539+ style = { {
540+ display : 'flex' ,
541+ gap : '0.5rem' ,
542+ marginTop : '1rem' ,
543+ flexWrap : 'wrap' ,
544+ } }
545+ >
503546 < button type = "button" onClick = { ( ) => void loadTrack ( ) } >
504547 Load
505548 </ button >
506- < button type = "button" onClick = { ( ) => void startPlayback ( ) } disabled = { isPlaying } >
549+ < button
550+ type = "button"
551+ onClick = { ( ) => void startPlayback ( ) }
552+ disabled = { isPlaying }
553+ >
507554 Play
508555 </ button >
509556 < button type = "button" onClick = { stopPlayback } disabled = { ! isPlaying } >
@@ -518,13 +565,22 @@ export function SoundTouchPlayground({
518565 onClick = { handleSeek }
519566 style = { { width : '100%' , cursor : 'pointer' } }
520567 />
521- < div style = { { display : 'flex' , justifyContent : 'space-between' , marginTop : '0.25rem' , fontSize : '0.9rem' } } >
568+ < div
569+ style = { {
570+ display : 'flex' ,
571+ justifyContent : 'space-between' ,
572+ marginTop : '0.25rem' ,
573+ fontSize : '0.9rem' ,
574+ } }
575+ >
522576 < span > { formatTime ( currentTime ) } </ span >
523577 < span > { formatTime ( duration ) } </ span >
524578 </ div >
525579 </ div >
526580
527- < p style = { { marginBottom : 0 , marginTop : '0.75rem' , color : '#374151' } } > { status } </ p >
581+ < p style = { { marginBottom : 0 , marginTop : '0.75rem' , color : '#374151' } } >
582+ { status }
583+ </ p >
528584 </ div >
529585 ) ;
530586}
0 commit comments