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 <logger.h> |
|
21 #include "cammsequalizercontrol.h" |
|
22 |
|
23 |
|
24 |
|
25 // ============================ MEMBER FUNCTIONS =============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CAMMSEqualizerControl::NewLC |
|
29 // Two-phased constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 CAMMSEqualizerControl* CAMMSEqualizerControl::NewLC(CMMAPlayer* aPlayer) |
|
32 { |
|
33 CAMMSEqualizerControl* self = |
|
34 new(ELeave) CAMMSEqualizerControl(aPlayer); |
|
35 |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 |
|
39 return self; |
|
40 } |
|
41 |
|
42 // Destructor |
|
43 CAMMSEqualizerControl::~CAMMSEqualizerControl() |
|
44 { |
|
45 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::~CAMMSEqualizerControl"); |
|
46 |
|
47 // Perform DeallocateControl, if the state change has not yet performed it. |
|
48 DeallocateControl(); |
|
49 delete iEqualizerUtility; |
|
50 delete iPresetNames; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CAMMSEqualizerControl::BandLevelL |
|
55 // Gets the gain set for the given equalizer band. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 TInt CAMMSEqualizerControl::BandLevelL(TInt aBand) |
|
59 { |
|
60 // if aBand is out of range the method must leave with KErrArgument. |
|
61 if (aBand < 0 || aBand > (NumberOfBands() - 1)) |
|
62 { |
|
63 User::Leave(KErrArgument); |
|
64 } |
|
65 |
|
66 // Returns the band level in mB for the specified band |
|
67 // AudioEqualizerBase: TInt32 BandLevel( TUint8 aBand ) const; |
|
68 return ((CAudioEqualizer*)iAudioEffect)->BandLevel( |
|
69 (TUint8)(aBand + KAMMSBandOffset)); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CAMMSEqualizerControl::MaxBandLevel |
|
74 // Returns the maximum band level supported. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 TInt CAMMSEqualizerControl::MaxBandLevel() |
|
78 { |
|
79 // Get the dB range in mB for the equalizer. |
|
80 |
|
81 TInt32 minLevel = 0; |
|
82 TInt32 maxLevel = 0; |
|
83 ((CAudioEqualizer*)iAudioEffect)->DbLevelLimits(minLevel, maxLevel); |
|
84 |
|
85 return maxLevel; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CAMMSEqualizerControl::MinBandLevel |
|
90 // Returns the minimum band level supported. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 TInt CAMMSEqualizerControl::MinBandLevel() |
|
94 { |
|
95 // Get the dB range in mB for the equalizer. |
|
96 |
|
97 TInt32 minLevel = 0; |
|
98 TInt32 maxLevel = 0; |
|
99 ((CAudioEqualizer*)iAudioEffect)->DbLevelLimits(minLevel, maxLevel); |
|
100 |
|
101 return minLevel; |
|
102 } |
|
103 |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CAMMSEqualizerControl::BandWidth |
|
107 // Returns the band width in Hz for the specified band. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 TInt CAMMSEqualizerControl::BandWidth(TInt aBand) |
|
111 { |
|
112 return ((CAudioEqualizer*)iAudioEffect)->BandWidth( |
|
113 (TUint8)(aBand + KAMMSBandOffset)); |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CAMMSEqualizerControl::CenterFrequency |
|
118 // Returns the center frequency in Hz for a given band. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt CAMMSEqualizerControl::CenterFrequency(TInt aBand) |
|
122 { |
|
123 return ((CAudioEqualizer*)iAudioEffect)->CenterFrequency( |
|
124 (TUint8)(aBand + KAMMSBandOffset)); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CAMMSEqualizerControl::CrossoverFrequency |
|
129 // Returns the cross-over frequency between the given frequency. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CAMMSEqualizerControl::CrossoverFrequency(TInt aBand) |
|
133 { |
|
134 return ((CAudioEqualizer*)iAudioEffect)->CrossoverFrequency( |
|
135 (TUint8)(aBand + KAMMSBandOffset)); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CAMMSEqualizerControl::NumberOfBands |
|
140 // Gets the number of frequency bands that the equalizer supports. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CAMMSEqualizerControl::NumberOfBands() |
|
144 { |
|
145 // Returns the number of equalizer bands. |
|
146 // AudioEqualizerBase: TUint8 NumberOfBands() const; |
|
147 return ((CAudioEqualizer*)iAudioEffect)->NumberOfBands(); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CAMMSEqualizerControl::SetBandLevelL |
|
152 // Sets the given equalizer band to the given gain value. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CAMMSEqualizerControl::SetBandLevelL( |
|
156 TInt aLevel, |
|
157 TInt aBand) |
|
158 { |
|
159 LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::SetBandLevelL: level=%d, band=%d", |
|
160 aLevel, aBand); |
|
161 |
|
162 // If aBand or aLevel is out of valid range the method must leave |
|
163 // with KErrArgument. |
|
164 if (aBand < 0 || |
|
165 aBand > (NumberOfBands() - 1) || |
|
166 aLevel < MinBandLevel() || |
|
167 aLevel > MaxBandLevel()) |
|
168 { |
|
169 User::Leave(KErrArgument); |
|
170 } |
|
171 |
|
172 // Sets the equalizer band level value in mB, ranging from Min to Max |
|
173 ((CAudioEqualizer*)iAudioEffect)->SetBandLevelL( |
|
174 (TInt8)(aBand + KAMMSBandOffset), aLevel); |
|
175 |
|
176 ApplySettingsL(); |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CAMMSEqualizerControl::SetPresetL |
|
181 // Sets the effect according to the given preset. |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CAMMSEqualizerControl::SetPresetL(const TDesC& aPreset) |
|
185 { |
|
186 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::SetPresetL \"%S\"", aPreset.Ptr()); |
|
187 |
|
188 const CDesCArray& presetNames = PresetNamesL(); |
|
189 |
|
190 TInt presetPosition = 0; |
|
191 TInt findPreset = presetNames.Find(aPreset, presetPosition); |
|
192 if (findPreset == 0) // Find returns zero, if a matching element is found. |
|
193 { |
|
194 // This supposes that the indexing of the presets starts at zero. |
|
195 iEqualizerUtility->GetPresetL(presetPosition); |
|
196 |
|
197 // Set the base class audio effect as the new CAudioEqualizer |
|
198 // that is set with the previous GetPresetL method. |
|
199 iAudioEffect = &(iEqualizerUtility->Equalizer()); |
|
200 iCurrentPreset = presetPosition; |
|
201 |
|
202 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::SetPresetL \"%S\" GetPresetL OK", |
|
203 aPreset.Ptr()); |
|
204 } |
|
205 else |
|
206 { |
|
207 User::Leave(KErrArgument); |
|
208 } |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CAMMSEqualizerControl::PresetNamesL |
|
213 // Gets the available preset names. |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 const CDesCArray& CAMMSEqualizerControl::PresetNamesL() |
|
217 { |
|
218 // Returns an array of all preset names (pre-defined and user-defined). |
|
219 // The pre-defined presets are in the beginning of the list. |
|
220 |
|
221 TArray< TEfAudioEqualizerUtilityPreset > presetNames = |
|
222 iEqualizerUtility->Presets(); |
|
223 |
|
224 // Before appending the preset names, reset the member array |
|
225 iPresetNames->Reset(); |
|
226 for (TInt i = 0; i < presetNames.Count(); i++) |
|
227 { |
|
228 iPresetNames->AppendL(presetNames[ i ].iPresetName); |
|
229 } |
|
230 |
|
231 return *iPresetNames; |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CAMMSEqualizerControl::PresetL |
|
236 // Gets the current preset. |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 const TDesC& CAMMSEqualizerControl::PresetL() |
|
240 { |
|
241 //if no preset is set, return null |
|
242 if (iCurrentPreset < 0) |
|
243 { |
|
244 return KNullDesC; |
|
245 } |
|
246 else |
|
247 { |
|
248 // Retrieves a Preset with the given index from the Central Repository |
|
249 // AudioEqualizerUtility.h: |
|
250 // const TDesC& GetPresetL(TInt aPresetIndex) |
|
251 return iEqualizerUtility->GetPresetL(iCurrentPreset); |
|
252 } |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CAMMSEqualizerControl::SetEnabledL |
|
257 // Enables/disables the effect. |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CAMMSEqualizerControl::SetEnabledL(TBool aEnable) |
|
261 { |
|
262 if (aEnable) |
|
263 { |
|
264 // Enable the effect |
|
265 // Instead of using CAudioEffectBase: virtual void EnableL(), |
|
266 // use the derived effect's (=preset's) ApplyL which calls EnableL. |
|
267 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::SetEnabledL(true), calling ApplyL"); |
|
268 iAudioEffect->ApplyL(); |
|
269 } |
|
270 else |
|
271 { |
|
272 // Disable the effect |
|
273 // Instead of using CAudioEffectBase: virtual void DisableL(), |
|
274 // use the utility class DisableEqualizerL, |
|
275 // which calls DisableL for the correct preset |
|
276 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::SetEnabledL(false), calling DisableEqualizerL"); |
|
277 iEqualizerUtility->DisableEqualizerL(); |
|
278 } |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CAMMSEqualizerControl::PrepareControlL |
|
283 // Function which is called after the correct state is set in Player. |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 void CAMMSEqualizerControl::PrepareControlL() |
|
287 { |
|
288 // Perform the action only for the first time, skip if called afterwards |
|
289 if (!iEqualizerUtility) |
|
290 { |
|
291 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::PrepareControlL"); |
|
292 |
|
293 CCustomCommandUtility* customCommandUtility = |
|
294 CreateCustomCommandUtilityL(); |
|
295 |
|
296 // Effect API takes the ownership of customCommandUtility. |
|
297 iEqualizerUtility = CAudioEqualizerUtility::NewL( |
|
298 customCommandUtility); |
|
299 |
|
300 // Set the base class audio effect as CAudioEqualizer, |
|
301 // even the native AudioEqualizerUtility has an empty CAudioEqualizer |
|
302 iAudioEffect = &(iEqualizerUtility->Equalizer()); |
|
303 } |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CAMMSEqualizerControl::DeallocateControl |
|
308 // Function which is called after the correct state is set in Player. |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CAMMSEqualizerControl::DeallocateControl() |
|
312 { |
|
313 if (iEqualizerUtility) |
|
314 { |
|
315 LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEqualizerControl::DeallocateControlL"); |
|
316 |
|
317 // Delete the Effect API class. |
|
318 TRAPD(err, iEqualizerUtility->DisableEqualizerL()); |
|
319 if (err != KErrNone) |
|
320 { |
|
321 // The only even theoritically possible error code here would be |
|
322 // KErrAccessDenied which is a result from Effect API calling ApplyL |
|
323 // method without having update rights, but since the Utility |
|
324 // class is already created, that situation can be discarded here. |
|
325 } |
|
326 |
|
327 delete iEqualizerUtility; |
|
328 iEqualizerUtility = NULL; |
|
329 } |
|
330 } |
|
331 |
|
332 const TDesC& CAMMSEqualizerControl::ClassName() const |
|
333 { |
|
334 return KAMMSEqualizerControl; |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CAMMSEqualizerControl::ConstructL |
|
339 // Symbian 2nd phase constructor can leave. |
|
340 // ----------------------------------------------------------------------------- |
|
341 void CAMMSEqualizerControl::ConstructL() |
|
342 { |
|
343 // Create array for preset names |
|
344 iPresetNames = new(ELeave) CDesCArrayFlat(1); |
|
345 |
|
346 // Set current preset to a negative value as it is not set yet |
|
347 iCurrentPreset = -1; |
|
348 |
|
349 CAMMSEffectControl::ConstructL(); |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CAMMSEqualizerControl::CAMMSEqualizerControl |
|
354 // C++ default constructor can NOT contain any code, that |
|
355 // might leave. |
|
356 // ----------------------------------------------------------------------------- |
|
357 CAMMSEqualizerControl::CAMMSEqualizerControl(CMMAPlayer* aPlayer) |
|
358 : CAMMSBaseEqualizerControl(aPlayer) |
|
359 { |
|
360 } |
|
361 |
|
362 // End of File |
|
363 |
|
364 |
|
365 |
|