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