Skip to content

Commit

Permalink
Use accurate scale for audio mixer render
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Sep 29, 2024
1 parent 70c275e commit 6ec0781
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions chrome/player/ui/audio/AudioChannelMixer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,13 @@ export class AudioChannelMixer extends AbstractAudioModule {

ctx.clearRect(0, 0, width, height);

const minDB = -40;
const maxDB = 40;
const dbRange = maxDB - minDB;
const lastVolume = analyzer._lastVolume || 0;
const volume = Math.max((Utils.clamp(AudioUtils.getVolume(analyzer), minDB, maxDB) - minDB) / dbRange, lastVolume * 0.95);
const lastVolume = analyzer._lastVolume !== undefined ? analyzer._lastVolume : -Infinity;
const newvolume = AudioUtils.getVolume(analyzer);
const volume = Math.max(newvolume, lastVolume - 0.5);
analyzer._lastVolume = volume;
const yScale = height;

const rectHeight = height / 50;
const volHeight = volume * yScale;

const rectCount = Math.round(volHeight / rectHeight);
const rectCount = Math.round((1 - AudioUtils.mixerDBToPositionRatio(volume)) * 50);
const now = Date.now();

if (!els.peak || rectCount > els.peak) {
Expand Down

0 comments on commit 6ec0781

Please sign in to comment.