Allow enabling/disabling of mic processing.
This commit is contained in:
parent
b79a67686d
commit
6b03054b59
3 changed files with 43 additions and 10 deletions
|
@ -336,10 +336,9 @@ export class AudioEngine extends ((EngineEmitter as unknown) as {
|
|||
this.micMixGain = this.audioContext.createGain();
|
||||
this.micMixGain.gain.value = 1;
|
||||
|
||||
this.micCalibrationGain.connect(this.micPrecompAnalyser);
|
||||
this.micCalibrationGain
|
||||
.connect(this.micCompressor)
|
||||
.connect(this.micMixGain)
|
||||
// We run setMicProcessingEnabled() later to either patch to the compressor, or bypass it to the mixGain node.
|
||||
this.micCompressor.connect(this.micMixGain);
|
||||
this.micMixGain
|
||||
.connect(this.micFinalAnalyser)
|
||||
// we don't run the mic into masterAnalyser to ensure it doesn't go to audioContext.destination
|
||||
.connect(this.streamingAnalyser);
|
||||
|
@ -449,6 +448,18 @@ export class AudioEngine extends ((EngineEmitter as unknown) as {
|
|||
this.micMixGain.gain.value = value;
|
||||
}
|
||||
|
||||
setMicProcessingEnabled(value: boolean) {
|
||||
// Disconnect whatever was connected before.
|
||||
this.micCalibrationGain.disconnect();
|
||||
this.micCalibrationGain.connect(this.micPrecompAnalyser);
|
||||
console.log("Setting mic processing to: ", value);
|
||||
if (value) {
|
||||
this.micCalibrationGain.connect(this.micCompressor);
|
||||
} else {
|
||||
this.micCalibrationGain.connect(this.micMixGain);
|
||||
}
|
||||
}
|
||||
|
||||
getLevels(source: LevelsSource, stereo: boolean): [number, number] {
|
||||
switch (source) {
|
||||
case "mic-precomp":
|
||||
|
|
|
@ -53,6 +53,7 @@ interface MicState {
|
|||
volume: 1 | 0;
|
||||
baseGain: number;
|
||||
id: string | null;
|
||||
processing: boolean;
|
||||
}
|
||||
|
||||
interface MixerState {
|
||||
|
@ -88,6 +89,7 @@ const mixerState = createSlice({
|
|||
baseGain: 0,
|
||||
openError: null,
|
||||
id: "None",
|
||||
processing: true,
|
||||
},
|
||||
} as MixerState,
|
||||
reducers: {
|
||||
|
@ -210,6 +212,9 @@ const mixerState = createSlice({
|
|||
setMicBaseGain(state, action: PayloadAction<number>) {
|
||||
state.mic.baseGain = action.payload;
|
||||
},
|
||||
setMicProcessingEnabled(state, action: PayloadAction<boolean>) {
|
||||
state.mic.processing = action.payload;
|
||||
},
|
||||
setTimeCurrent(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
|
@ -695,11 +700,6 @@ export const openMicrophone = (
|
|||
micID: string,
|
||||
micMapping: ChannelMapping
|
||||
): AppThunk => async (dispatch, getState) => {
|
||||
// TODO: not sure why this is here, and I have a hunch it may break shit, so disabling
|
||||
// File a ticket if it breaks stuff. -Marks
|
||||
// if (getState().mixer.mic.open) {
|
||||
// micSource?.disconnect();
|
||||
// }
|
||||
if (audioEngine.audioContext.state !== "running") {
|
||||
console.log("Resuming AudioContext because Chrome bad");
|
||||
await audioEngine.audioContext.resume();
|
||||
|
@ -730,10 +730,19 @@ export const openMicrophone = (
|
|||
const state = getState().mixer.mic;
|
||||
audioEngine.setMicCalibrationGain(state.baseGain);
|
||||
audioEngine.setMicVolume(state.volume);
|
||||
|
||||
// Now to patch in the Mic to the Compressor, or Bypass it.
|
||||
audioEngine.setMicProcessingEnabled(state.processing);
|
||||
dispatch(mixerState.actions.micOpen(micID));
|
||||
};
|
||||
|
||||
export const setMicProcessingEnabled = (enabled: boolean): AppThunk => async (
|
||||
dispatch,
|
||||
_
|
||||
) => {
|
||||
dispatch(mixerState.actions.setMicProcessingEnabled(enabled));
|
||||
audioEngine.setMicProcessingEnabled(enabled);
|
||||
};
|
||||
|
||||
export const setMicVolume = (level: MicVolumePresetEnum): AppThunk => (
|
||||
dispatch
|
||||
) => {
|
||||
|
|
|
@ -132,6 +132,19 @@ export function MicTab() {
|
|||
<option value={"stereo-normal"} label="Stereo" />
|
||||
<option value={"stereo-flipped"} label="Stereo - Flipped" />
|
||||
</select>
|
||||
<div className="form-check">
|
||||
<input
|
||||
className="form-check-input"
|
||||
type="checkbox"
|
||||
checked={state.processing}
|
||||
onChange={(e) => {
|
||||
dispatch(MixerState.setMicProcessingEnabled(e.target.checked));
|
||||
}}
|
||||
/>
|
||||
<label className="form-check-label">
|
||||
Apply Mic Processing (Default: On)
|
||||
</label>
|
||||
</div>
|
||||
<hr />
|
||||
<div style={{ opacity: state.open ? 1 : 0.5 }}>
|
||||
<h3>Calibration</h3>
|
||||
|
|
Loading…
Reference in a new issue