use a GainNode for volume control instead of custom code, thus improving

the feedback
This commit is contained in:
Jakob Ketterl 2019-10-19 12:58:09 +02:00
parent a102ee181a
commit 72329a8a2a

View File

@ -108,7 +108,7 @@ function style_value(of_what, which) {
} }
function updateVolume() { function updateVolume() {
volume = parseFloat(e("openwebrx-panel-volume").value) / 100; gainNode.gain.value = parseFloat(e("openwebrx-panel-volume").value) / 100;
} }
function toggleMute() { function toggleMute() {
@ -1519,7 +1519,7 @@ function divlog(what, is_error) {
var audio_context; var audio_context;
var audio_initialized = 0; var audio_initialized = 0;
var volume = 1.0; var gainNode;
var volumeBeforeMute = 100.0; var volumeBeforeMute = 100.0;
var mute = false; var mute = false;
@ -1536,13 +1536,6 @@ var audio_flush_interval_ms = 500; //the interval in which audio_flush() is call
var audio_buffers = []; var audio_buffers = [];
var audio_last_output_buffer; var audio_last_output_buffer;
function gain_ff(gain_value, data) //great! solved clicking! will have to move to sdr.js
{
for (var i = 0; i < data.length; i++)
data[i] *= gain_value;
return data;
}
function audio_prepare(data) { function audio_prepare(data) {
if (!audio_node) return; if (!audio_node) return;
var buffer = data; var buffer = data;
@ -1550,7 +1543,7 @@ function audio_prepare(data) {
//resampling & ADPCM //resampling & ADPCM
buffer = audio_codec.decode(buffer); buffer = audio_codec.decode(buffer);
} }
buffer = audio_resampler.process(gain_ff(volume, sdrjs.ConvertI16_F(buffer))); buffer = audio_resampler.process(sdrjs.ConvertI16_F(buffer));
if (audio_node.port) { if (audio_node.port) {
// AudioWorklets supported // AudioWorklets supported
audio_node.port.postMessage(buffer, [buffer.buffer]); audio_node.port.postMessage(buffer, [buffer.buffer]);
@ -1717,6 +1710,8 @@ function audio_init() {
audio_initialized = 1; // only tell on_ws_recv() not to call it again audio_initialized = 1; // only tell on_ws_recv() not to call it again
var tech; var tech;
gainNode = audio_context.createGain();
gainNode.connect(audio_context.destination);
if (audio_context.audioWorklet) { if (audio_context.audioWorklet) {
tech = "AudioWorklet"; tech = "AudioWorklet";
audio_context.audioWorklet.addModule('static/lib/AudioProcessor.js').then(function(){ audio_context.audioWorklet.addModule('static/lib/AudioProcessor.js').then(function(){
@ -1729,7 +1724,7 @@ function audio_init() {
reduceToLength: audio_buffer_decrease_to_on_overrun_sec reduceToLength: audio_buffer_decrease_to_on_overrun_sec
} }
}); });
audio_node.connect(audio_context.destination); audio_node.connect(gainNode);
window.setInterval(function(){ window.setInterval(function(){
audio_node.port.postMessage(JSON.stringify({cmd:'getBuffers'})); audio_node.port.postMessage(JSON.stringify({cmd:'getBuffers'}));
}, audio_flush_interval_ms); }, audio_flush_interval_ms);
@ -1748,10 +1743,13 @@ function audio_init() {
var createjsnode_function = (audio_context.createJavaScriptNode === undefined) ? audio_context.createScriptProcessor.bind(audio_context) : audio_context.createJavaScriptNode.bind(audio_context); var createjsnode_function = (audio_context.createJavaScriptNode === undefined) ? audio_context.createScriptProcessor.bind(audio_context) : audio_context.createJavaScriptNode.bind(audio_context);
audio_node = createjsnode_function(audio_buffer_size, 0, 1); audio_node = createjsnode_function(audio_buffer_size, 0, 1);
audio_node.onaudioprocess = audio_onprocess; audio_node.onaudioprocess = audio_onprocess;
audio_node.connect(audio_context.destination); audio_node.connect(gainNode);
window.setInterval(audio_flush, audio_flush_interval_ms); window.setInterval(audio_flush, audio_flush_interval_ms);
} }
//Synchronise volume with slider
updateVolume();
// --- Resampling --- // --- Resampling ---
//https://github.com/grantgalitz/XAudioJS/blob/master/XAudioServer.js //https://github.com/grantgalitz/XAudioJS/blob/master/XAudioServer.js
//audio_resampler = new Resampler(audio_received_sample_rate, audio_context.sampleRate, 1, audio_buffer_size, true); //audio_resampler = new Resampler(audio_received_sample_rate, audio_context.sampleRate, 1, audio_buffer_size, true);
@ -2200,9 +2198,6 @@ function openwebrx_init() {
init_header(); init_header();
bookmarks = new BookmarkBar(); bookmarks = new BookmarkBar();
//Synchronise volume with slider
updateVolume();
} }
function digimodes_init() { function digimodes_init() {