@@ -1419,24 +1419,24 @@ async function processAudio() {
14191419 throw new Error ( 'Cancelled' ) ;
14201420 }
14211421
1422+ const needsResample = result . audioBuffer . sampleRate !== parsedSampleRate ;
14221423 let exportBuffer = result . audioBuffer ;
1423- if ( exportBuffer . sampleRate !== parsedSampleRate ) {
1424- updateProgress ( 83 , `Resampling to ${ parsedSampleRate / 1000 } kHz...` ) ;
1425- let exportBuffer = result . audioBuffer ;
1426- if ( exportBuffer . sampleRate !== parsedSampleRate ) {
1424+ if ( needsResample ) {
14271425 updateProgress ( 86 , `Resampling to ${ parsedSampleRate / 1000 } kHz...` ) ;
14281426 exportBuffer = await resampleAudioBuffer ( exportBuffer , parsedSampleRate ) ;
14291427 }
14301428 if ( processingCancelled ) {
14311429 throw new Error ( 'Cancelled' ) ;
14321430 }
14331431
1434- updateProgress ( 88 , 'Encoding WAV...' ) ;
1432+ const encodeProgressStart = needsResample ? 86 : 85 ;
1433+ const encodeProgressSpan = needsResample ? 9 : 10 ;
1434+ updateProgress ( encodeProgressStart , 'Encoding WAV...' ) ;
14351435 // Yield so the UI can repaint before encoding begins.
14361436 await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
14371437
14381438 outputData = await encodeWAVAsync ( exportBuffer , parsedSampleRate , parsedBitDepth , {
1439- onProgress : ( p ) => updateProgress ( Math . round ( 88 + p * 10 ) , 'Encoding WAV...' ) ,
1439+ onProgress : ( p ) => updateProgress ( Math . round ( encodeProgressStart + p * encodeProgressSpan ) , 'Encoding WAV...' ) ,
14401440 shouldCancel : ( ) => processingCancelled
14411441 } ) ;
14421442 } catch ( workerErr ) {
0 commit comments