@@ -37,11 +37,13 @@ const WAVEFORM_SAMPLE_STEP = 0.1;
3737const WAVEFORM_CONTROL_STEP = 0.05 ;
3838const WAVEFORM_PADDING_SECONDS = 0.3 ;
3939
40+ const WAVEFORM_MUTE_DB = - 30 ;
41+
4042function gainToScale ( gain ?: number ) {
4143 if ( ! Number . isFinite ( gain ) ) return 1 ;
4244 const value = gain as number ;
43- if ( value <= WAVEFORM_MIN_DB ) return 0 ;
44- return Math . max ( 0 , 1 + value / - WAVEFORM_MIN_DB ) ;
45+ if ( value <= WAVEFORM_MUTE_DB ) return 0 ;
46+ return Math . max ( 0 , ( value - WAVEFORM_MUTE_DB ) / - WAVEFORM_MUTE_DB ) ;
4547}
4648
4749const MAX_WAVEFORM_SAMPLES = 6000 ;
@@ -202,7 +204,10 @@ function WaveformCanvas(props: {
202204 } ;
203205 }
204206
205- const renderKey = `${ canvasWidth } -${ renderSegment . start . toFixed ( 2 ) } -${ renderSegment . end . toFixed ( 2 ) } ` ;
207+ const micScale = gainToScale ( project . audio . micVolumeDb ) ;
208+ const systemScale = gainToScale ( project . audio . systemVolumeDb ) ;
209+
210+ const renderKey = `${ canvasWidth } -${ renderSegment . start . toFixed ( 2 ) } -${ renderSegment . end . toFixed ( 2 ) } -${ micScale . toFixed ( 2 ) } -${ systemScale . toFixed ( 2 ) } ` ;
206211 if ( renderKey === lastRenderKey ) {
207212 return ;
208213 }
@@ -230,10 +235,8 @@ function WaveformCanvas(props: {
230235 const scale = gainToScale ( gain ) ;
231236 if ( scale <= 0 ) return ;
232237 ctx . save ( ) ;
233- ctx . translate ( 0 , - 1 ) ;
234- ctx . scale ( 1 , scale ) ;
235- ctx . translate ( 0 , 1 ) ;
236- ctx . scale ( canvasWidth , canvasHeight ) ;
238+ ctx . translate ( 0 , canvasHeight * ( 1 - scale ) ) ;
239+ ctx . scale ( canvasWidth , canvasHeight * scale ) ;
237240 ctx . fillStyle = color ;
238241 ctx . fill ( path ) ;
239242 ctx . restore ( ) ;
@@ -436,7 +439,7 @@ export function ClipTrack(
436439 const systemAudioWaveform = ( ) => {
437440 if (
438441 project . audio . systemVolumeDb &&
439- project . audio . systemVolumeDb <= - 30
442+ project . audio . systemVolumeDb < - 30
440443 )
441444 return ;
442445
0 commit comments