@@ -29,13 +29,12 @@ class Volume: StoreSubscriber {
2929 let device : AudioDevice ! = Application . selectedDevice
3030 let volumeSupported = device. outputVolumeSupported
3131 let balanceSupported = device. outputBalanceSupported
32-
32+ var virtualVolume : Double = 1
3333 if ( gain <= 1 ) {
3434 if ( volumeSupported) {
3535 device. setVirtualMasterVolume ( Float32 ( gain) , direction: . playback)
36- booster. globalGain = 0
3736 } else {
38- booster . globalGain = Float ( Utilities . mapValue ( value : gain, inMin : 0 , inMax : 1 , outMin : - 96 , outMax : 0 ) )
37+ virtualVolume = gain
3938 }
4039
4140 if ( balanceSupported) {
@@ -45,13 +44,13 @@ class Volume: StoreSubscriber {
4544 mixer. pan = Float ( balance)
4645 }
4746
47+ booster. globalGain = 0
4848 Driver . device!. setVirtualMasterVolume ( Float32 ( gain) , direction: . playback)
49-
5049 } else { // gain > 1
5150 if ( volumeSupported) {
5251 device. setVirtualMasterVolume ( 1.0 , direction: . playback)
5352 }
54- booster . globalGain = Float ( Utilities . mapValue ( value: gain, inMin: 1 , inMax: 2 , outMin: 0 , outMax: 12 ) )
53+ virtualVolume = Utilities . mapValue ( value: gain, inMin: 1 , inMax: 2 , outMin: 0 , outMax: 6 )
5554
5655 if ( balanceSupported) {
5756 device. setVirtualMasterBalance ( Float32 ( Utilities . mapValue ( value: balance, inMin: - 1 , inMax: 1 , outMin: 0 , outMax: 1 ) ) , direction: . playback)
@@ -63,7 +62,8 @@ class Volume: StoreSubscriber {
6362 Driver . device!. setVirtualMasterVolume ( 1 , direction: . playback)
6463 }
6564
66-
65+ mixer. outputVolume = Float ( virtualVolume)
66+
6767 if ( !volumeSupported) {
6868 Driver . device!. mute = false
6969 device. mute = false
@@ -77,16 +77,13 @@ class Volume: StoreSubscriber {
7777
7878 Application . ignoreNextVolumeEvent = false
7979 Application . ignoreNextDriverMuteEvent = false
80-
81- Console . log ( " Boost: \( booster. globalGain) Mix: \( mixer. pan) " )
8280 }
8381 }
8482
8583 var muted : Bool = false {
8684 didSet {
8785 if ( muted) {
88- // leftGain = 0
89- // rightGain = 0
86+ mixer. outputVolume = 0
9087 } else {
9188 ( gain = gain)
9289 }
@@ -169,12 +166,12 @@ class Volume: StoreSubscriber {
169166
170167 func attachToEngine ( engine: AVAudioEngine ) {
171168 self . engine = engine
172- let format = engine. inputNode . inputFormat ( forBus: 0 )
169+ let format = engine. outputNode . outputFormat ( forBus: 0 )
173170
174171 engine. attach ( booster)
175172 engine. attach ( mixer)
176173
177- engine. connect ( mixer , to: booster , format: format)
174+ engine. connect ( booster , to: mixer , format: format)
178175 }
179176
180177 func postSetup ( ) {
0 commit comments