Improved background performance when voice is muted
Signed-off-by: WolverinDEV <git@teaspeak.de>
This commit is contained in:
parent
90ee270547
commit
98a1e628ee
2 changed files with 53 additions and 11 deletions
|
@ -651,6 +651,8 @@ class ConnectionHandler {
|
||||||
property_update["client_input_hardware"] = false;
|
property_update["client_input_hardware"] = false;
|
||||||
property_update["client_output_hardware"] = false;
|
property_update["client_output_hardware"] = false;
|
||||||
this.client_status.input_hardware = true; /* IDK if we have input hardware or not, but it dosn't matter at all so */
|
this.client_status.input_hardware = true; /* IDK if we have input hardware or not, but it dosn't matter at all so */
|
||||||
|
|
||||||
|
/* no icons are shown so no update at all */
|
||||||
} else {
|
} else {
|
||||||
const audio_source = vconnection.voice_recorder();
|
const audio_source = vconnection.voice_recorder();
|
||||||
const recording_supported = typeof(audio_source) !== "undefined" && audio_source.record_supported && (!targetChannel || vconnection.encoding_supported(targetChannel.properties.channel_codec));
|
const recording_supported = typeof(audio_source) !== "undefined" && audio_source.record_supported && (!targetChannel || vconnection.encoding_supported(targetChannel.properties.channel_codec));
|
||||||
|
@ -659,9 +661,8 @@ class ConnectionHandler {
|
||||||
property_update["client_input_hardware"] = recording_supported;
|
property_update["client_input_hardware"] = recording_supported;
|
||||||
property_update["client_output_hardware"] = playback_supported;
|
property_update["client_output_hardware"] = playback_supported;
|
||||||
this.client_status.input_hardware = recording_supported;
|
this.client_status.input_hardware = recording_supported;
|
||||||
}
|
|
||||||
|
|
||||||
if(this.serverConnection && this.serverConnection.connected()) {
|
/* update icons */
|
||||||
const client_properties = this.getClient().properties;
|
const client_properties = this.getClient().properties;
|
||||||
for(const key of Object.keys(property_update)) {
|
for(const key of Object.keys(property_update)) {
|
||||||
if(client_properties[key] === property_update[key])
|
if(client_properties[key] === property_update[key])
|
||||||
|
@ -680,10 +681,10 @@ class ConnectionHandler {
|
||||||
this.getClient().updateVariables(...updates);
|
this.getClient().updateVariables(...updates);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else { /* no icons are shown so no update at all */ }
|
}
|
||||||
|
|
||||||
|
|
||||||
if(targetChannel && (!vconnection || vconnection.connected())) {
|
if(targetChannel && basic_voice_support) {
|
||||||
const encoding_supported = vconnection && vconnection.encoding_supported(targetChannel.properties.channel_codec);
|
const encoding_supported = vconnection && vconnection.encoding_supported(targetChannel.properties.channel_codec);
|
||||||
const decoding_supported = vconnection && vconnection.decoding_supported(targetChannel.properties.channel_codec);
|
const decoding_supported = vconnection && vconnection.decoding_supported(targetChannel.properties.channel_codec);
|
||||||
|
|
||||||
|
|
|
@ -89,9 +89,14 @@ namespace audio {
|
||||||
active: boolean = false; /* if true the filter filters! */
|
active: boolean = false; /* if true the filter filters! */
|
||||||
callback_active_change: (new_state: boolean) => any;
|
callback_active_change: (new_state: boolean) => any;
|
||||||
|
|
||||||
|
paused: boolean = true;
|
||||||
|
|
||||||
abstract initialize(context: AudioContext, source_node: AudioNode);
|
abstract initialize(context: AudioContext, source_node: AudioNode);
|
||||||
abstract finalize();
|
abstract finalize();
|
||||||
|
|
||||||
|
/* whatever the input has been paused and we don't expect any input */
|
||||||
|
abstract set_pause(flag: boolean);
|
||||||
|
|
||||||
is_enabled(): boolean {
|
is_enabled(): boolean {
|
||||||
return this.enabled;
|
return this.enabled;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +122,7 @@ namespace audio {
|
||||||
private _smooth_attack = 0;
|
private _smooth_attack = 0;
|
||||||
|
|
||||||
finalize() {
|
finalize() {
|
||||||
clearInterval(this._update_task);
|
this.set_pause(true);
|
||||||
this._update_task = 0;
|
|
||||||
|
|
||||||
if(this.source_node) {
|
if(this.source_node) {
|
||||||
try { this.source_node.disconnect(this._analyser) } catch (error) {}
|
try { this.source_node.disconnect(this._analyser) } catch (error) {}
|
||||||
|
@ -147,10 +151,12 @@ namespace audio {
|
||||||
|
|
||||||
this.active = false;
|
this.active = false;
|
||||||
this.audio_node.gain.value = 1;
|
this.audio_node.gain.value = 1;
|
||||||
this._update_task = setInterval(() => this._analyse(), JThresholdFilter.update_task_interval);
|
|
||||||
|
|
||||||
this.source_node.connect(this.audio_node);
|
this.source_node.connect(this.audio_node);
|
||||||
this.source_node.connect(this._analyser);
|
this.source_node.connect(this._analyser);
|
||||||
|
|
||||||
|
/* force update paused state */
|
||||||
|
this.set_pause(!(this.paused = !this.paused));
|
||||||
}
|
}
|
||||||
|
|
||||||
get_margin_frames(): number { return this._margin_frames; }
|
get_margin_frames(): number { return this._margin_frames; }
|
||||||
|
@ -174,8 +180,6 @@ namespace audio {
|
||||||
this._smooth_release = value;
|
this._smooth_release = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get_threshold(): number {
|
get_threshold(): number {
|
||||||
return this._threshold;
|
return this._threshold;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +226,7 @@ namespace audio {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _update_gain_node() {
|
private _update_gain_node() {
|
||||||
let state = false;
|
let state;
|
||||||
if(this._current_level > this._threshold) {
|
if(this._current_level > this._threshold) {
|
||||||
this._silence_count = 0;
|
this._silence_count = 0;
|
||||||
state = true;
|
state = true;
|
||||||
|
@ -243,6 +247,24 @@ namespace audio {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_pause(flag: boolean) {
|
||||||
|
if(flag === this.paused) return;
|
||||||
|
this.paused = flag;
|
||||||
|
|
||||||
|
if(this.paused) {
|
||||||
|
clearInterval(this._update_task);
|
||||||
|
this._update_task = undefined;
|
||||||
|
|
||||||
|
if(this.active) {
|
||||||
|
this.active = false;
|
||||||
|
this.callback_active_change(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(!this._update_task && this._analyser)
|
||||||
|
this._update_task = setInterval(() => this._analyse(), JThresholdFilter.update_task_interval);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class JStateFilter extends JAbstractFilter<GainNode> implements StateFilter {
|
export class JStateFilter extends JAbstractFilter<GainNode> implements StateFilter {
|
||||||
|
@ -282,6 +304,10 @@ namespace audio {
|
||||||
this.callback_active_change(state);
|
this.callback_active_change(state);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_pause(flag: boolean) {
|
||||||
|
this.paused = flag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,6 +322,7 @@ namespace audio {
|
||||||
private _audio_context: AudioContext;
|
private _audio_context: AudioContext;
|
||||||
private _source_node: AudioNode; /* last node which could be connected to the target; target might be the _consumer_node */
|
private _source_node: AudioNode; /* last node which could be connected to the target; target might be the _consumer_node */
|
||||||
private _consumer_callback_node: ScriptProcessorNode;
|
private _consumer_callback_node: ScriptProcessorNode;
|
||||||
|
private readonly _consumer_audio_callback;
|
||||||
private _volume_node: GainNode;
|
private _volume_node: GainNode;
|
||||||
private _mute_node: GainNode;
|
private _mute_node: GainNode;
|
||||||
|
|
||||||
|
@ -309,6 +336,7 @@ namespace audio {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
player.on_ready(() => this._audio_initialized());
|
player.on_ready(() => this._audio_initialized());
|
||||||
|
this._consumer_audio_callback = this._audio_callback.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _audio_initialized() {
|
private _audio_initialized() {
|
||||||
|
@ -321,12 +349,12 @@ namespace audio {
|
||||||
this._mute_node.connect(this._audio_context.destination);
|
this._mute_node.connect(this._audio_context.destination);
|
||||||
|
|
||||||
this._consumer_callback_node = this._audio_context.createScriptProcessor(1024 * 4);
|
this._consumer_callback_node = this._audio_context.createScriptProcessor(1024 * 4);
|
||||||
this._consumer_callback_node.addEventListener('audioprocess', event => this._audio_callback(event));
|
|
||||||
this._consumer_callback_node.connect(this._mute_node);
|
this._consumer_callback_node.connect(this._mute_node);
|
||||||
|
|
||||||
this._volume_node = this._audio_context.createGain();
|
this._volume_node = this._audio_context.createGain();
|
||||||
this._volume_node.gain.value = this._volume;
|
this._volume_node.gain.value = this._volume;
|
||||||
|
|
||||||
|
this._initialize_filters();
|
||||||
if(this._state === InputState.INITIALIZING)
|
if(this._state === InputState.INITIALIZING)
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
|
@ -453,6 +481,11 @@ namespace audio {
|
||||||
}
|
}
|
||||||
this._current_stream = _result;
|
this._current_stream = _result;
|
||||||
|
|
||||||
|
for(const f of this._filters)
|
||||||
|
if(f.is_enabled() && f instanceof filter.JAbstractFilter)
|
||||||
|
f.set_pause(false);
|
||||||
|
this._consumer_callback_node.addEventListener('audioprocess', this._consumer_audio_callback);
|
||||||
|
|
||||||
this._current_audio_stream = this._audio_context.createMediaStreamSource(this._current_stream);
|
this._current_audio_stream = this._audio_context.createMediaStreamSource(this._current_stream);
|
||||||
this._current_audio_stream.connect(this._volume_node);
|
this._current_audio_stream.connect(this._volume_node);
|
||||||
this._state = InputState.RECORDING;
|
this._state = InputState.RECORDING;
|
||||||
|
@ -489,6 +522,11 @@ namespace audio {
|
||||||
|
|
||||||
this._current_stream = undefined;
|
this._current_stream = undefined;
|
||||||
this._current_audio_stream = undefined;
|
this._current_audio_stream = undefined;
|
||||||
|
for(const f of this._filters)
|
||||||
|
if(f.is_enabled() && f instanceof filter.JAbstractFilter)
|
||||||
|
f.set_pause(true);
|
||||||
|
if(this._consumer_callback_node)
|
||||||
|
this._consumer_callback_node.removeEventListener('audioprocess', this._consumer_audio_callback);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,6 +611,7 @@ namespace audio {
|
||||||
for(const _filter of this._filters) {
|
for(const _filter of this._filters) {
|
||||||
if(!_filter.is_enabled())
|
if(!_filter.is_enabled())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const c_filter = _filter as any as filter.JAbstractFilter<AudioNode>;
|
const c_filter = _filter as any as filter.JAbstractFilter<AudioNode>;
|
||||||
c_filter.finalize();
|
c_filter.finalize();
|
||||||
c_filter.enabled = false;
|
c_filter.enabled = false;
|
||||||
|
@ -591,6 +630,7 @@ namespace audio {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
filter.enabled = false;
|
filter.enabled = false;
|
||||||
|
filter.set_pause(true);
|
||||||
filter.finalize();
|
filter.finalize();
|
||||||
this._initialize_filters();
|
this._initialize_filters();
|
||||||
this._recalculate_filter_status();
|
this._recalculate_filter_status();
|
||||||
|
@ -602,6 +642,7 @@ namespace audio {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
filter.enabled = true;
|
filter.enabled = true;
|
||||||
|
filter.set_pause(typeof this._current_audio_stream !== "object");
|
||||||
this._initialize_filters();
|
this._initialize_filters();
|
||||||
this._recalculate_filter_status();
|
this._recalculate_filter_status();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue