|
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: Implementation of the Audio Equalizer effect class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #ifdef _DEBUG |
|
24 #include <e32svr.h> |
|
25 #endif |
|
26 |
|
27 #include <AudioEqualizerBase.h> |
|
28 #include <CustomInterfaceUtility.h> |
|
29 #include "AudioEqualizerProxy.h" |
|
30 #include <s32mem.h> |
|
31 #include <DrmAudioSamplePlayer.h> |
|
32 #include <mdaaudioinputstream.h> |
|
33 #include <mdaaudiooutputstream.h> |
|
34 #include <mdaaudiotoneplayer.h> |
|
35 #include <mmf/server/sounddevice.h> |
|
36 |
|
37 #ifdef _DEBUG |
|
38 #define DEBPRN0 RDebug::Printf( "%s", __PRETTY_FUNCTION__); |
|
39 #define DEBPRN1(str) RDebug::Printf( "%s %s", __PRETTY_FUNCTION__, str ); |
|
40 #else |
|
41 #define DEBPRN0 |
|
42 #define DEBPRN1(str) |
|
43 #endif |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CAudioEqualizer::CAudioEqualizer |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CAudioEqualizer::CAudioEqualizer() |
|
54 : iAudioEqualizerData(0, 0), |
|
55 iDataPckgTo(iAudioEqualizerData), |
|
56 iBandChange(0) |
|
57 { |
|
58 } |
|
59 |
|
60 // Destructor |
|
61 EXPORT_C CAudioEqualizer::~CAudioEqualizer() |
|
62 { |
|
63 delete iBandDataBuf; |
|
64 iBandsData.Close(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CAudioEqualizer::NewL |
|
69 // Static function for creating an instance of the AudioEqualizer object. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL() |
|
73 { |
|
74 User::Leave(KErrNotSupported); |
|
75 return NULL; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CAudioEqualizer::NewL |
|
80 // Static function for creating an instance of the AudioEqualizer object. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
84 CMdaAudioConvertUtility& aUtility ) |
|
85 { |
|
86 DEBPRN0; |
|
87 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility); |
|
88 CleanupStack::PushL(customInterface); |
|
89 |
|
90 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
91 |
|
92 if ( !audioEqualizerProxy ) |
|
93 { |
|
94 DEBPRN1("No Adaptation Support - leaving"); |
|
95 User::Leave(KErrNotSupported); |
|
96 } |
|
97 |
|
98 CleanupStack::Pop(customInterface); |
|
99 |
|
100 return audioEqualizerProxy; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CAudioEqualizer::NewL |
|
105 // Static function for creating an instance of the AudioEqualizer object. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
109 CMdaAudioInputStream& aUtility ) |
|
110 { |
|
111 DEBPRN0; |
|
112 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)aUtility.CustomInterface(KUidAudioEqualizerEffect); |
|
113 if (audioEqualizerProxy == NULL) |
|
114 { |
|
115 DEBPRN1("No Adaptation Support - leaving"); |
|
116 User::Leave(KErrNotSupported); |
|
117 } |
|
118 return audioEqualizerProxy; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CAudioEqualizer::NewL |
|
123 // Static function for creating an instance of the AudioEqualizer object. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
127 CMdaAudioOutputStream& aUtility ) |
|
128 { |
|
129 DEBPRN0; |
|
130 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)aUtility.CustomInterface(KUidAudioEqualizerEffect); |
|
131 if (audioEqualizerProxy == NULL) |
|
132 { |
|
133 DEBPRN1("No Adaptation Support - leaving"); |
|
134 User::Leave(KErrNotSupported); |
|
135 } |
|
136 return audioEqualizerProxy; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CAudioEqualizer::NewL |
|
141 // Static function for creating an instance of the AudioEqualizer object. |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
145 CMdaAudioPlayerUtility& aUtility ) |
|
146 { |
|
147 DEBPRN0; |
|
148 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility); |
|
149 CleanupStack::PushL(customInterface); |
|
150 |
|
151 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
152 |
|
153 if ( !audioEqualizerProxy ) |
|
154 { |
|
155 DEBPRN1("No Adaptation Support - leaving"); |
|
156 User::Leave(KErrNotSupported); |
|
157 } |
|
158 |
|
159 CleanupStack::Pop(customInterface); |
|
160 |
|
161 return audioEqualizerProxy; |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CAudioEqualizer::NewL |
|
166 // Static function for creating an instance of the AudioEqualizer object. |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
170 CMdaAudioRecorderUtility& aUtility, |
|
171 TBool aRecordStream ) |
|
172 { |
|
173 DEBPRN0; |
|
174 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility, aRecordStream); |
|
175 CleanupStack::PushL(customInterface); |
|
176 |
|
177 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
178 |
|
179 if ( !audioEqualizerProxy ) |
|
180 { |
|
181 DEBPRN1("No Adaptation Support - leaving"); |
|
182 User::Leave(KErrNotSupported); |
|
183 } |
|
184 |
|
185 CleanupStack::Pop(customInterface); |
|
186 |
|
187 return audioEqualizerProxy; |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CAudioEqualizer::NewL |
|
192 // Static function for creating an instance of the AudioEqualizer object. |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
196 CMdaAudioToneUtility& aUtility ) |
|
197 { |
|
198 DEBPRN0; |
|
199 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)aUtility.CustomInterface(KUidAudioEqualizerEffect); |
|
200 if (audioEqualizerProxy == NULL) |
|
201 { |
|
202 DEBPRN1("No Adaptation Support - leaving"); |
|
203 User::Leave(KErrNotSupported); |
|
204 } |
|
205 return audioEqualizerProxy; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CAudioEqualizer::NewL |
|
210 // Static function for creating an instance of the AudioEqualizer object. |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
214 CMMFDevSound& aDevSound ) |
|
215 { |
|
216 DEBPRN0; |
|
217 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)aDevSound.CustomInterface(KUidAudioEqualizerEffect); |
|
218 if (audioEqualizerProxy == NULL) |
|
219 { |
|
220 DEBPRN1("No Adaptation Support - leaving"); |
|
221 User::Leave(KErrNotSupported); |
|
222 } |
|
223 return audioEqualizerProxy; |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // CAudioEqualizer::NewL |
|
228 // Static function for creating an instance of the AudioEqualizer object. |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
232 CCustomCommandUtility* aUtility ) |
|
233 { |
|
234 DEBPRN0; |
|
235 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility); |
|
236 CleanupStack::PushL(customInterface); |
|
237 |
|
238 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
239 if ( !audioEqualizerProxy ) |
|
240 { |
|
241 DEBPRN1("No Adaptation Support - leaving"); |
|
242 User::Leave(KErrNotSupported); |
|
243 } |
|
244 |
|
245 CleanupStack::Pop(customInterface); |
|
246 |
|
247 return audioEqualizerProxy; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CAudioEqualizer::NewL |
|
252 // Static function for creating an instance of the AudioEqualizer object. |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
256 MCustomInterface& aCustomInterface ) |
|
257 { |
|
258 DEBPRN0; |
|
259 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)aCustomInterface.CustomInterface(KUidAudioEqualizerEffect); |
|
260 |
|
261 if ( !audioEqualizerProxy ) |
|
262 { |
|
263 DEBPRN1("No Adaptation Support - leaving"); |
|
264 User::Leave(KErrNotSupported); |
|
265 } |
|
266 |
|
267 return audioEqualizerProxy; |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CAudioEqualizer::NewL |
|
272 // Static function for creating an instance of the AudioEqualizer object. |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
276 CMidiClientUtility& aUtility ) |
|
277 { |
|
278 DEBPRN0; |
|
279 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility); |
|
280 CleanupStack::PushL(customInterface); |
|
281 |
|
282 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
283 |
|
284 if ( !audioEqualizerProxy ) |
|
285 { |
|
286 DEBPRN1("No Adaptation Support - leaving"); |
|
287 User::Leave(KErrNotSupported); |
|
288 } |
|
289 |
|
290 CleanupStack::Pop(customInterface); |
|
291 |
|
292 return audioEqualizerProxy; |
|
293 } |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CAudioEqualizer::NewL |
|
297 // Static function for creating an instance of the AudioEqualizer object. |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
301 CDrmPlayerUtility& aUtility ) |
|
302 { |
|
303 DEBPRN0; |
|
304 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility); |
|
305 CleanupStack::PushL(customInterface); |
|
306 |
|
307 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
308 |
|
309 if ( !audioEqualizerProxy ) |
|
310 { |
|
311 DEBPRN1("No Adaptation Support - leaving"); |
|
312 User::Leave(KErrNotSupported); |
|
313 } |
|
314 |
|
315 CleanupStack::Pop(customInterface); |
|
316 |
|
317 return audioEqualizerProxy; |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CAudioEqualizer::NewL |
|
322 // Static function for creating an instance of the AudioEqualizer object. |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C CAudioEqualizer* CAudioEqualizer::NewL( |
|
326 CVideoPlayerUtility& aUtility ) |
|
327 { |
|
328 DEBPRN0; |
|
329 CCustomInterfaceUtility* customInterface = CCustomInterfaceUtility::NewL(aUtility); |
|
330 CleanupStack::PushL(customInterface); |
|
331 |
|
332 CAudioEqualizerProxy* audioEqualizerProxy = (CAudioEqualizerProxy*)customInterface->CustomInterface(KUidAudioEqualizerEffect); |
|
333 |
|
334 if ( !audioEqualizerProxy ) |
|
335 { |
|
336 DEBPRN1("No Adaptation Support - leaving"); |
|
337 User::Leave(KErrNotSupported); |
|
338 } |
|
339 |
|
340 CleanupStack::Pop(customInterface); |
|
341 |
|
342 return audioEqualizerProxy; |
|
343 } |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CAudioEqualizer::BandLevel |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 EXPORT_C TInt32 CAudioEqualizer::BandLevel( |
|
349 TUint8 aBand ) const |
|
350 { |
|
351 if( aBand > NumberOfBands() ) |
|
352 { |
|
353 return KErrArgument; |
|
354 } |
|
355 else |
|
356 { |
|
357 return iBandsData[aBand-1].iBandLevel; |
|
358 } |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CAudioEqualizer::BandWidth |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 EXPORT_C TInt32 CAudioEqualizer::BandWidth( |
|
366 TUint8 aBand ) const |
|
367 { |
|
368 if( aBand > NumberOfBands() ) |
|
369 { |
|
370 return KErrArgument; |
|
371 } |
|
372 else |
|
373 { |
|
374 return iBandsData[aBand-1].iBandWidth; |
|
375 } |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // CAudioEqualizer::CenterFrequency |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 EXPORT_C TInt32 CAudioEqualizer::CenterFrequency( |
|
383 TUint8 aBand ) const |
|
384 { |
|
385 if( aBand > NumberOfBands() ) |
|
386 { |
|
387 return KErrArgument; |
|
388 } |
|
389 else |
|
390 { |
|
391 return iBandsData[aBand-1].iCenterFrequency; |
|
392 } |
|
393 } |
|
394 |
|
395 // ----------------------------------------------------------------------------- |
|
396 // CAudioEqualizer::CrossoverFrequency |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 EXPORT_C TInt32 CAudioEqualizer::CrossoverFrequency( |
|
400 TUint8 aBand ) const |
|
401 { |
|
402 if( aBand > NumberOfBands() ) |
|
403 { |
|
404 return KErrArgument; |
|
405 } |
|
406 else |
|
407 { |
|
408 return iBandsData[aBand-1].iCrossoverFrequency; |
|
409 } |
|
410 } |
|
411 |
|
412 // ----------------------------------------------------------------------------- |
|
413 // CAudioEqualizer::DbLevelLimits |
|
414 // ----------------------------------------------------------------------------- |
|
415 // |
|
416 EXPORT_C void CAudioEqualizer::DbLevelLimits( |
|
417 TInt32& aMin, |
|
418 TInt32& aMax ) |
|
419 { |
|
420 aMin = iAudioEqualizerData.iMindB; |
|
421 aMax = iAudioEqualizerData.iMaxdB; |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CAudioEqualizer::CrossoverFrequency |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 EXPORT_C TUint8 CAudioEqualizer::NumberOfBands() const |
|
429 |
|
430 { |
|
431 return iBandsData.Count(); |
|
432 } |
|
433 |
|
434 // ----------------------------------------------------------------------------- |
|
435 // CAudioEqualizer::SetBandLevelL |
|
436 // ----------------------------------------------------------------------------- |
|
437 // |
|
438 EXPORT_C void CAudioEqualizer::SetBandLevelL( |
|
439 TInt8 aBand, |
|
440 TInt32 aLevel ) |
|
441 { |
|
442 if( aBand > NumberOfBands() ) |
|
443 { |
|
444 User::Leave(KErrArgument); |
|
445 } |
|
446 else |
|
447 { |
|
448 TUint32 mask = 1; |
|
449 iBandChange = iBandChange | (mask << aBand-1); |
|
450 iBandsData[aBand-1].iBandLevel = aLevel; |
|
451 } |
|
452 } |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // CAudioEqualizer::Uid |
|
456 // ----------------------------------------------------------------------------- |
|
457 // |
|
458 EXPORT_C TUid CAudioEqualizer::Uid() const |
|
459 { |
|
460 return KUidAudioEqualizerEffect; |
|
461 } |
|
462 |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CAudioEqualizer::DoEffectData |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 EXPORT_C const TDesC8& CAudioEqualizer::DoEffectData() |
|
469 { |
|
470 DEBPRN0; |
|
471 iDataPckgTo = iAudioEqualizerData; |
|
472 return iDataPckgTo; |
|
473 } |
|
474 |
|
475 // ----------------------------------------------------------------------------- |
|
476 // CAudioEqualizer::SetEffectData |
|
477 // ----------------------------------------------------------------------------- |
|
478 // |
|
479 EXPORT_C void CAudioEqualizer::SetEffectData( |
|
480 const TDesC8& aEffectDataBuffer ) |
|
481 { |
|
482 DEBPRN0; |
|
483 TEfAudioEqualizerDataPckg dataPckg; |
|
484 dataPckg.Copy(aEffectDataBuffer); |
|
485 iAudioEqualizerData = dataPckg(); |
|
486 iEnabled = iAudioEqualizerData.iEnabled; |
|
487 iEnforced = iAudioEqualizerData.iEnforced; |
|
488 iHaveUpdateRights = iAudioEqualizerData.iHaveUpdateRights; |
|
489 } |
|
490 |
|
491 // ----------------------------------------------------------------------------- |
|
492 // CAudioEqualizer::DoBandData |
|
493 // ----------------------------------------------------------------------------- |
|
494 // |
|
495 EXPORT_C const TDesC8& CAudioEqualizer::DoBandDataL( |
|
496 TUint8 aBand, |
|
497 TBool aAllBands ) |
|
498 { |
|
499 |
|
500 DEBPRN0; |
|
501 if ( aAllBands ) |
|
502 { |
|
503 if ( iBandDataBuf ) |
|
504 { |
|
505 delete iBandDataBuf; |
|
506 iBandDataBuf = NULL; |
|
507 } |
|
508 |
|
509 iBandDataBuf = HBufC8::NewL(NumberOfBands() * sizeof(TEfAudioEqualizerBand)); |
|
510 TPtr8 des = iBandDataBuf->Des(); |
|
511 des.SetLength(iBandDataBuf->Size()); |
|
512 RDesWriteStream writeStream(des); |
|
513 |
|
514 for (TInt i=0; i<NumberOfBands(); i++) |
|
515 { |
|
516 writeStream << iBandsData[i]; |
|
517 } |
|
518 writeStream.CommitL(); |
|
519 return *iBandDataBuf; |
|
520 } |
|
521 else |
|
522 { |
|
523 if ( aBand > NumberOfBands() ) |
|
524 { |
|
525 User::Leave(KErrArgument); |
|
526 } |
|
527 iBandDataPckgTo = iBandsData[aBand-1]; |
|
528 return iBandDataPckgTo; |
|
529 } |
|
530 } |
|
531 |
|
532 // ----------------------------------------------------------------------------- |
|
533 // CAudioEqualizer::SetBandData |
|
534 // ----------------------------------------------------------------------------- |
|
535 // |
|
536 EXPORT_C void CAudioEqualizer::SetBandDataL( |
|
537 TInt aNumberOfBands, |
|
538 const TDesC8& aBandDataBuffer ) |
|
539 { |
|
540 DEBPRN0; |
|
541 if ( aNumberOfBands > 1 ) |
|
542 { |
|
543 RDesReadStream readStream(aBandDataBuffer); |
|
544 for (TInt i=0; i<NumberOfBands(); i++) |
|
545 { |
|
546 readStream >> iBandsData[i]; |
|
547 } |
|
548 } |
|
549 else |
|
550 { |
|
551 TEfAudioEqualizerBandDataPckg dataPckg; |
|
552 TEfAudioEqualizerBand band; |
|
553 dataPckg.Copy(aBandDataBuffer); |
|
554 band = dataPckg(); |
|
555 if ( band.iBandId > NumberOfBands() ) |
|
556 { |
|
557 User::Leave(KErrArgument); |
|
558 } |
|
559 iBandsData[band.iBandId-1] = band; |
|
560 } |
|
561 } |
|
562 |
|
563 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
564 |
|
565 |