|
1 /* |
|
2 * Copyright (c) 2006 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: Project file for EnhancedMediaClient Utility |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "EqualizerEffectImpl.h" |
|
20 #include <AudioEqualizerBase.h> |
|
21 #include <ControlObserver.h> |
|
22 |
|
23 using namespace multimedia; |
|
24 |
|
25 CEqualizerEffect::CEqualizerEffect() |
|
26 { |
|
27 // No Impl |
|
28 } |
|
29 |
|
30 CEqualizerEffect::~CEqualizerEffect() |
|
31 { |
|
32 delete iPrevEqualizerProxy; |
|
33 delete iEqualizerProxy; |
|
34 iObservers.Close(); |
|
35 } |
|
36 |
|
37 TInt CEqualizerEffect::PostConstructor() |
|
38 { |
|
39 TRAPD( status, CEffectControlBase::ConstructL(KUidAudioEqualizerEffect) ); |
|
40 return status; |
|
41 } |
|
42 |
|
43 // From MControl begins |
|
44 TInt CEqualizerEffect::AddObserver( MControlObserver& aObserver ) |
|
45 { |
|
46 return iObservers.Append(&aObserver); |
|
47 } |
|
48 |
|
49 TInt CEqualizerEffect::RemoveObserver( MControlObserver& aObserver ) |
|
50 { |
|
51 TInt index = iObservers.Find(&aObserver); |
|
52 if( index != KErrNotFound ) |
|
53 { |
|
54 iObservers.Remove(index); |
|
55 } |
|
56 return index; |
|
57 } |
|
58 |
|
59 TUid CEqualizerEffect::Type() |
|
60 { |
|
61 return KEqualizerEffectControl; |
|
62 } |
|
63 |
|
64 TControlType CEqualizerEffect::ControlType() |
|
65 { |
|
66 return EEffectControl; |
|
67 } |
|
68 |
|
69 // From MControl ends |
|
70 |
|
71 // From MEffectControl begins |
|
72 TInt CEqualizerEffect::Apply() |
|
73 { |
|
74 return DoApply(); |
|
75 } |
|
76 |
|
77 // From MEffectControl ends |
|
78 |
|
79 TInt CEqualizerEffect::DoApply() |
|
80 { |
|
81 TInt error(KErrNone); |
|
82 if(iEqualizerProxy) |
|
83 { |
|
84 TRAP(error,iEqualizerProxy->ApplyL()); |
|
85 } |
|
86 else |
|
87 { |
|
88 error = KErrNotReady; |
|
89 } |
|
90 return error; |
|
91 } |
|
92 |
|
93 // From MEqualizerEffect begins |
|
94 /** |
|
95 * Get the band level in mB for the specified band |
|
96 * @since 5.0 |
|
97 * @param aBand Frequency Band |
|
98 * @return Returns the band level in mB for the specified band |
|
99 */ |
|
100 TInt CEqualizerEffect::BandLevel( TInt& aBand, TInt& aBandLevel ) |
|
101 { |
|
102 TInt status(KErrNone); |
|
103 if(iEqualizerProxy) |
|
104 { |
|
105 // status here returns the Band Level |
|
106 //TUint8 band(aBand); |
|
107 //TInt32 bandlevel; |
|
108 aBandLevel = iEqualizerProxy->BandLevel(aBand); |
|
109 //aBandLevel = bandlevel; |
|
110 } |
|
111 else |
|
112 { |
|
113 status = KErrNotReady; |
|
114 } |
|
115 return status; |
|
116 } |
|
117 |
|
118 /** |
|
119 * Get the band width in Hz for the specified band. |
|
120 * @since 5.0 |
|
121 * @param aBand Frequency Band |
|
122 * @return The band width in Hz for the specified band |
|
123 */ |
|
124 TInt CEqualizerEffect::BandWidth( TInt& aBand, TInt& aBandWidth ) |
|
125 { |
|
126 TInt status(KErrNone); |
|
127 if(iEqualizerProxy) |
|
128 { |
|
129 TRAP(aBandWidth,iEqualizerProxy->BandWidth(aBand)); |
|
130 } |
|
131 else |
|
132 { |
|
133 status = KErrNotReady; |
|
134 } |
|
135 return status; |
|
136 } |
|
137 |
|
138 /** |
|
139 * Get the center frequency in Hz for a given band |
|
140 * @since 5.0 |
|
141 * @param aBand Frequency Band |
|
142 * @return The center frequency in Hz for a given band. |
|
143 */ |
|
144 TInt CEqualizerEffect::CenterFrequency( TInt& aBand, TInt& aCenterFrequency ) |
|
145 { |
|
146 TInt status(KErrNone); |
|
147 if(iEqualizerProxy) |
|
148 { |
|
149 aCenterFrequency = iEqualizerProxy->CenterFrequency(aBand); |
|
150 } |
|
151 else |
|
152 { |
|
153 status = KErrNotReady; |
|
154 } |
|
155 return status; |
|
156 } |
|
157 |
|
158 /** |
|
159 * Get the cross-over frequency between the given frequency band (aBand) and the next band |
|
160 * @since 5.0 |
|
161 * @param aBand Frequency Band |
|
162 * @return Crossover frequency. |
|
163 */ |
|
164 TInt CEqualizerEffect::CrossoverFrequency( TInt& aBand, TInt& aCrossoverFreq ) |
|
165 { |
|
166 TInt status(KErrNone); |
|
167 if(iEqualizerProxy) |
|
168 { |
|
169 aCrossoverFreq = iEqualizerProxy->CenterFrequency(aBand); |
|
170 } |
|
171 else |
|
172 { |
|
173 status = KErrNotReady; |
|
174 } |
|
175 return status; |
|
176 } |
|
177 |
|
178 /** |
|
179 * Get the dB range in mB for the equalizer |
|
180 * @since 5.0 |
|
181 * @param aMin Minimum level in dB |
|
182 * @param aMin Maximum level in dB |
|
183 */ |
|
184 TInt CEqualizerEffect::DbLevelLimits( TInt& aMin, TInt& aMax ) |
|
185 { |
|
186 TInt status(KErrNone); |
|
187 if(iEqualizerProxy) |
|
188 { |
|
189 TInt32 min,max; |
|
190 TRAP(status,iEqualizerProxy->DbLevelLimits(min,max)); |
|
191 aMin = min; |
|
192 aMax = max; |
|
193 } |
|
194 else |
|
195 { |
|
196 status = KErrNotReady; |
|
197 } |
|
198 return status; |
|
199 } |
|
200 |
|
201 /** |
|
202 * Get number of equalizer bands. |
|
203 * @since 5.0 |
|
204 * @param - |
|
205 * @return The number of equalizer bands. |
|
206 */ |
|
207 TInt CEqualizerEffect::NumberOfBands(TInt& aNumberofBands) |
|
208 { |
|
209 TInt status(KErrNone); |
|
210 if(iEqualizerProxy) |
|
211 { |
|
212 aNumberofBands= iEqualizerProxy->NumberOfBands(); |
|
213 } |
|
214 else |
|
215 { |
|
216 status = KErrNotReady; |
|
217 } |
|
218 return status; |
|
219 } |
|
220 |
|
221 /** |
|
222 * Sets the equalizer band level value in mB, ranging from Min to Max |
|
223 * @since 5.0 |
|
224 * @param aBand Frequency Band |
|
225 * @param aLevel band level in dB, ranges from DbLevelLimits() |
|
226 * @return - |
|
227 */ |
|
228 TInt CEqualizerEffect::SetBandLevel( TInt& aBand, TInt& aLevel ) |
|
229 { |
|
230 TInt status(KErrNone); |
|
231 if(iEqualizerProxy) |
|
232 { |
|
233 TRAP(status,iEqualizerProxy->SetBandLevelL(aBand,aLevel)); |
|
234 } |
|
235 else |
|
236 { |
|
237 status = KErrNotReady; |
|
238 } |
|
239 return status; |
|
240 } |
|
241 |
|
242 // From MAudioEffectControl |
|
243 /** |
|
244 * Disable the effect |
|
245 * @since 5.0 |
|
246 */ |
|
247 TInt CEqualizerEffect::Disable() |
|
248 { |
|
249 TInt status(KErrNone); |
|
250 if(iEqualizerProxy) |
|
251 { |
|
252 TRAP(status,iEqualizerProxy->DisableL()); |
|
253 } |
|
254 else |
|
255 { |
|
256 status = KErrNotReady; |
|
257 } |
|
258 return status; |
|
259 } |
|
260 |
|
261 /** |
|
262 * Enable the effect |
|
263 * @since 5.0 |
|
264 */ |
|
265 TInt CEqualizerEffect::Enable() |
|
266 { |
|
267 TInt status(KErrNone); |
|
268 RDebug::Print(_L("CEqualizerEffect::Enable() [%x]"),iEqualizerProxy); |
|
269 if(iEqualizerProxy) |
|
270 { |
|
271 TRAP(status,iEqualizerProxy->EnableL()); |
|
272 } |
|
273 else |
|
274 { |
|
275 status = KErrNotReady; |
|
276 } |
|
277 return status; |
|
278 } |
|
279 |
|
280 /** |
|
281 * Enforce the effect. |
|
282 * @since 5.0 |
|
283 * @param aEnforced Indicate the effect is to be enforced or not. ETrue = Enforced. |
|
284 */ |
|
285 TInt CEqualizerEffect::Enforce( TBool &aEnforced ) |
|
286 { |
|
287 TInt status(KErrNone); |
|
288 if(iEqualizerProxy) |
|
289 { |
|
290 TRAP(status,iEqualizerProxy->EnforceL(aEnforced)); |
|
291 } |
|
292 else |
|
293 { |
|
294 status = KErrNotReady; |
|
295 } |
|
296 return status; |
|
297 } |
|
298 |
|
299 /** |
|
300 * Check if this effect object currently has update rights. |
|
301 * A client can lose update rights in some hardware platforms where there are a limited |
|
302 * number of instances of an effect that can exist at the same time. When an effect instance |
|
303 * has lost update rights the user can still change settings, but any calls to Apply the |
|
304 * settings will be deferred until update rights are regained. |
|
305 * @since 5.0 |
|
306 * @return ETrue if this object currently has rights to update the settings of this effect, |
|
307 * EFalse otherwise. |
|
308 */ |
|
309 TInt CEqualizerEffect::HaveUpdateRights(TBool &aHaveUpdateRights) |
|
310 { |
|
311 TInt status(KErrNone); |
|
312 if(iEqualizerProxy) |
|
313 { |
|
314 aHaveUpdateRights = iEqualizerProxy->HaveUpdateRights(); |
|
315 } |
|
316 else |
|
317 { |
|
318 status = KErrNotReady; |
|
319 } |
|
320 return status; |
|
321 } |
|
322 |
|
323 /** |
|
324 * Check if the effect is enabled |
|
325 * @since 5.0 |
|
326 * @return ETrue if the effect is enabled, EFalse if the effect is disabled. |
|
327 */ |
|
328 TInt CEqualizerEffect::IsEnabled(TBool &aEnabled) |
|
329 { |
|
330 TInt status(KErrNone); |
|
331 if(iEqualizerProxy) |
|
332 { |
|
333 aEnabled = iEqualizerProxy->IsEnabled(); |
|
334 } |
|
335 else |
|
336 { |
|
337 status = KErrNotReady; |
|
338 } |
|
339 return status; |
|
340 } |
|
341 |
|
342 /** |
|
343 * Check if the effect is enforced. |
|
344 * @since 5.0 |
|
345 * @return ETrue if the effect is enforced, EFalse if the effect isn ot enforced. |
|
346 */ |
|
347 TInt CEqualizerEffect::IsEnforced(TBool &aEnforced) |
|
348 { |
|
349 TInt status(KErrNone); |
|
350 if(iEqualizerProxy) |
|
351 { |
|
352 aEnforced = iEqualizerProxy->IsEnforced(); |
|
353 } |
|
354 else |
|
355 { |
|
356 status = KErrNotReady; |
|
357 } |
|
358 return status; |
|
359 } |
|
360 |
|
361 /* |
|
362 * Get the unique identifier of the audio effect |
|
363 * @since 5.0 |
|
364 * @return Unique identifier of the audio effect object. |
|
365 */ |
|
366 TInt CEqualizerEffect::Uid(TUid &aUid) |
|
367 { |
|
368 TInt status(KErrNone); |
|
369 if(iEqualizerProxy) |
|
370 { |
|
371 aUid = iEqualizerProxy->Uid(); |
|
372 } |
|
373 else |
|
374 { |
|
375 status = KErrNotReady; |
|
376 } |
|
377 return status; |
|
378 } |
|
379 // From MAudioEffectControl Ends |
|
380 |
|
381 |
|
382 // From CEffectControlBase begins |
|
383 void CEqualizerEffect::Event( TEffectControlEvent aEvent ) |
|
384 { |
|
385 TInt status(KErrNone); |
|
386 // Controller Loaded with ECIBuilderCreated |
|
387 if ( aEvent == ECIBuilderCreated ) |
|
388 { |
|
389 RDebug::Print(_L("Deleting Proxy")); |
|
390 status = DeleteEffectProxy(); |
|
391 RDebug::Print(_L("Deleting Proxy [%d]"),status); |
|
392 status = CreateEffectProxy(); |
|
393 RDebug::Print(_L("Creating Proxy [%d]"),status); |
|
394 if(status == KErrNone) |
|
395 { |
|
396 SavePreviousSettings(); |
|
397 } |
|
398 else |
|
399 { |
|
400 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
401 { |
|
402 iObservers[i]->Event(this,MAudioEffectControl::KDisabled,NULL); |
|
403 } |
|
404 } |
|
405 } |
|
406 else if ( aEvent == EMessageHandlerDeleted ) |
|
407 { |
|
408 if(status == KErrNone) |
|
409 { |
|
410 DeleteEffectProxy(); |
|
411 } |
|
412 } |
|
413 } |
|
414 |
|
415 // From CEffectControlBase ends |
|
416 |
|
417 TInt CEqualizerEffect::CreateEffectProxy() |
|
418 { |
|
419 TInt status(KErrNone); |
|
420 status = GetMessageHandle(iMsgHndlrHandlePckg); |
|
421 if(status != KErrNone) |
|
422 { |
|
423 return status; |
|
424 } |
|
425 iCustomCommand = GetCustomCommand(); |
|
426 if(!iCustomCommand) |
|
427 { |
|
428 return KErrNotReady; |
|
429 } |
|
430 |
|
431 TRAP(status,iEqualizerProxy = CAudioEqualizerProxy::NewL(iMsgHndlrHandlePckg, *iCustomCommand, NULL)); |
|
432 if(status == KErrNone) |
|
433 { |
|
434 TRAP(status,iEqualizerProxy->RegisterObserverL(*this)); |
|
435 } |
|
436 |
|
437 return status; |
|
438 } |
|
439 |
|
440 TInt CEqualizerEffect::DeleteEffectProxy() |
|
441 { |
|
442 TInt status(KErrNone); |
|
443 if(iEqualizerProxy) |
|
444 { |
|
445 iPrevEqualizerProxy = iEqualizerProxy; |
|
446 } |
|
447 iEqualizerProxy = NULL; |
|
448 return status; |
|
449 } |
|
450 |
|
451 TInt CEqualizerEffect::SavePreviousSettings() |
|
452 { |
|
453 TInt status(KErrNone); |
|
454 if(iPrevEqualizerProxy) |
|
455 { |
|
456 TInt bands = iPrevEqualizerProxy->NumberOfBands(); |
|
457 for(TInt i = 1; i <= bands; i++) |
|
458 { |
|
459 TRAP(status , iEqualizerProxy->SetBandLevelL(i,iPrevEqualizerProxy->BandLevel(i))); |
|
460 } |
|
461 |
|
462 TBool enforce = iPrevEqualizerProxy->IsEnforced(); |
|
463 iEqualizerProxy->EnforceL(enforce); |
|
464 |
|
465 TBool enable = iPrevEqualizerProxy->IsEnabled(); |
|
466 if(enable) |
|
467 { |
|
468 iEqualizerProxy->EnableL(); |
|
469 } |
|
470 |
|
471 delete iPrevEqualizerProxy; |
|
472 iPrevEqualizerProxy = NULL; |
|
473 } |
|
474 return status; |
|
475 } |
|
476 |
|
477 void CEqualizerEffect::EffectChanged( const CAudioEffect* /*aObservedEffect*/, TUint8 aEvent ) |
|
478 { |
|
479 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
480 { |
|
481 iObservers[i]->Event(this,aEvent,NULL); |
|
482 } |
|
483 } |
|
484 |
|
485 // End of file |