Trim in decibels instead of wacko-units

This commit is contained in:
Marks Polakovs 2020-05-09 16:25:14 +02:00
parent 3510840227
commit 66abc19412
5 changed files with 17 additions and 8 deletions

View file

@ -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) {

View file

@ -64,7 +64,7 @@ const BasePlayerState: PlayerState = {
state: "stopped",
volume: 1,
gain: 1,
trim: 1,
trim: 0,
timeCurrent: 0,
timeRemaining: 0,
timeLength: 0,

View file

@ -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";

View file

@ -7,7 +7,6 @@ import {
FaPlay,
FaPause,
FaStop,
FaTachometerAlt
} from "react-icons/fa";
import { RootState } from "../rootReducer";
import * as MixerState from "../mixer/state";

View file

@ -21,7 +21,7 @@ export default function ProModeButtons({channel}: { channel: number }) {
)}
{activeButton === "trim" && (
<>
<input type="range" min={0.01} max={5} step={0.2} value={trimVal.toFixed(1)}
<input type="range" min={-12} max={12} step={0.2} value={trimVal.toFixed(1)}
onChange={e => dispatch(setChannelTrim(channel, parseFloat(e.target.value)))}/>
<b>{trimVal}</b>
</>