|
1 /* |
|
2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Manipulates the settings of an audio effect called reverb. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cammsreverbcontrol.h" |
|
21 #include <RoomLevelBase.h> |
|
22 #include <logger.h> |
|
23 |
|
24 #ifdef _DEBUG |
|
25 // CONSTANTS |
|
26 const TInt KAMMSMaxReverbLevel = 0; |
|
27 const TInt KAMMSMinReverbTime = 0; |
|
28 #endif // _DEBUG |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CAMMSReverbControl::NewLC |
|
34 // Two-phased constructor. |
|
35 // ----------------------------------------------------------------------------- |
|
36 CAMMSReverbControl* CAMMSReverbControl::NewLC(CMMAPlayer* aPlayer) |
|
37 { |
|
38 CAMMSReverbControl* self = new(ELeave) CAMMSReverbControl(aPlayer); |
|
39 |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(); |
|
42 |
|
43 return self; |
|
44 } |
|
45 |
|
46 // Destructor |
|
47 CAMMSReverbControl::~CAMMSReverbControl() |
|
48 { |
|
49 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::~CAMMSReverbControl"); |
|
50 |
|
51 // Perform DeallocateControl, if the state change has not yet performed it. |
|
52 DeallocateControl(); |
|
53 delete iReverbUtility; |
|
54 delete iPresetNames; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CAMMSReverbControl::SetReverbLevelL |
|
59 // Sets the gain level of the reverberation. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 TInt CAMMSReverbControl::SetReverbLevelL(TInt aLevel) |
|
63 { |
|
64 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetReverbLevelL: %d", aLevel); |
|
65 |
|
66 // Check in debug build that aLevel is within valid range. |
|
67 __ASSERT_DEBUG(aLevel <= KAMMSMaxReverbLevel, User::Invariant()); |
|
68 |
|
69 CEnvironmentalReverb* reverbEffect = (CEnvironmentalReverb*)iAudioEffect; |
|
70 |
|
71 TInt roomLevel = reverbEffect->RoomLevel(); |
|
72 TInt tempChange = aLevel - reverbEffect->ReflectionsLevel() - roomLevel; |
|
73 |
|
74 // Sets the reverb reflections level in mB |
|
75 reverbEffect->SetReflectionsLevelL(aLevel - roomLevel); |
|
76 |
|
77 |
|
78 // Calculate native reverb level. |
|
79 TInt reverbLevel = reverbEffect->ReverbLevel() + tempChange; |
|
80 |
|
81 // Ensure that the level is within the limits. |
|
82 |
|
83 TInt32 minLevel = 0; |
|
84 TInt32 maxLevel = 0; |
|
85 reverbEffect->ReverbLevelRange(minLevel, maxLevel); |
|
86 |
|
87 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetReverbLevelL: orig %d", |
|
88 reverbLevel); |
|
89 |
|
90 reverbLevel = Min(reverbLevel, maxLevel); |
|
91 reverbLevel = Max(reverbLevel, minLevel); |
|
92 |
|
93 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetReverbLevelL: set %d", |
|
94 reverbLevel); |
|
95 |
|
96 // Sets the reverb level in mB |
|
97 reverbEffect->SetReverbLevelL(reverbLevel); |
|
98 |
|
99 // Apply can be called for Reverb, as it does not internally include EnableL |
|
100 // unlike in case of Equalizer or StereoWidening |
|
101 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetReverbLevelL calling ApplyL"); |
|
102 reverbEffect->ApplyL(); |
|
103 |
|
104 // Return the value that was used in setting the reverb |
|
105 return aLevel; |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CAMMSReverbControl::SetReverbTimeL |
|
110 // Sets the reverberation time of the reverb. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CAMMSReverbControl::SetReverbTimeL(TInt aTime) |
|
114 { |
|
115 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetReverbTimeL: %d", aTime); |
|
116 |
|
117 // Check in debug build that aTime is within valid range. |
|
118 __ASSERT_DEBUG(aTime >= KAMMSMinReverbTime, User::Invariant()); |
|
119 |
|
120 // Sets the decay time in milliseconds |
|
121 ((CEnvironmentalReverb*)iAudioEffect)->SetDecayTimeL(aTime); |
|
122 |
|
123 // Apply can be called for Reverb, as it does not internally include EnableL |
|
124 // unlike in case of Equalizer or StereoWidening |
|
125 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetReverbTimeL calling ApplyL"); |
|
126 iAudioEffect->ApplyL(); |
|
127 |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CAMMSReverbControl::ReverbLevel |
|
132 // Gets the gain level of the reverberation. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 TInt CAMMSReverbControl::ReverbLevel() |
|
136 { |
|
137 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::ReverbLevel called"); |
|
138 // Return here (reflections level + room level) |
|
139 return (((CEnvironmentalReverb*)iAudioEffect)->ReflectionsLevel() + |
|
140 ((CEnvironmentalReverb*)iAudioEffect)->RoomLevel()); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CAMMSReverbControl::ReverbTime |
|
145 // Gets the reverberation time. |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 TInt CAMMSReverbControl::ReverbTime() |
|
149 { |
|
150 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::ReverbTime called"); |
|
151 |
|
152 return (((CEnvironmentalReverb*)iAudioEffect)->DecayTime()); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CAMMSReverbControl::MinReverbLevel |
|
157 // Gets the minimum level of the reverberation. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 TInt CAMMSReverbControl::MinReverbLevel() |
|
161 { |
|
162 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::MinReverbLevel called"); |
|
163 |
|
164 TInt32 minLevel; |
|
165 TInt32 maxLevel; |
|
166 ((CEnvironmentalReverb*)iAudioEffect)->ReverbLevelRange( |
|
167 minLevel, maxLevel); |
|
168 |
|
169 return minLevel; |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CAMMSReverbControl::MaxReverbLevel |
|
174 // Gets the maximum level of the reverberation. |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TInt CAMMSReverbControl::MaxReverbLevel() |
|
178 { |
|
179 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::MaxReverbLevel called"); |
|
180 |
|
181 TInt32 minLevel; |
|
182 TInt32 maxLevel; |
|
183 ((CEnvironmentalReverb*)iAudioEffect)->ReverbLevelRange( |
|
184 minLevel, maxLevel); |
|
185 |
|
186 return maxLevel; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CAMMSReverbControl::CurrentPresetIndex |
|
191 // Gets current preset index. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 TInt CAMMSReverbControl::CurrentPresetIndex() |
|
195 { |
|
196 return iCurrentPreset; |
|
197 } |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CAMMSReverbControl::SetPresetL |
|
200 // Sets the effect according to the given preset. |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CAMMSReverbControl::SetPresetL(const TDesC& aPreset) |
|
204 { |
|
205 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetPresetL \"%S\"", aPreset.Ptr()); |
|
206 |
|
207 const CDesCArray& presetNames = PresetNamesL(); |
|
208 |
|
209 TInt presetPosition = 0; |
|
210 TInt findPreset = presetNames.Find(aPreset, presetPosition); |
|
211 if (findPreset == 0) // Find returns zero, if a matching element is found. |
|
212 { |
|
213 // This supposes that the indexing of the presets starts at zero. |
|
214 iReverbUtility->GetPresetL(presetPosition); |
|
215 |
|
216 // Set the base class audio effect as the new CEnvironmentalReverb |
|
217 // that is set with the previous GetPresetL method. |
|
218 iAudioEffect = &(iReverbUtility->EnvironmentalReverb()); |
|
219 iCurrentPreset = presetPosition; |
|
220 |
|
221 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetPresetL \"%S\" GetPresetL OK", |
|
222 aPreset.Ptr()); |
|
223 } |
|
224 else |
|
225 { |
|
226 User::Leave(KErrArgument); |
|
227 } |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CAMMSReverbControl::PresetNamesL |
|
232 // Gets the available preset names. |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 const CDesCArray& CAMMSReverbControl::PresetNamesL() |
|
236 { |
|
237 // Returns an array of all preset names (pre-defined and user-defined). |
|
238 // The pre-defined presets are in the beginning of the list. |
|
239 TArray< TEfEnvironmentalReverbUtilityPreset > presetNames = |
|
240 iReverbUtility->Presets(); |
|
241 |
|
242 // Before appending the preset names, reset the member array |
|
243 iPresetNames->Reset(); |
|
244 for (TInt i = 0; i < presetNames.Count(); i++) |
|
245 { |
|
246 iPresetNames->AppendL(presetNames[ i ].iPresetName); |
|
247 } |
|
248 |
|
249 return *iPresetNames; |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CAMMSReverbControl::PresetL |
|
254 // Gets the current preset. |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 const TDesC& CAMMSReverbControl::PresetL() |
|
258 { |
|
259 //if no preset is set, return null |
|
260 if (iCurrentPreset < 0) |
|
261 { |
|
262 return KNullDesC; |
|
263 } |
|
264 else |
|
265 { |
|
266 // Retrieves a Preset with the given index from the Central Repository |
|
267 return iReverbUtility->GetPresetL(iCurrentPreset); |
|
268 } |
|
269 } |
|
270 |
|
271 |
|
272 // ----------------------------------------------------------------------------- |
|
273 // CAMMSReverbControl::SetEnabledL |
|
274 // Enables/disables the effect. |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 void CAMMSReverbControl::SetEnabledL(TBool aEnable) |
|
278 { |
|
279 if (aEnable) |
|
280 { |
|
281 // Enable the effect |
|
282 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetEnabledL(true), calling EnableL"); |
|
283 iAudioEffect->EnableL(); |
|
284 } |
|
285 else |
|
286 { |
|
287 // Disable the effect |
|
288 // Instead of using CAudioEffectBase: virtual void DisableL(), |
|
289 // use the utility class DisableEnvironmentalReverbL, |
|
290 // which calls DisableL for the correct preset |
|
291 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::SetEnabledL(false), calling DisableEnvironmentalReverbL"); |
|
292 iReverbUtility->DisableEnvironmentalReverbL(); |
|
293 } |
|
294 } |
|
295 |
|
296 // ----------------------------------------------------------------------------- |
|
297 // CAMMSReverbControl::PrepareControlL |
|
298 // Function which is called after the correct state is set in Player. |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 void CAMMSReverbControl::PrepareControlL() |
|
302 { |
|
303 // Perform the action only for the first time, skip if called afterwards |
|
304 if (!iReverbUtility) |
|
305 { |
|
306 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::PrepareControlL"); |
|
307 |
|
308 CCustomCommandUtility* customCommandUtility = |
|
309 CreateCustomCommandUtilityL(); |
|
310 |
|
311 // Effect API takes the ownership of customCommandUtility. |
|
312 iReverbUtility = CEnvironmentalReverbUtility::NewL( |
|
313 customCommandUtility); |
|
314 |
|
315 SetPresetL(KAMMSDefaultReverbPreset); |
|
316 } |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CAMMSReverbControl::DeallocateControl |
|
321 // Function which is called after the correct state is set in Player. |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 void CAMMSReverbControl::DeallocateControl() |
|
325 { |
|
326 if (iReverbUtility) |
|
327 { |
|
328 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::DeallocateControlL"); |
|
329 |
|
330 // Delete the Effect API class. |
|
331 TRAPD(err, iReverbUtility->DisableEnvironmentalReverbL()); |
|
332 if (err != KErrNone) |
|
333 { |
|
334 // The only even theoritically possible error code here would be |
|
335 // KErrAccessDenied which is a result from Effect API calling ApplyL |
|
336 // method without having update rights, but since the Utility |
|
337 // class is already created, that situation can be discarded here. |
|
338 } |
|
339 |
|
340 delete iReverbUtility; |
|
341 iReverbUtility = NULL; |
|
342 |
|
343 // Set current preset to a negative value to state it has not been set |
|
344 iCurrentPreset = -1; |
|
345 } |
|
346 } |
|
347 |
|
348 // ----------------------------------------------------------------------------- |
|
349 // CAMMSReverbControl::GetEnvironmentalReverbUtilityL |
|
350 // Returns the environmental reverb utility. |
|
351 // ----------------------------------------------------------------------------- |
|
352 void CAMMSReverbControl::GetEnvironmentalReverbUtilityL( |
|
353 CEnvironmentalReverbUtility** aEnvironmentalReverbUtility) |
|
354 { |
|
355 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::GetEnvironmentalReverbUtilityL"); |
|
356 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSReverbControl::GetEnvironmentalReverbUtilityL CurrentPreset = %d",CurrentPresetIndex()); |
|
357 *aEnvironmentalReverbUtility = iReverbUtility; |
|
358 } |
|
359 |
|
360 const TDesC& CAMMSReverbControl::ClassName() const |
|
361 { |
|
362 return KAMMSReverbControl; |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CAMMSReverbControl::ConstructL |
|
367 // Symbian 2nd phase constructor can leave. |
|
368 // ----------------------------------------------------------------------------- |
|
369 void CAMMSReverbControl::ConstructL() |
|
370 { |
|
371 // Create array for preset names |
|
372 iPresetNames = new(ELeave) CDesCArrayFlat(1); |
|
373 |
|
374 // Set current preset to a negative value as it is not set yet |
|
375 iCurrentPreset = -1; |
|
376 |
|
377 CAMMSEffectControl::ConstructL(); |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CAMMSReverbControl::CAMMSReverbControl |
|
382 // C++ default constructor can NOT contain any code, that |
|
383 // might leave. |
|
384 // ----------------------------------------------------------------------------- |
|
385 CAMMSReverbControl::CAMMSReverbControl(CMMAPlayer* aPlayer) |
|
386 : CAMMSBaseReverbControl(aPlayer) |
|
387 { |
|
388 } |
|
389 |
|
390 // End of File |