mirror of
https://github.com/koel/koel
synced 2024-11-28 23:10:27 +00:00
Fix equalizer by using new audio API
This commit is contained in:
parent
566e2067b5
commit
fe79e53558
1 changed files with 8 additions and 6 deletions
|
@ -34,6 +34,8 @@ import nouislider from 'nouislider'
|
||||||
import { isAudioContextSupported, event, $ } from '@/utils'
|
import { isAudioContextSupported, event, $ } from '@/utils'
|
||||||
import { equalizerStore, preferenceStore as preferences } from '@/stores'
|
import { equalizerStore, preferenceStore as preferences } from '@/stores'
|
||||||
|
|
||||||
|
let context
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
@ -86,7 +88,7 @@ export default {
|
||||||
window.oAudioContext ||
|
window.oAudioContext ||
|
||||||
window.msAudioContext
|
window.msAudioContext
|
||||||
|
|
||||||
const context = new AudioContext()
|
context = new AudioContext()
|
||||||
|
|
||||||
this.preampGainNode = context.createGain()
|
this.preampGainNode = context.createGain()
|
||||||
this.changePreampGain(settings.preamp)
|
this.changePreampGain(settings.preamp)
|
||||||
|
@ -109,9 +111,9 @@ export default {
|
||||||
filter.type = 'peaking'
|
filter.type = 'peaking'
|
||||||
}
|
}
|
||||||
|
|
||||||
filter.gain.value = settings.gains[i] ? settings.gains[i] : 0
|
filter.gain.setTargetAtTime(settings[i] || 0, context.currentTime, .01)
|
||||||
filter.Q.value = 1
|
filter.Q.setTargetAtTime(1, context.currentTime, .01)
|
||||||
filter.frequency.value = frequency
|
filter.frequency.setTargetAtTime(frequency, context.currentTime, .01)
|
||||||
|
|
||||||
prevFilter ? prevFilter.connect(filter) : this.preampGainNode.connect(filter)
|
prevFilter ? prevFilter.connect(filter) : this.preampGainNode.connect(filter)
|
||||||
prevFilter = filter
|
prevFilter = filter
|
||||||
|
@ -175,7 +177,7 @@ export default {
|
||||||
*/
|
*/
|
||||||
changePreampGain (dbValue) {
|
changePreampGain (dbValue) {
|
||||||
this.preampGainValue = dbValue
|
this.preampGainValue = dbValue
|
||||||
this.preampGainNode.gain.value = Math.pow(10, dbValue / 20)
|
this.preampGainNode.gain.setTargetAtTime(Math.pow(10, dbValue / 20), context.currentTime, .01)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,7 +187,7 @@ export default {
|
||||||
* @param {Object} value Value of the gain, in dB.
|
* @param {Object} value Value of the gain, in dB.
|
||||||
*/
|
*/
|
||||||
changeFilterGain (filter, value) {
|
changeFilterGain (filter, value) {
|
||||||
filter.gain.value = value
|
filter.gain.setTargetAtTime(value, context.currentTime, .01)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue