Browse Source

Disable audio equalizer and fix some audio device selection bugs

reviewable/pr209/r1
Samuel Attard 6 years ago
parent
commit
95c9474046
  1. 104
      src/inject/GPMInject/playback/audioEQ.js
  2. 11
      src/inject/GPMInject/playback/audioSelection.js
  3. 13
      src/inject/settings/audioSelection.js
  4. 2
      src/inject/settings/index.js
  5. 1
      src/main/features/core/tray.js
  6. 5
      src/public_html/desktop_settings.html

104
src/inject/GPMInject/playback/audioEQ.js

@ -16,11 +16,9 @@ window.wait(() => {
if (device.label === Settings.get('audiooutput')) {
set = true;
let once = true;
console.log('Found Device');
document.querySelector('audio').addEventListener('playing', () => {
if (!once) return;
once = false;
console.log('Play Start');
setAudioDevice(device.deviceId)
.then(resolve);
});
@ -31,56 +29,58 @@ window.wait(() => {
})
.then(() => {
// TODO: Uncomment this so that the equalizer works
const context = new AudioContext();
window.audioFilterContext = context;
const mediaElement = document.querySelector('audio');
const sourceNode = context.createMediaElementSource(mediaElement);
window.audioSourceNode = sourceNode;
const GAIN_DB = -40.0;
// These are the EQ levels that the android EQ uses
const BAND_SPLITS = [60, 230, 910, 4000, 14000];
const bands = [];
const sum = context.createGain();
const mBand = context.createGain();
BAND_SPLITS.forEach((UPPER_BAND, index) => {
const band = context.createBiquadFilter();
band.type = (index !== BAND_SPLITS.length - 1 ? 'highshelf' : 'lowshelf');
band.frequency.value = UPPER_BAND;
band.gain.value = GAIN_DB;
const invert = context.createGain();
invert.gain.value = -1.0;
sourceNode.connect(band);
band.connect(invert);
invert.connect(mBand);
const gain = context.createGain();
band.connect(gain);
gain.connect(sum);
bands.push(gain);
});
sourceNode.connect(mBand);
const mGain = context.createGain();
mBand.connect(mGain);
mGain.connect(sum);
sum.connect(context.destination);
// TODO: remove
window.bands = bands;
window.mBand = mBand;
Emitter.on('eq:change', (event, details) => {
bands[details.index].gain.value = details.value;
});
// DEV: This doesn't work with audio selection so let's disable it
// const context = new AudioContext();
// window.audioFilterContext = context;
// const mediaElement = document.querySelector('audio');
// const sourceNode = context.createMediaElementSource(mediaElement);
// window.audioSourceNode = sourceNode;
//
// const GAIN_DB = -40.0;
// // These are the EQ levels that the android EQ uses
// const BAND_SPLITS = [60, 230, 910, 4000, 14000];
//
// const bands = [];
//
// const sum = context.createGain();
// const mBand = context.createGain();
//
// BAND_SPLITS.forEach((UPPER_BAND, index) => {
// const band = context.createBiquadFilter();
// band.type = (index !== BAND_SPLITS.length - 1 ? 'highshelf' : 'lowshelf');
// band.frequency.value = UPPER_BAND;
// band.gain.value = GAIN_DB;
//
// const invert = context.createGain();
// invert.gain.value = -1.0;
// sourceNode.connect(band);
// band.connect(invert);
// invert.connect(mBand);
//
// const gain = context.createGain();
// band.connect(gain);
// gain.connect(sum);
//
// gain.gain.value = Settings.get('eq', [1, 1, 1, 1, 1, 1])[bands.length];
// bands.push(gain);
// });
//
// sourceNode.connect(mBand);
//
// const mGain = context.createGain();
// mBand.connect(mGain);
//
// mGain.connect(sum);
//
// sum.connect(context.destination);
//
// // TODO: remove
// window.bands = bands;
// window.mBand = mBand;
//
// Emitter.on('eq:change', (event, details) => {
// bands[details.index].gain.value = details.value;
// });
});
}
}, 10);

11
src/inject/GPMInject/playback/audioSelection.js

@ -22,5 +22,14 @@ export const setAudioDevice = (id, count = 0) => {
};
Emitter.on('audiooutput:set', (event, deviceId) => {
setAudioDevice(deviceId);
let once = true;
if (document.querySelector('audio').paused) {
document.querySelector('audio').addEventListener('playing', () => {
if (!once) return;
once = false;
setAudioDevice(deviceId);
});
} else {
setAudioDevice(deviceId);
}
});

13
src/inject/settings/audioSelection.js

@ -43,3 +43,16 @@ $('#audioOutputSelect').on('change', (e) => {
}).label;
Emitter.fire('audiooutput:set', label);
});
let currentSelected = Settings.get('audiooutput');
setInterval(() => {
if (currentSelected !== Settings.get('audiooutput')) {
currentSelected = Settings.get('audiooutput');
$('#audioOutputSelect option').each((index, opt) => {
if ($(opt).text() === currentSelected) {
$('#audioOutputSelect').val($(opt).attr('value'));
$('#audioOutputSelect').material_select();
}
});
}
}, 500);

2
src/inject/settings/index.js

@ -1,6 +1,6 @@
import './themeSettings';
import './audioSelection';
import './audioEQ';
// import './audioEQ';
import './hotkeys';
import './tray';
import './lastFM';

1
src/main/features/core/tray.js

@ -78,3 +78,4 @@ Emitter.on('audiooutput:list', (event, devices) => {
});
Emitter.sendToGooglePlayMusic('audiooutput:fetch');
Emitter.on('audiooutput:set', () => Emitter.sendToGooglePlayMusic('audiooutput:fetch'));

5
src/public_html/desktop_settings.html

@ -132,14 +132,15 @@
<select id="audioOutputSelect"></select>
<label>Audio Output Device</label>
</div>
<div class="input-field col s12" style="margin-top: 0">
<!-- This doesn't work with audio selection so let's disable it -->
<!--<div class="input-field col s12" style="margin-top: 0">
<span>Equalizer <a class="waves-effect waves-light btn reset-eq" style="position:absolute;right:0;top:-8px">Reset</a></span>
<div class="eq-slide-con"><label>60Hz</label><div class="eq-slide"></div></div>
<div class="eq-slide-con"><label>230Hz</label><div class="eq-slide"></div></div>
<div class="eq-slide-con"><label>910Hz</label><div class="eq-slide"></div></div>
<div class="eq-slide-con"><label>4kHz</label><div class="eq-slide"></div></div>
<div class="eq-slide-con"><label>14kHz</label><div class="eq-slide"></div></div>
</div>
</div>-->
</div>
</div>
</div>

Loading…
Cancel
Save