1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #ifndef __JFXMedia__AVFSoundLevelUnit__
27 #define __JFXMedia__AVFSoundLevelUnit__
28
29 #include <AudioUnit/AudioUnit.h>
30 #include <Accelerate/Accelerate.h>
31 #include "AVFKernelProcessor.h"
32 #include "AUEffectBase.h"
33
34 #define kDefaultSoundLevelParam_Volume 1.0f
35 #define kDefaultSoundLevelParam_Balance 0.0f
36
37 /*
38 * This unit applies the volume/balance controls.
39 */
40 class AVFSoundLevelUnit : public AVFKernelProcessor {
41 public:
42 AVFSoundLevelUnit() :
43 AVFKernelProcessor(),
44 mVolume(kDefaultSoundLevelParam_Volume),
45 mBalance(kDefaultSoundLevelParam_Balance)
46 {}
47
48 virtual ~AVFSoundLevelUnit() {}
49
50 virtual AUKernelBase *NewKernel();
79 Float32 balance = mBalance;
80 Float32 level = volume;
81
82 if (channelCount == 2) {
83 // balance is only done on stereo audio
84 if (((balance < 0.0) && channelNum == 1) ||
85 ((balance > 0.0) && channelNum == 0)) {
86 // attenuate according to balance
87 balance = 1.0 - fabsf(balance);
88 level *= balance; // invert so it ramps the right direction
89 }
90 }
91 return level;
92 }
93
94 private:
95 Float32 mVolume;
96 Float32 mBalance;
97 };
98
99 #endif /* defined(__JFXMedia__AVFSoundLevelUnit__) */
|
1 /*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #ifndef __JFXMedia__AVFSoundLevelUnit__
27 #define __JFXMedia__AVFSoundLevelUnit__
28
29 #include <AudioUnit/AudioUnit.h>
30 #include <Accelerate/Accelerate.h>
31
32 #include <memory>
33
34 #include "AVFKernelProcessor.h"
35 #include "AUEffectBase.h"
36
37 #define kDefaultSoundLevelParam_Volume 1.0f
38 #define kDefaultSoundLevelParam_Balance 0.0f
39
40 /*
41 * This unit applies the volume/balance controls.
42 */
43 class AVFSoundLevelUnit : public AVFKernelProcessor {
44 public:
45 AVFSoundLevelUnit() :
46 AVFKernelProcessor(),
47 mVolume(kDefaultSoundLevelParam_Volume),
48 mBalance(kDefaultSoundLevelParam_Balance)
49 {}
50
51 virtual ~AVFSoundLevelUnit() {}
52
53 virtual AUKernelBase *NewKernel();
82 Float32 balance = mBalance;
83 Float32 level = volume;
84
85 if (channelCount == 2) {
86 // balance is only done on stereo audio
87 if (((balance < 0.0) && channelNum == 1) ||
88 ((balance > 0.0) && channelNum == 0)) {
89 // attenuate according to balance
90 balance = 1.0 - fabsf(balance);
91 level *= balance; // invert so it ramps the right direction
92 }
93 }
94 return level;
95 }
96
97 private:
98 Float32 mVolume;
99 Float32 mBalance;
100 };
101
102 typedef std::shared_ptr<AVFSoundLevelUnit> AVFSoundLevelUnitPtr;
103
104 #endif /* defined(__JFXMedia__AVFSoundLevelUnit__) */
|