|
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 equalization settings of a Player. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <jdebug.h> |
|
21 #include "cammsemcequalizercontrol.h" |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CAMMSEMCEqualizerControl::NewLC |
|
30 // Two-phased constructor. |
|
31 // ----------------------------------------------------------------------------- |
|
32 CAMMSEMCEqualizerControl* CAMMSEMCEqualizerControl::NewLC(CMMAPlayer* aPlayer) |
|
33 { |
|
34 CAMMSEMCEqualizerControl* self = |
|
35 new(ELeave) CAMMSEMCEqualizerControl(aPlayer); |
|
36 |
|
37 CleanupStack::PushL(self); |
|
38 self->ConstructL(); |
|
39 |
|
40 return self; |
|
41 } |
|
42 |
|
43 // Destructor |
|
44 CAMMSEMCEqualizerControl::~CAMMSEMCEqualizerControl() |
|
45 { |
|
46 DEBUG("AMMS::CAMMSEMCEqualizerControl::~CAMMSEMCEqualizerControl"); |
|
47 |
|
48 // Perform DeallocateControl, if the state change has not yet performed it. |
|
49 DeallocateControl(); |
|
50 if (iAMMSEMCEqualizerEnvironmentalPresetUtility) |
|
51 delete iAMMSEMCEqualizerEnvironmentalPresetUtility; |
|
52 delete iPresetNames; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CAMMSEMCEqualizerControl::BandLevelL |
|
57 // Gets the gain set for the given equalizer band. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 TInt CAMMSEMCEqualizerControl::BandLevelL(TInt aBand) |
|
61 { |
|
62 // if aBand is out of range the method must leave with KErrArgument. |
|
63 |
|
64 if (aBand < 0 || aBand > (NumberOfBands() - 1)) |
|
65 { |
|
66 User::Leave(KErrArgument); |
|
67 } |
|
68 // Returns the band level in mB for the specified band |
|
69 TInt bandlevel; |
|
70 TInt aNativeBand = aBand + KAMMSBandOffset; |
|
71 iMEqualizerControl->BandLevel(aNativeBand,bandlevel); |
|
72 return bandlevel; |
|
73 |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CAMMSEMCEqualizerControl::MaxBandLevel |
|
78 // Returns the maximum band level supported. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 TInt CAMMSEMCEqualizerControl::MaxBandLevel() |
|
82 { |
|
83 // Get the dB range in mB for the equalizer. |
|
84 TInt min,max; |
|
85 iMEqualizerControl->DbLevelLimits(min,max); |
|
86 return max; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CAMMSEMCEqualizerControl::MinBandLevel |
|
91 // Returns the minimum band level supported. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 TInt CAMMSEMCEqualizerControl::MinBandLevel() |
|
95 { |
|
96 // Get the dB range in mB for the equalizer. |
|
97 TInt min,max; |
|
98 iMEqualizerControl->DbLevelLimits(min,max); |
|
99 return min; |
|
100 } |
|
101 |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CAMMSEMCEqualizerControl::BandWidth |
|
105 // Returns the band width in Hz for the specified band. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TInt CAMMSEMCEqualizerControl::BandWidth(TInt aBand) |
|
109 { |
|
110 TInt bndwdth; |
|
111 TInt aNativeBand = aBand + KAMMSBandOffset; |
|
112 iMEqualizerControl->BandWidth(aNativeBand,bndwdth); |
|
113 return bndwdth; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CAMMSEMCEqualizerControl::CenterFrequency |
|
118 // Returns the center frequency in Hz for a given band. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CAMMSEMCEqualizerControl::CenterFrequency(TInt aBand) |
|
122 { |
|
123 TInt cntrfreq; |
|
124 TInt aNativeBand = aBand + KAMMSBandOffset; |
|
125 iMEqualizerControl->CenterFrequency(aNativeBand,cntrfreq); |
|
126 return cntrfreq; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CAMMSEMCEqualizerControl::CrossoverFrequency |
|
131 // Returns the cross-over frequency between the given frequency. |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CAMMSEMCEqualizerControl::CrossoverFrequency(TInt aBand) |
|
135 { |
|
136 TInt aCrossOverFreq; |
|
137 TInt aNativeBand = aBand + KAMMSBandOffset; |
|
138 iMEqualizerControl->CrossoverFrequency(aNativeBand, aCrossOverFreq); |
|
139 return aCrossOverFreq; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CAMMSEMCEqualizerControl::NumberOfBands |
|
144 // Gets the number of frequency bands that the equalizer supports. |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 TInt CAMMSEMCEqualizerControl::NumberOfBands() |
|
148 { |
|
149 // Returns the number of equalizer bands. |
|
150 // AudioEqualizerBase: TUint8 NumberOfBands() const; |
|
151 |
|
152 TInt aNumOfBands; |
|
153 iMEqualizerControl->NumberOfBands(aNumOfBands); |
|
154 return aNumOfBands; |
|
155 |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CAMMSEMCEqualizerControl::SetBandLevelL |
|
160 // Sets the given equalizer band to the given gain value. |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CAMMSEMCEqualizerControl::SetBandLevelL( |
|
164 TInt aLevel, |
|
165 TInt aBand) |
|
166 { |
|
167 DEBUG_INT2("AMMS::CAMMSEMCEqualizerControl::SetBandLevelL: level=%d, band=%d", |
|
168 aLevel, aBand); |
|
169 // If aBand or aLevel is out of valid range the method must leave |
|
170 // with KErrArgument. |
|
171 if (aBand < 0 || |
|
172 aBand > (NumberOfBands() - 1) || |
|
173 aLevel < MinBandLevel() || |
|
174 aLevel > MaxBandLevel()) |
|
175 { |
|
176 User::Leave(KErrArgument); |
|
177 } |
|
178 TInt aNativeBand = aBand + KAMMSBandOffset; |
|
179 // Sets the equalizer band level value in mB, ranging from Min to Max |
|
180 iMEqualizerControl->SetBandLevel(aNativeBand, aLevel); |
|
181 |
|
182 ApplySettingsL(); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CAMMSEMCEqualizerControl::SetPresetL |
|
187 // Sets the effect according to the given preset. |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 void CAMMSEMCEqualizerControl::SetPresetL(const TDesC& aPreset) |
|
191 { |
|
192 DEBUG_STR("AMMS::CAMMSEMCEqualizerControl::SetPresetL \"%S\"", aPreset); |
|
193 CAudioEqualizer *iAudioEqualizer = NULL; |
|
194 iAMMSEMCEqualizerEnvironmentalPresetUtility->PrepareEmptyEqualizerUtilitiesL(); |
|
195 iAMMSEMCEqualizerEnvironmentalPresetUtility->GetPresetNamesL(*iPresetNames); |
|
196 TInt presetPosition = 0; |
|
197 TInt findPreset = iPresetNames->Find(aPreset, presetPosition); |
|
198 if (findPreset == 0) // Find returns zero, if a matching element is found. |
|
199 { |
|
200 iAudioEqualizer = iAMMSEMCEqualizerEnvironmentalPresetUtility->GetEqualizerAtPresetIndexL(presetPosition); |
|
201 iCurrentPreset = presetPosition; |
|
202 } |
|
203 else |
|
204 { |
|
205 iAMMSEMCEqualizerEnvironmentalPresetUtility->DeleteEmptyEqualizerUtilities(); |
|
206 User::Leave(KErrArgument); |
|
207 } |
|
208 |
|
209 if (!iAudioEqualizer) |
|
210 { |
|
211 iAMMSEMCEqualizerEnvironmentalPresetUtility->DeleteEmptyEqualizerUtilities(); |
|
212 return; |
|
213 } |
|
214 //Get all preset data here |
|
215 // For each band of AudioEqualizer get the band level and set it to iMEqualizerControl |
|
216 |
|
217 TInt noOfbands = iAudioEqualizer->NumberOfBands(); |
|
218 |
|
219 for (TInt i = 0; i < noOfbands; i++) |
|
220 { |
|
221 // Band 0 in JSR-234 equals Band 1 in Effect API |
|
222 TInt aNativeBand = i + KAMMSBandOffset; |
|
223 TInt iBandLevel = iAudioEqualizer->BandLevel(aNativeBand); |
|
224 iMEqualizerControl->SetBandLevel(aNativeBand, iBandLevel); |
|
225 } |
|
226 |
|
227 iMEqualizerControl->Apply(); |
|
228 iAMMSEMCEqualizerEnvironmentalPresetUtility->DeleteEmptyEqualizerUtilities(); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CAMMSEMCEqualizerControl::PresetNamesL |
|
233 // Gets the available preset names. |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 const CDesCArray& CAMMSEMCEqualizerControl::PresetNamesL() |
|
237 { |
|
238 // Returns an array of all preset names (pre-defined and user-defined). |
|
239 // The pre-defined presets are in the beginning of the list. |
|
240 iAMMSEMCEqualizerEnvironmentalPresetUtility->PrepareEmptyEqualizerUtilitiesL(); |
|
241 iAMMSEMCEqualizerEnvironmentalPresetUtility->GetPresetNamesL(*iPresetNames); |
|
242 iAMMSEMCEqualizerEnvironmentalPresetUtility->DeleteEmptyEqualizerUtilities(); |
|
243 return *iPresetNames; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CAMMSEMCEqualizerControl::PresetL |
|
248 // Gets the current preset. |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 const TDesC& CAMMSEMCEqualizerControl::PresetL() |
|
252 {//if no preset is set, return null |
|
253 if (iCurrentPreset < 0) |
|
254 { |
|
255 return KNullDesC; |
|
256 } |
|
257 |
|
258 else |
|
259 { |
|
260 // Retrieves a Preset with the given index from the utility class |
|
261 iAMMSEMCEqualizerEnvironmentalPresetUtility->PrepareEmptyEqualizerUtilitiesL(); // codescanner::leave |
|
262 iAMMSEMCEqualizerEnvironmentalPresetUtility->GetPresetAtIndexL(iPresetName , iCurrentPreset); // codescanner::leave |
|
263 iAMMSEMCEqualizerEnvironmentalPresetUtility->DeleteEmptyEqualizerUtilities(); |
|
264 return iPresetName; |
|
265 } |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CAMMSEMCEqualizerControl::SetEnabledL |
|
270 // Enables/disables the effect. |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CAMMSEMCEqualizerControl::SetEnabledL(TBool aEnable) |
|
274 { |
|
275 if (aEnable) |
|
276 { |
|
277 // Enable the effect. |
|
278 |
|
279 iMEqualizerControl->Enable(); |
|
280 DEBUG("AMMS::CAMMSEMCEqualizerControl::SetEnabledL(true), calling Apply"); |
|
281 iMEqualizerControl->Apply(); |
|
282 } |
|
283 else |
|
284 { |
|
285 // Disable the effect |
|
286 |
|
287 DEBUG("AMMS::CAMMSEMCEqualizerControl::SetEnabledL(false), calling Disable"); |
|
288 iMEqualizerControl->Disable(); |
|
289 iMEqualizerControl->Apply(); |
|
290 } |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CAMMSEMCEqualizerControl::PrepareControlL |
|
295 // Function which is called after the correct state is set in Player. |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CAMMSEMCEqualizerControl::PrepareControlL() |
|
299 { |
|
300 // Perform the action only for the first time, skip if called afterwards |
|
301 if (!iMEqualizerControl) |
|
302 { |
|
303 DEBUG("AMMS::CAMMSEMCEqualizerControl::PrepareControlL"); |
|
304 //Create Equalizer Effect Control |
|
305 iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl(); |
|
306 iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory(); |
|
307 |
|
308 MEffectControl* temp(NULL); |
|
309 User::LeaveIfError(iFactory->CreateEffectControl(KEqualizerEffectControl, temp)); |
|
310 iMEqualizerControl = static_cast<MEqualizerControl*>(temp); |
|
311 User::LeaveIfError(iStreamControl->AddEffect(*iMEqualizerControl)); |
|
312 iMEqualizerControl->Enable(); |
|
313 } |
|
314 |
|
315 |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CAMMSEMCEqualizerControl::DeallocateControl |
|
320 // Function which is called after the correct state is set in Player. |
|
321 // ----------------------------------------------------------------------------- |
|
322 // |
|
323 void CAMMSEMCEqualizerControl::DeallocateControl() |
|
324 { |
|
325 if (iMEqualizerControl) |
|
326 { |
|
327 DEBUG("AMMS::CAMMSEMCEqualizerControl::DeallocateControl"); |
|
328 |
|
329 // Equalizer for Audio can be disabled or enabled |
|
330 TRAPD(err,iMEqualizerControl->Disable()); |
|
331 if (err != KErrNone) |
|
332 { |
|
333 //Some EMC Error |
|
334 DEBUG_INT("AMMS::CAMMSEMCEqualizerControl::DeallocateControl err = %d",err); |
|
335 } |
|
336 //return the control to factory |
|
337 MEffectControl* temp = iMEqualizerControl; |
|
338 iStreamControl->RemoveEffect(*temp); |
|
339 // Delete the Effect |
|
340 MEffectControl* tempCtrl = iMEqualizerControl; |
|
341 iFactory->DeleteEffectControl(tempCtrl); |
|
342 iMEqualizerControl = NULL; |
|
343 } |
|
344 } |
|
345 |
|
346 |
|
347 const TDesC& CAMMSEMCEqualizerControl::ClassName() const |
|
348 { |
|
349 return KAMMSEMCEqualizerControl; |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CAMMSEMCEqualizerControl::SetEnforcedL |
|
354 // Enforces the effect to be in use. |
|
355 // ----------------------------------------------------------------------------- |
|
356 // |
|
357 void CAMMSEMCEqualizerControl::SetEnforcedL(TBool aEnforced) |
|
358 { |
|
359 DEBUG("AMMS::CAMMSEMCEqualizerControl:SetEnforcedL"); |
|
360 // Indicate the effect is to be enforced or not. ETrue = Enforced. |
|
361 |
|
362 iMEqualizerControl->Enforce(aEnforced); |
|
363 |
|
364 ApplySettingsL(); |
|
365 |
|
366 } |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CAMMSEMCEqualizerControl::Enforced |
|
370 // Returns the current enforced setting of the effect. |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 TBool CAMMSEMCEqualizerControl::Enforced() |
|
374 { |
|
375 // Returns ETrue if the effect is enforced, EFalse if not enforced. |
|
376 TBool enforced; |
|
377 iMEqualizerControl->IsEnforced(enforced); |
|
378 return enforced; |
|
379 |
|
380 } |
|
381 |
|
382 // ----------------------------------------------------------------------------- |
|
383 // CAMMSEMCEqualizerControl::SetScopeL |
|
384 // Sets the scope of the effect. |
|
385 // ----------------------------------------------------------------------------- |
|
386 // |
|
387 void CAMMSEMCEqualizerControl::SetScopeL(TInt aScope) |
|
388 { |
|
389 DEBUG("AMMS::CAMMSEMCEqualizerControl:SetScopeL"); |
|
390 __ASSERT_DEBUG( |
|
391 (aScope == CAMMSEffectControlGroup::EScopeLiveOnly), |
|
392 User::Invariant()); |
|
393 // Just to suppress warning in release build |
|
394 (void)aScope; |
|
395 } |
|
396 |
|
397 // ----------------------------------------------------------------------------- |
|
398 // CAMMSEMCEqualizerControl::Scope |
|
399 // Returns the scope in which the effect is present. |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 TInt CAMMSEMCEqualizerControl::Scope() |
|
403 { |
|
404 // For now only the (LIVE_ONLY) scope is supported. |
|
405 return CAMMSEffectControlGroup::EScopeLiveOnly; |
|
406 } |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CAMMSEMCAudioVirtualizerControl::ApplySettingsL |
|
410 // Apply changed settings if Effect is in enabled state. |
|
411 // ----------------------------------------------------------------------------- |
|
412 void CAMMSEMCEqualizerControl::ApplySettingsL() |
|
413 { |
|
414 DEBUG("AMMS::CAMMSEMCEqualizerControl:ApplySettingsL called, checking state"); |
|
415 TBool enabled; |
|
416 iMEqualizerControl->IsEnabled(enabled); |
|
417 if (enabled) |
|
418 { |
|
419 DEBUG("AMMS::CAMMSEMCEqualizerControl:ApplySettingsL calling ApplyL"); |
|
420 iMEqualizerControl->Apply(); |
|
421 } |
|
422 } |
|
423 |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CAMMSEMCEqualizerControl::ConstructL |
|
427 // Symbian 2nd phase constructor can leave. |
|
428 // ----------------------------------------------------------------------------- |
|
429 void CAMMSEMCEqualizerControl::ConstructL() |
|
430 { |
|
431 // Create array for preset names |
|
432 iPresetNames = new(ELeave) CDesCArrayFlat(1); |
|
433 |
|
434 // Set current preset to a negative value as it is not set yet |
|
435 iCurrentPreset = -1; |
|
436 |
|
437 CAMMSEffectControl::ConstructL(); |
|
438 iAMMSEMCEqualizerEnvironmentalPresetUtility = new(ELeave)CAMMSEMCEqualizerEnvironmentalPresetUtility; |
|
439 iAMMSEMCEqualizerEnvironmentalPresetUtility->ConstructL(); |
|
440 } |
|
441 |
|
442 // ----------------------------------------------------------------------------- |
|
443 // CAMMSEMCEqualizerControl::CAMMSEMCEqualizerControl |
|
444 // C++ default constructor can NOT contain any code, that |
|
445 // might leave. |
|
446 // ----------------------------------------------------------------------------- |
|
447 CAMMSEMCEqualizerControl::CAMMSEMCEqualizerControl(CMMAPlayer* aPlayer) |
|
448 : CAMMSBaseEqualizerControl(aPlayer) |
|
449 { |
|
450 iMMAPlayer = aPlayer; |
|
451 } |
|
452 |
|
453 // End of File |
|
454 |
|
455 |
|
456 |