|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Lesser General Public License |
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
|
17 */ |
|
18 |
|
19 #include <EnvironmentalReverbBase.h> |
|
20 #include "environmentalreverb.h" |
|
21 |
|
22 QT_BEGIN_NAMESPACE |
|
23 |
|
24 using namespace Phonon; |
|
25 using namespace Phonon::MMF; |
|
26 |
|
27 /*! \class MMF::EnvironmentalReverb |
|
28 \internal |
|
29 */ |
|
30 |
|
31 // Define functions which depend on concrete native effect class name |
|
32 PHONON_MMF_DEFINE_EFFECT_FUNCTIONS(EnvironmentalReverb) |
|
33 |
|
34 enum Parameters |
|
35 { |
|
36 DecayHFRatio = AbstractAudioEffect::ParameterBase, |
|
37 DecayTime, |
|
38 Density, |
|
39 Diffusion, |
|
40 ReflectionsDelay, |
|
41 ReflectionsLevel, |
|
42 ReverbDelay, |
|
43 ReverbLevel, |
|
44 RoomHFLevel, |
|
45 RoomLevel |
|
46 }; |
|
47 |
|
48 EnvironmentalReverb::EnvironmentalReverb(QObject *parent, const QList<EffectParameter>& parameters) |
|
49 : AbstractAudioEffect::AbstractAudioEffect(parent, parameters) |
|
50 { |
|
51 |
|
52 } |
|
53 |
|
54 int EnvironmentalReverb::effectParameterChanged(const EffectParameter ¶m, |
|
55 const QVariant &value) |
|
56 { |
|
57 const qreal externalLevel = value.toReal(); |
|
58 const int internalLevel = param.toInternalValue(externalLevel); |
|
59 |
|
60 TInt err = 0; |
|
61 |
|
62 switch(param.id()) { |
|
63 case DecayHFRatio: |
|
64 TRAP(err, concreteEffect()->SetDecayHFRatioL(internalLevel)); |
|
65 break; |
|
66 case DecayTime: |
|
67 TRAP(err, concreteEffect()->SetDecayTimeL(internalLevel)); |
|
68 break; |
|
69 case Density: |
|
70 TRAP(err, concreteEffect()->SetDensityL(internalLevel)); |
|
71 break; |
|
72 case Diffusion: |
|
73 TRAP(err, concreteEffect()->SetDiffusionL(internalLevel)); |
|
74 break; |
|
75 case ReflectionsDelay: |
|
76 TRAP(err, concreteEffect()->SetReflectionsDelayL(internalLevel)); |
|
77 break; |
|
78 case ReflectionsLevel: |
|
79 TRAP(err, concreteEffect()->SetReflectionsLevelL(internalLevel)); |
|
80 break; |
|
81 case ReverbDelay: |
|
82 TRAP(err, concreteEffect()->SetReverbDelayL(internalLevel)); |
|
83 break; |
|
84 case ReverbLevel: |
|
85 TRAP(err, concreteEffect()->SetReverbLevelL(internalLevel)); |
|
86 break; |
|
87 case RoomHFLevel: |
|
88 TRAP(err, concreteEffect()->SetRoomHFLevelL(internalLevel)); |
|
89 break; |
|
90 case RoomLevel: |
|
91 TRAP(err, concreteEffect()->SetRoomLevelL(internalLevel)); |
|
92 break; |
|
93 default: |
|
94 Q_ASSERT_X(false, Q_FUNC_INFO, "Unknown parameter"); |
|
95 } |
|
96 |
|
97 return err; |
|
98 } |
|
99 |
|
100 |
|
101 //----------------------------------------------------------------------------- |
|
102 // Static functions |
|
103 //----------------------------------------------------------------------------- |
|
104 |
|
105 const char* EnvironmentalReverb::description() |
|
106 { |
|
107 return "Reverb"; |
|
108 } |
|
109 |
|
110 // Internal helper function |
|
111 Phonon::MMF::EffectParameter createParameter(int id, const QString &name, |
|
112 int defaultValue, int minValue, int maxValue, |
|
113 Phonon::EffectParameter::Hint hint = Phonon::EffectParameter::IntegerHint) |
|
114 { |
|
115 const qreal externalDefaultValue = |
|
116 Phonon::MMF::EffectParameter::toExternalValue |
|
117 (defaultValue, minValue, maxValue); |
|
118 |
|
119 Phonon::MMF::EffectParameter param(id, name, hint, |
|
120 /* defaultValue */ QVariant(externalDefaultValue), |
|
121 /* minimumValue */ QVariant(qreal(-1.0)), |
|
122 /* maximumValue */ QVariant(qreal(+1.0))); |
|
123 |
|
124 param.setInternalRange(minValue, maxValue); |
|
125 return param; |
|
126 } |
|
127 |
|
128 bool EnvironmentalReverb::getParameters(CMdaAudioOutputStream *stream, |
|
129 QList<EffectParameter>& parameters) |
|
130 { |
|
131 bool supported = false; |
|
132 |
|
133 QScopedPointer<CEnvironmentalReverb> effect; |
|
134 TRAPD(err, effect.reset(CEnvironmentalReverb::NewL(*stream))); |
|
135 |
|
136 if (KErrNone == err) { |
|
137 supported = true; |
|
138 |
|
139 TInt32 min, max; |
|
140 TUint32 umin, umax; |
|
141 |
|
142 // DecayHFRatio |
|
143 effect->DecayHFRatioRange(umin, umax); |
|
144 parameters.append(createParameter( |
|
145 DecayHFRatio, tr("Decay HF ratio (%)"), effect->DecayHFRatio(), |
|
146 umin, umax)); |
|
147 |
|
148 // DecayTime |
|
149 effect->DecayTimeRange(umin, umax); |
|
150 parameters.append(createParameter( |
|
151 DecayTime, tr("Decay time (ms)"), effect->DecayTime(), |
|
152 umin, umax)); |
|
153 |
|
154 // Density |
|
155 parameters.append(createParameter( |
|
156 Density, tr("Density (%)"), effect->Density(), 0, 100)); |
|
157 |
|
158 // Diffusion |
|
159 parameters.append(createParameter( |
|
160 Diffusion, tr("Diffusion (%)"), effect->Diffusion(), 0, 100)); |
|
161 |
|
162 // ReflectionsDelay |
|
163 parameters.append(createParameter( |
|
164 ReflectionsDelay, tr("Reflections delay (ms)"), |
|
165 effect->ReflectionsDelay(), 0, effect->ReflectionsDelayMax())); |
|
166 |
|
167 // ReflectionsLevel |
|
168 effect->ReflectionLevelRange(min, max); |
|
169 parameters.append(createParameter( |
|
170 ReflectionsLevel, tr("Reflections level (mB)"), |
|
171 effect->ReflectionsLevel(), |
|
172 min, max, EffectParameter::LogarithmicHint)); |
|
173 |
|
174 // ReverbDelay |
|
175 parameters.append(createParameter( |
|
176 ReverbDelay, tr("Reverb delay (ms)"), effect->ReverbDelay(), |
|
177 0, effect->ReverbDelayMax())); |
|
178 |
|
179 // ReverbLevel |
|
180 effect->ReverbLevelRange(min, max); |
|
181 parameters.append(createParameter( |
|
182 ReverbLevel, tr("Reverb level (mB)"), effect->ReverbLevel(), |
|
183 min, max, EffectParameter::LogarithmicHint)); |
|
184 |
|
185 // RoomHFLevel |
|
186 effect->RoomHFLevelRange(min, max); |
|
187 parameters.append(createParameter( |
|
188 RoomHFLevel, tr("Room HF level"), effect->RoomHFLevel(), |
|
189 min, max)); |
|
190 |
|
191 // RoomLevel |
|
192 effect->RoomLevelRange(min, max); |
|
193 parameters.append(createParameter( |
|
194 RoomLevel, tr("Room level (mB)"), effect->RoomLevel(), |
|
195 min, max, EffectParameter::LogarithmicHint)); |
|
196 } |
|
197 |
|
198 return supported; |
|
199 } |
|
200 |
|
201 QT_END_NAMESPACE |