diff --git a/src/mixer/audio.ts b/src/mixer/audio.ts index 5107469..823d57f 100644 --- a/src/mixer/audio.ts +++ b/src/mixer/audio.ts @@ -67,12 +67,24 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) { setVolume(val: number) { this.volume = val; - this.wavesurfer.setVolume(this.volume * this.trim); + this._applyVolume(); } setTrim(val: number) { this.trim = val; - this.wavesurfer.setVolume(this.volume * this.trim); + this._applyVolume(); + } + + _applyVolume() { + const level = this.volume * (this.trim === 0 ? 1 : this.trim); + const linear = Math.pow(10, (level/10)); + if (linear < 1) { + this.wavesurfer.setVolume(linear); + (this.wavesurfer as any).backend.gainNode.gain.value = 1; + } else { + this.wavesurfer.setVolume(1); + (this.wavesurfer as any).backend.gainNode.gain.value = linear; + } } public static create(engine: AudioEngine, player: number, url: string) { diff --git a/src/mixer/state.ts b/src/mixer/state.ts index 48dd9b9..973b0f6 100644 --- a/src/mixer/state.ts +++ b/src/mixer/state.ts @@ -64,7 +64,7 @@ const BasePlayerState: PlayerState = { state: "stopped", volume: 1, gain: 1, - trim: 1, + trim: 0, timeCurrent: 0, timeRemaining: 0, timeLength: 0, diff --git a/src/optionsMenu/ProModeTab.tsx b/src/optionsMenu/ProModeTab.tsx index 2022253..9220be4 100644 --- a/src/optionsMenu/ProModeTab.tsx +++ b/src/optionsMenu/ProModeTab.tsx @@ -1,6 +1,4 @@ -import React, { useState, useRef, useEffect, useCallback } from "react"; -import { streamer } from "../broadcast/state"; -import { WebRTCStreamer } from "../broadcast/rtc_streamer"; +import React from "react"; import {useDispatch, useSelector} from "react-redux"; import {RootState} from "../rootReducer"; import {changeSetting} from "./settingsState"; diff --git a/src/showplanner/Player.tsx b/src/showplanner/Player.tsx index 1a43085..aeb19a3 100644 --- a/src/showplanner/Player.tsx +++ b/src/showplanner/Player.tsx @@ -7,7 +7,6 @@ import { FaPlay, FaPause, FaStop, - FaTachometerAlt } from "react-icons/fa"; import { RootState } from "../rootReducer"; import * as MixerState from "../mixer/state"; diff --git a/src/showplanner/ProModeButtons.tsx b/src/showplanner/ProModeButtons.tsx index 400ed22..a62270b 100644 --- a/src/showplanner/ProModeButtons.tsx +++ b/src/showplanner/ProModeButtons.tsx @@ -21,7 +21,7 @@ export default function ProModeButtons({channel}: { channel: number }) { )} {activeButton === "trim" && ( <> - dispatch(setChannelTrim(channel, parseFloat(e.target.value)))}/> {trimVal}