|
1 /* |
|
2 * Copyright (c) 2005 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: Engine class that uses the Effects API and saves changes. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <centralrepository.h> |
|
21 #include <CustomCommandUtility.h> |
|
22 #include <mpxplaybackutility.h> |
|
23 #include <mpxplaybackmessage.h> |
|
24 |
|
25 #include <EnvironmentalReverbUtility.h> |
|
26 #include <EnvironmentalReverbUtilityData.h> |
|
27 #include <StereoWideningBase.h> |
|
28 #include <StereoWideningData.h> |
|
29 #include <BassBoostBase.h> |
|
30 #include <BassBoostData.h> |
|
31 #include <LoudnessBase.h> |
|
32 #include <LoudnessData.h> |
|
33 #include <AudioEqualizerUtility.h> |
|
34 #include <EqualizerConstants.h> |
|
35 #include <mpxlog.h> |
|
36 |
|
37 #include "mpxaudioeffectengine.h" |
|
38 |
|
39 // Music setting |
|
40 const TUid KCRUidMPXMPSettings = {0x101FFCDC}; |
|
41 const TUint32 KMPXMPEqPresetId = 0x00000001; |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMPXAudioEffectEngine::NewL() |
|
47 // Standard 2-Phased Constructor |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CMPXAudioEffectEngine* CMPXAudioEffectEngine::NewL( |
|
51 CMdaAudioPlayerUtility* aPlayer ) |
|
52 { |
|
53 CMPXAudioEffectEngine* self = new( ELeave ) CMPXAudioEffectEngine( aPlayer ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CMPXAudioEffectEngine::CMPXAudioEffectEngine() |
|
62 // Constructor |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CMPXAudioEffectEngine::CMPXAudioEffectEngine(CMdaAudioPlayerUtility* aPlayer) |
|
66 :iMdaPlayer(aPlayer) |
|
67 { |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CMPXAudioEffectEngine::~CMPXAudioEffectEngine() |
|
72 // Virtual destructor |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CMPXAudioEffectEngine::~CMPXAudioEffectEngine() |
|
76 { |
|
77 if (iProp) |
|
78 { |
|
79 delete iProp; |
|
80 } |
|
81 DestroyAudioEffect(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CMPXAudioEffectEngine::ConstructL() |
|
86 // Standard Second Phased Constructor |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CMPXAudioEffectEngine::ConstructL() |
|
90 { |
|
91 iProp = new(ELeave) CMPXAudioEffectProperties(); |
|
92 MPX_TRAPD( err, iProp->LoadFromFileL() ); //Loads saved settings if available |
|
93 if( err != KErrNone ) |
|
94 { |
|
95 MPX_DEBUG1("CMPXAudioEffectEngine::ConstructL -- reset save to file"); |
|
96 iProp->Reset(); |
|
97 iProp->SaveToFileL(); |
|
98 } |
|
99 } |
|
100 |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CMPXAudioEffectEngine::SetBalanceL() |
|
104 // (other items were commented in a header). |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 EXPORT_C void CMPXAudioEffectEngine::SetBalanceL() |
|
108 { |
|
109 iProp->LoadFromFileL(); |
|
110 if(iMdaPlayer) |
|
111 { |
|
112 if(iMdaPlayer->SetBalance(iProp->Balance())!=KErrNone) |
|
113 { |
|
114 User::Leave(KErrNotSupported); |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CMPXAudioEffectEngine::SetReverberationL() |
|
122 // (other items were commented in a header). |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 EXPORT_C void CMPXAudioEffectEngine::SetReverberationL() |
|
126 { |
|
127 #ifdef _REVERB |
|
128 if(!iReverbEffect) |
|
129 { |
|
130 //Effect enabled immediately, cmdUtil ownership passed into new object |
|
131 MPX_TRAPD(error, iReverbEffect = |
|
132 CEnvironmentalReverbUtility::NewL(*iMdaPlayer)); |
|
133 if(!error) |
|
134 { |
|
135 SetReverberationL(); |
|
136 } |
|
137 } |
|
138 |
|
139 iProp->LoadFromFileL(); |
|
140 |
|
141 TBuf16<32> reverbation; |
|
142 TBuf16<32> reverbation2; |
|
143 |
|
144 switch( iProp->Reverb() ) //aIndex ranges always from 0 to 7 |
|
145 { |
|
146 case 1: _LIT( KRevName, "Alley" ); |
|
147 reverbation.Append( KRevName ); |
|
148 break; |
|
149 case 2: _LIT( KRevName2, "Bathroom" ); |
|
150 reverbation.Append( KRevName2 ); |
|
151 break; |
|
152 case 3: _LIT( KRevName3, "Underwater" ); |
|
153 reverbation.Append( KRevName3 ); |
|
154 break; |
|
155 case 4: _LIT( KRevName4, "Small room" ); |
|
156 reverbation.Append( KRevName4 ); |
|
157 break; |
|
158 case 5: _LIT( KRevName5, "Medium room" ); |
|
159 reverbation.Append( KRevName5 ); |
|
160 break; |
|
161 case 6: _LIT( KRevName6, "Large room" ); |
|
162 reverbation.Append( KRevName6 ); |
|
163 break; |
|
164 case 7: _LIT( KRevName7, "Large hall" ); |
|
165 reverbation.Append( KRevName7 ); |
|
166 break; |
|
167 default: break; |
|
168 } |
|
169 TUint32 count; |
|
170 count = iReverbEffect->NumberOfPreDefinedPresets(); |
|
171 TArray<TEfEnvironmentalReverbUtilityPreset> array = iReverbEffect->Presets(); |
|
172 |
|
173 if( 0 != iProp->Reverb() ) |
|
174 { |
|
175 TInt i = 0; |
|
176 |
|
177 do //compare descriptors and apply preset if descriptors match |
|
178 { |
|
179 reverbation2.Copy( array[i].iPresetName ); |
|
180 if( reverbation2.Compare(reverbation) == 0 ) |
|
181 { |
|
182 iReverbEffect->ApplyPresetL( i ); |
|
183 i = count; |
|
184 } |
|
185 i++; |
|
186 }while( i < count ); |
|
187 } |
|
188 else |
|
189 { |
|
190 iReverbEffect->DisableEnvironmentalReverbL(); |
|
191 } |
|
192 #endif |
|
193 } |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CMPXAudioEffectEngine::SetStereoWideningL() |
|
198 // (other items were commented in a header). |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 EXPORT_C void CMPXAudioEffectEngine::SetStereoWideningL() |
|
202 { |
|
203 #ifdef _STEREO |
|
204 iProp->LoadFromFileL(); |
|
205 |
|
206 if(iProp->Stereo()) |
|
207 { |
|
208 if(!iStereoEffect) // If stereo widening is ON and not constructed |
|
209 { |
|
210 TUint stereoLevel = 100; |
|
211 // cmdUtil ownership passed into new object |
|
212 MPX_TRAPD(error, |
|
213 iStereoEffect = CStereoWidening::NewL(*iMdaPlayer, |
|
214 EFalse, stereoLevel)); |
|
215 if(error) |
|
216 { |
|
217 iStereoEffect = NULL; |
|
218 User::Leave(KErrNotSupported); |
|
219 } |
|
220 } |
|
221 |
|
222 iStereoEffect->EnableL(); |
|
223 TUint8 level = 100; |
|
224 iStereoEffect->SetStereoWideningLevelL( level ); |
|
225 iStereoEffect->ApplyL(); |
|
226 } |
|
227 else |
|
228 { |
|
229 if (iStereoEffect) // If audio effects was not on, then no need to disable |
|
230 { |
|
231 iStereoEffect->DisableL(); |
|
232 } |
|
233 } |
|
234 #endif |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // CMPXAudioEffectEngine::SetBassBoostL() |
|
239 // (other items were commented in a header). |
|
240 // ----------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CMPXAudioEffectEngine::SetBassBoostL() |
|
243 { |
|
244 #ifdef _BASSBOOST |
|
245 iProp->LoadFromFileL(); |
|
246 if(iProp->BassBoost()) |
|
247 { |
|
248 if (!iBassBoostEffect) |
|
249 { |
|
250 // cmdUtil ownership passed into new object |
|
251 MPX_TRAPD(error, |
|
252 iBassBoostEffect = CBassBoost::NewL(*iMdaPlayer, |
|
253 iProp->BassBoost())); |
|
254 if (error) |
|
255 { |
|
256 User::Leave(KErrNotSupported); |
|
257 } |
|
258 } |
|
259 iBassBoostEffect->EnableL(); |
|
260 } |
|
261 else |
|
262 { |
|
263 if (iBassBoostEffect) |
|
264 { |
|
265 iBassBoostEffect->DisableL(); |
|
266 } |
|
267 } |
|
268 #endif |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CMPXAudioEffectEngine::SetLoudnessL() |
|
273 // (other items were commented in a header). |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 EXPORT_C void CMPXAudioEffectEngine::SetLoudnessL() |
|
277 { |
|
278 #ifdef _LOUDNESS |
|
279 iProp->LoadFromFileL(); |
|
280 if(iProp->Loudness()) |
|
281 { |
|
282 if(!iLoudnessEffect) |
|
283 { |
|
284 // cmdUtil ownership passed into new object |
|
285 MPX_TRAPD(error, |
|
286 iLoudnessEffect = CLoudness::NewL(*iMdaPlayer, |
|
287 iProp->Loudness())); |
|
288 if(error) |
|
289 { |
|
290 iLoudnessEffect = NULL; |
|
291 User::Leave(KErrNotSupported); |
|
292 } |
|
293 else |
|
294 { |
|
295 } |
|
296 } |
|
297 |
|
298 iLoudnessEffect->EnableL(); |
|
299 } |
|
300 else |
|
301 { |
|
302 if( iLoudnessEffect ) // Only disable if it was constructed |
|
303 { |
|
304 iLoudnessEffect->DisableL(); |
|
305 } |
|
306 } |
|
307 #endif |
|
308 } |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // Sets the equalizer |
|
312 // (other items were commented in a header). |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 EXPORT_C void CMPXAudioEffectEngine::SetEqualizerL() |
|
316 { |
|
317 MPX_DEBUG1("CMPXAudioEffectEngine::SetEqualizerL <--"); |
|
318 |
|
319 // Create the effect |
|
320 // |
|
321 if( !iEqualizerEffect ) |
|
322 { |
|
323 iEqualizerEffect = CAudioEqualizerUtility::NewL(*iMdaPlayer); |
|
324 } |
|
325 |
|
326 // Get equalizer preset id from cenrep |
|
327 // |
|
328 TInt presetId( KEqualizerPresetNone ); |
|
329 TRAP_IGNORE( |
|
330 { |
|
331 CRepository* repository = CRepository::NewL( KCRUidMPXMPSettings ); |
|
332 repository->Get( KMPXMPEqPresetId, presetId ); |
|
333 delete repository; |
|
334 repository = NULL; |
|
335 } ); |
|
336 |
|
337 // Translate preset ID to index |
|
338 // |
|
339 MPX_DEBUG1("CMPXAudioEffectEngine::SetEqualizerL = finding preset index"); |
|
340 |
|
341 TInt index( KErrNotFound ); |
|
342 if ( iEqualizerEffect && presetId != KEqualizerPresetNone ) |
|
343 { |
|
344 TArray<TEfAudioEqualizerUtilityPreset> presetArray = |
|
345 iEqualizerEffect->Presets(); |
|
346 |
|
347 TBool found( EFalse ); |
|
348 for ( TInt i = 0; i < presetArray.Count() && found == EFalse; i++ ) |
|
349 { |
|
350 if ( presetArray[i].iPresetNameKey == |
|
351 static_cast<TUint32>( presetId ) ) |
|
352 { |
|
353 found = ETrue; |
|
354 index = i; |
|
355 } |
|
356 } |
|
357 } |
|
358 MPX_DEBUG2("CMPXAudioEffectEngine::SetEqualizerL effect index: %i", index); |
|
359 |
|
360 // Apply preset index index or disable if not found |
|
361 // |
|
362 if ( KErrNotFound != index ) |
|
363 { |
|
364 iEqualizerEffect->ApplyPresetL( index ); |
|
365 } |
|
366 else |
|
367 { |
|
368 iEqualizerEffect->DisableEqualizerL(); |
|
369 } |
|
370 |
|
371 MPX_DEBUG1("CMPXAudioEffectEngine::SetEqualizerL -->"); |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // CreateAudioEffectsL |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 EXPORT_C void CMPXAudioEffectEngine::CreateAudioEffectsL() |
|
379 { |
|
380 SetEqualizerL(); |
|
381 SetStereoWideningL(); |
|
382 SetBalanceL(); |
|
383 SetLoudnessL(); |
|
384 } |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // Destroy audio effect |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 EXPORT_C void CMPXAudioEffectEngine::DestroyAudioEffect() |
|
391 { |
|
392 if (iReverbEffect) |
|
393 { |
|
394 delete iReverbEffect; //effect automatically disabled |
|
395 iReverbEffect = NULL; |
|
396 } |
|
397 |
|
398 if (iStereoEffect) |
|
399 { |
|
400 delete iStereoEffect; //effect automatically disabled |
|
401 iStereoEffect = NULL; |
|
402 } |
|
403 if (iBassBoostEffect) |
|
404 { |
|
405 delete iBassBoostEffect; //effect automatically disabled |
|
406 iBassBoostEffect = NULL; |
|
407 } |
|
408 if (iLoudnessEffect) |
|
409 { |
|
410 delete iLoudnessEffect; //effect automatically disabled |
|
411 iLoudnessEffect = NULL; |
|
412 } |
|
413 if (iEqualizerEffect) |
|
414 { |
|
415 delete iEqualizerEffect; //effect automatically disabled |
|
416 iEqualizerEffect = NULL; |
|
417 } |
|
418 } |
|
419 |
|
420 //End of File |