|
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 "cammsemcreverbcontrol.h" |
|
21 #include <RoomLevelBase.h> |
|
22 #include <logger.h> |
|
23 #ifdef _DEBUG |
|
24 // CONSTANTS |
|
25 const TInt KAMMSMaxReverbLevel = 0; |
|
26 const TInt KAMMSMinReverbTime = 0; |
|
27 #endif // _DEBUG |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CAMMSEMCReverbControl::NewLC |
|
33 // Two-phased constructor. |
|
34 // ----------------------------------------------------------------------------- |
|
35 CAMMSEMCReverbControl* CAMMSEMCReverbControl::NewLC(CMMAPlayer* aPlayer) |
|
36 { |
|
37 CAMMSEMCReverbControl* self = new(ELeave) CAMMSEMCReverbControl(aPlayer); |
|
38 |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 |
|
42 return self; |
|
43 } |
|
44 |
|
45 // Destructor |
|
46 CAMMSEMCReverbControl::~CAMMSEMCReverbControl() |
|
47 { |
|
48 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::~CAMMSEMCReverbControl"); |
|
49 |
|
50 // Perform DeallocateControl, if the state change has not yet performed it. |
|
51 DeallocateControl(); |
|
52 if (iAMMSEMCReverbEnvironmentalPresetUtility) |
|
53 delete iAMMSEMCReverbEnvironmentalPresetUtility; |
|
54 delete iPresetNames; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CAMMSEMCReverbControl::SetReverbLevelL |
|
59 // Sets the gain level of the reverberation. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 TInt CAMMSEMCReverbControl::SetReverbLevelL(TInt aLevel) |
|
63 { |
|
64 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetReverbLevelL: %d", aLevel); |
|
65 __ASSERT_DEBUG(aLevel <= KAMMSMaxReverbLevel, User::Invariant()); |
|
66 TInt roomLevel = 0; |
|
67 iMReverbControl->RoomLevel(roomLevel); |
|
68 TInt reflectionLevel =0; |
|
69 iMReverbControl->ReflectionsLevel(reflectionLevel); |
|
70 TInt tempChange = aLevel - reflectionLevel - roomLevel; |
|
71 |
|
72 // Sets the reverb reflections level in mB |
|
73 iMReverbControl->SetReflectionsLevel(aLevel - roomLevel); |
|
74 |
|
75 // Calculate native reverb level. |
|
76 TInt reverbLevel; |
|
77 // iMReverbControl->ReverbLevel(reverbLevel); |
|
78 reverbLevel = iEnvReverbLevel + tempChange; |
|
79 |
|
80 // Ensure that the level is within the limits. |
|
81 |
|
82 TInt minLevel = 0; |
|
83 TInt maxLevel = 0; |
|
84 iMReverbControl->ReverbLevelRange(minLevel, maxLevel); |
|
85 |
|
86 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetReverbLevelL: orig %d", |
|
87 reverbLevel); |
|
88 |
|
89 reverbLevel = Min(reverbLevel, maxLevel); |
|
90 reverbLevel = Max(reverbLevel, minLevel); |
|
91 |
|
92 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetReverbLevelL: set %d", |
|
93 reverbLevel); |
|
94 // Sets the reverb level in mB |
|
95 iMReverbControl->SetReverbLevel(reverbLevel); |
|
96 // Apply can be called for Reverb, as it does not internally include EnableL |
|
97 // unlike in case of Equalizer or StereoWidening |
|
98 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetReverbLevelL calling ApplyL"); |
|
99 iMReverbControl->Apply(); |
|
100 |
|
101 // Return the value that was used in setting the reverb |
|
102 return aLevel; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CAMMSEMCReverbControl::SetReverbTimeL |
|
107 // Sets the reverberation time of the reverb. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CAMMSEMCReverbControl::SetReverbTimeL(TInt aTime) |
|
111 { |
|
112 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetReverbTimeL: %d", aTime); |
|
113 // Check in debug build that aTime is within valid range. |
|
114 __ASSERT_DEBUG(aTime >= KAMMSMinReverbTime, User::Invariant()); |
|
115 iMReverbControl->SetDecayTime(aTime); |
|
116 iMReverbControl->Apply(); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CAMMSEMCReverbControl::ReverbLevel |
|
121 // Gets the gain level of the reverberation. |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 TInt CAMMSEMCReverbControl::ReverbLevel() |
|
125 { |
|
126 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::ReverbLevel called"); |
|
127 TInt iReverbLevel; |
|
128 iMReverbControl->ReverbLevel(iReverbLevel); |
|
129 return iReverbLevel; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CAMMSEMCReverbControl::ReverbTime |
|
134 // Gets the reverberation time. |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CAMMSEMCReverbControl::ReverbTime() |
|
138 { |
|
139 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::ReverbTime called"); |
|
140 |
|
141 TUint iReverbTime; |
|
142 iMReverbControl->DecayTime(iReverbTime); |
|
143 return iReverbTime; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CAMMSEMCReverbControl::MinReverbLevel |
|
148 // Gets the minimum level of the reverberation. |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CAMMSEMCReverbControl::MinReverbLevel() |
|
152 { |
|
153 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::MinReverbLevel called"); |
|
154 |
|
155 TInt minLevel; |
|
156 TInt maxLevel; |
|
157 iMReverbControl->ReverbLevelRange( |
|
158 minLevel, maxLevel); |
|
159 |
|
160 return minLevel; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CAMMSEMCReverbControl::MaxReverbLevel |
|
165 // Gets the maximum level of the reverberation. |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CAMMSEMCReverbControl::MaxReverbLevel() |
|
169 { |
|
170 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::MaxReverbLevel called"); |
|
171 TInt minLevel; |
|
172 TInt maxLevel; |
|
173 iMReverbControl->ReverbLevelRange(minLevel, maxLevel); |
|
174 return maxLevel; |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CAMMSEMCReverbControl::SetPresetL |
|
179 // Sets the effect according to the given preset. |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 void CAMMSEMCReverbControl::SetPresetL(const TDesC& aPreset) |
|
183 { |
|
184 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetPresetL \"%S\"", aPreset.Ptr()); |
|
185 CEnvironmentalReverb *iEnvironmentalReverb = NULL; |
|
186 User::LeaveIfError(iAMMSEMCReverbEnvironmentalPresetUtility->PrepareEmptyReverbUtilitiesL()); |
|
187 iAMMSEMCReverbEnvironmentalPresetUtility->GetPresetNamesL(*iPresetNames); |
|
188 TInt presetPosition = 0; |
|
189 TInt findPreset = iPresetNames->Find(aPreset, presetPosition); |
|
190 if (findPreset == 0) // Find returns zero, if a matching element is found. |
|
191 { |
|
192 iEnvironmentalReverb = iAMMSEMCReverbEnvironmentalPresetUtility->GetEnvironmentalReverbAtPresetIndexL(presetPosition); |
|
193 iCurrentPreset = presetPosition; |
|
194 } |
|
195 else |
|
196 { |
|
197 iAMMSEMCReverbEnvironmentalPresetUtility->DeleteEmptyReverbUtilities(); |
|
198 User::Leave(KErrArgument); |
|
199 } |
|
200 |
|
201 if (!iEnvironmentalReverb) |
|
202 { |
|
203 iAMMSEMCReverbEnvironmentalPresetUtility->DeleteEmptyReverbUtilities(); |
|
204 return; |
|
205 } |
|
206 //Get all preset data here |
|
207 |
|
208 TInt iReverbTime = iEnvironmentalReverb-> DecayTime(); |
|
209 TInt iReverbLevel = iEnvironmentalReverb->ReflectionsLevel() + iEnvironmentalReverb->RoomLevel(); |
|
210 iEnvReverbLevel = iEnvironmentalReverb->ReverbLevel(); |
|
211 TInt roomLevel = iEnvironmentalReverb->RoomLevel(); |
|
212 TInt reflectionLevel = iEnvironmentalReverb->ReflectionsLevel(); |
|
213 TUint decayHFRatio = iEnvironmentalReverb->DecayHFRatio(); |
|
214 TUint density = iEnvironmentalReverb->Density(); |
|
215 TUint diffusion = iEnvironmentalReverb->Diffusion(); |
|
216 TUint reflectionsDelay = iEnvironmentalReverb->ReflectionsDelay(); |
|
217 TUint reverbDelay = iEnvironmentalReverb->ReverbDelay(); |
|
218 TUint roomHFLevel = iEnvironmentalReverb->RoomHFLevel(); |
|
219 |
|
220 // Set all preset data to EMC |
|
221 TInt err = iMReverbControl->SetDecayTime(iReverbTime); |
|
222 err = iMReverbControl->SetReverbLevel(iReverbLevel); |
|
223 err = iMReverbControl->SetRoomLevel(roomLevel); |
|
224 err = iMReverbControl->SetReflectionsLevel(reflectionLevel); |
|
225 err = iMReverbControl->SetDecayHFRatio(decayHFRatio); |
|
226 err = iMReverbControl->SetDensity(density); |
|
227 err = iMReverbControl->SetDiffusion(diffusion); |
|
228 err = iMReverbControl->SetReflectionsDelay(reflectionsDelay); |
|
229 err = iMReverbControl->SetReverbDelay(reverbDelay); |
|
230 err = iMReverbControl->SetRoomHFLevel(roomHFLevel); |
|
231 err = iMReverbControl->Apply(); |
|
232 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCReverbControl::SetPresetL iMReverbControl setter func. err = %d",err); |
|
233 iAMMSEMCReverbEnvironmentalPresetUtility->DeleteEmptyReverbUtilities(); |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CAMMSEMCReverbControl::PresetNamesL |
|
238 // Gets the available preset names. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 const CDesCArray& CAMMSEMCReverbControl::PresetNamesL() |
|
242 { |
|
243 |
|
244 //CEnvironmentalReverb *iEnvironmentalReverb = NULL; |
|
245 iAMMSEMCReverbEnvironmentalPresetUtility->PrepareEmptyReverbUtilitiesL(); |
|
246 iAMMSEMCReverbEnvironmentalPresetUtility->GetPresetNamesL(*iPresetNames); |
|
247 iAMMSEMCReverbEnvironmentalPresetUtility->DeleteEmptyReverbUtilities(); |
|
248 return *iPresetNames; |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CAMMSEMCReverbControl::PresetL |
|
253 // Gets the current preset. |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 const TDesC& CAMMSEMCReverbControl::PresetL() |
|
257 { |
|
258 //if no preset is set, return null |
|
259 if (iCurrentPreset < 0) |
|
260 { |
|
261 return KNullDesC; |
|
262 } |
|
263 |
|
264 else |
|
265 { |
|
266 // Retrieves a Preset with the given index from the utility class |
|
267 iAMMSEMCReverbEnvironmentalPresetUtility->PrepareEmptyReverbUtilitiesL(); |
|
268 iAMMSEMCReverbEnvironmentalPresetUtility->GetPresetAtIndexL(iPresetName , iCurrentPreset); |
|
269 iAMMSEMCReverbEnvironmentalPresetUtility->DeleteEmptyReverbUtilities(); |
|
270 return iPresetName; |
|
271 } |
|
272 |
|
273 |
|
274 } |
|
275 |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CAMMSEMCReverbControl::SetEnabledL |
|
279 // Enables/disables the effect. |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CAMMSEMCReverbControl::SetEnabledL(TBool aEnable) |
|
283 { |
|
284 if (aEnable) |
|
285 { |
|
286 // Enable the effect |
|
287 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetEnabledL(true), calling Enable"); |
|
288 iMReverbControl->Enable(); |
|
289 iMReverbControl->Apply(); |
|
290 } |
|
291 else |
|
292 { |
|
293 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetEnabledL(false), calling Disable"); |
|
294 iMReverbControl->Disable(); |
|
295 } |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CAMMSEMCReverbControl::PrepareControlL |
|
300 // Function which is called after the correct state is set in Player. |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 void CAMMSEMCReverbControl::PrepareControlL() |
|
304 { |
|
305 // Perform the action only for the first time, skip if called afterwards |
|
306 if (!iMReverbControl) |
|
307 { |
|
308 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::PrepareControlL"); |
|
309 //Create Reverb Effect Control |
|
310 iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl(); |
|
311 iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory(); |
|
312 |
|
313 MEffectControl* temp(NULL); |
|
314 User::LeaveIfError(iFactory->CreateEffectControl(KReverbEffectControl, temp)); |
|
315 iMReverbControl = static_cast<MReverbControl*>(temp); |
|
316 User::LeaveIfError(iStreamControl->AddEffect(*iMReverbControl)); |
|
317 iMReverbControl->Enable(); |
|
318 SetPresetL(KAMMSEMCDefaultReverbPreset); |
|
319 |
|
320 } |
|
321 } |
|
322 |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CAMMSEMCReverbControl::DeallocateControl |
|
325 // Function which is called after the correct state is set in Player. |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 void CAMMSEMCReverbControl::DeallocateControl() |
|
329 { |
|
330 |
|
331 if (iMReverbControl) |
|
332 { |
|
333 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::DeallocateControl"); |
|
334 |
|
335 // Reverb for Audio can be disabled or enabled |
|
336 TRAPD(err,iMReverbControl->Disable()); |
|
337 if (err != KErrNone) |
|
338 { |
|
339 //Some EMC Error |
|
340 ELOG1( EJavaAMMS, "AMMS::CAMMSEMCReverbControl::DeallocateControl err = %d",err); |
|
341 } |
|
342 //return the control to factory |
|
343 MEffectControl* temp = iMReverbControl; |
|
344 iStreamControl->RemoveEffect(*temp); |
|
345 // Delete the Effect |
|
346 MEffectControl* tempCtrl = iMReverbControl; |
|
347 iFactory->DeleteEffectControl(tempCtrl); |
|
348 iMReverbControl = NULL; |
|
349 |
|
350 iCurrentPreset = -1; |
|
351 } |
|
352 } |
|
353 |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CAMMSEMCReverbControl::GetReverbControl |
|
357 // Returns the reverb control. It will be used by CAMMSEMCReverbSourceControl |
|
358 // ----------------------------------------------------------------------------- |
|
359 MReverbControl * CAMMSEMCReverbControl::GetReverbControlL() |
|
360 { |
|
361 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::GetReverbControl"); |
|
362 |
|
363 if (! iMReverbControl) |
|
364 { |
|
365 PrepareControlL(); // creates the control |
|
366 } |
|
367 |
|
368 return iMReverbControl; |
|
369 } |
|
370 |
|
371 // ----------------------------------------------------------------------------- |
|
372 // CAMMSEMCReverbControl::CurrentPresetIndex |
|
373 // Returns the Current Preset Index. It will be used by CAMMSEMCReverbSourceControl |
|
374 // ----------------------------------------------------------------------------- |
|
375 TInt CAMMSEMCReverbControl::CurrentPresetIndex() |
|
376 { |
|
377 return iCurrentPreset; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // Overriding the base class CAMMSEffectControl function here |
|
382 //------------------------------------------------------------------------------ |
|
383 |
|
384 void CAMMSEMCReverbControl::SetEnforcedL(TBool aEnforced) |
|
385 { |
|
386 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetEnforcedL"); |
|
387 // Indicate the effect is to be enforced or not. ETrue = Enforced. |
|
388 iMReverbControl->Enforce(aEnforced); |
|
389 |
|
390 ApplySettingsL(); |
|
391 |
|
392 } |
|
393 TBool CAMMSEMCReverbControl::Enforced() |
|
394 { |
|
395 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::Enforced"); |
|
396 // Returns ETrue if the effect is enforced, EFalse if not enforced. |
|
397 TBool enforced; |
|
398 iMReverbControl->IsEnforced(enforced); |
|
399 return enforced; |
|
400 |
|
401 } |
|
402 void CAMMSEMCReverbControl::SetScopeL(TInt aScope) |
|
403 { |
|
404 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::SetScopeL"); |
|
405 __ASSERT_DEBUG( |
|
406 (aScope == CAMMSEffectControlGroup::EScopeLiveOnly), |
|
407 User::Invariant()); |
|
408 // Just to suppress warning in release build |
|
409 (void)aScope; |
|
410 } |
|
411 TInt CAMMSEMCReverbControl::Scope() |
|
412 { |
|
413 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::Scope"); |
|
414 // For now only the (LIVE_ONLY) scope is supported. |
|
415 return CAMMSEffectControlGroup::EScopeLiveOnly; |
|
416 |
|
417 } |
|
418 void CAMMSEMCReverbControl::ApplySettingsL() |
|
419 { |
|
420 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl::ApplySettingsL"); |
|
421 TBool enabled; |
|
422 iMReverbControl->IsEnabled(enabled); |
|
423 if (enabled) |
|
424 { |
|
425 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCReverbControl:ApplySettingsL calling ApplyL"); |
|
426 iMReverbControl->Apply(); |
|
427 } |
|
428 } |
|
429 |
|
430 const TDesC& CAMMSEMCReverbControl::ClassName() const |
|
431 { |
|
432 return KAMMSEMCReverbControl; |
|
433 } |
|
434 |
|
435 // ----------------------------------------------------------------------------- |
|
436 // CAMMSEMCReverbControl::ConstructL |
|
437 // Symbian 2nd phase constructor can leave. |
|
438 // ----------------------------------------------------------------------------- |
|
439 void CAMMSEMCReverbControl::ConstructL() |
|
440 { |
|
441 // Create array for preset names |
|
442 iPresetNames = new(ELeave) CDesCArrayFlat(1); |
|
443 |
|
444 // Set current preset to a negative value as it is not set yet |
|
445 iCurrentPreset = -1; |
|
446 |
|
447 CAMMSEffectControl::ConstructL(); |
|
448 iAMMSEMCReverbEnvironmentalPresetUtility = new(ELeave) CAMMSEMCReverbEnvironmentalPresetUtility; |
|
449 iAMMSEMCReverbEnvironmentalPresetUtility->ConstructL(); |
|
450 |
|
451 } |
|
452 |
|
453 // ----------------------------------------------------------------------------- |
|
454 // CAMMSEMCReverbControl::CAMMSEMCReverbControl |
|
455 // C++ default constructor can NOT contain any code, that |
|
456 // might leave. |
|
457 // ----------------------------------------------------------------------------- |
|
458 CAMMSEMCReverbControl::CAMMSEMCReverbControl(CMMAPlayer* aPlayer) |
|
459 : CAMMSBaseReverbControl(aPlayer) |
|
460 { |
|
461 iMMAPlayer = aPlayer; |
|
462 } |
|
463 |
|
464 // End of File |