|
1 /* |
|
2 * Copyright (c) 2010 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: Audio player implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include <utf.h> // For converting data for TTS |
|
21 #include "tmsshared.h" |
|
22 #include "tmsutility.h" |
|
23 #include "tmsrtaudiohdlr.h" |
|
24 #include "tmsrtcontainer.h" |
|
25 #include "tmsrtaudiohdlrobsrv.h" |
|
26 |
|
27 using namespace TMS; |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KMinVolumeLevel = 1; |
|
31 const TInt KMaxVolumeLevel = 10; |
|
32 const TInt KTMSRingingRepeatsTrailPause = 1000000; |
|
33 const TInt KTMSAudioAscendingRampDuration = 3000000; |
|
34 const TInt KTMSMdaAudioToneRepeatForever = -2; |
|
35 const TInt KUTF8Multiply = 2; |
|
36 |
|
37 _LIT(KFileListRngMimeType, "application/vnd.nokia.ringing-tone"); |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // TMSRtAudioHdlr::TMSRtAudioHdlr |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 TMSRtAudioHdlr::TMSRtAudioHdlr(TAudioDataFormat aDataFormat, |
|
44 TMSRtAudioHdlrObsrv& aObserver, TUint aPriority, TUint aPreference, |
|
45 TInt aType) : |
|
46 iFormat(aDataFormat), |
|
47 iObserver(aObserver), |
|
48 iPriority(aPriority), |
|
49 iPreference(aPreference), |
|
50 iRtType(aType) |
|
51 { |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TMSRtAudioHdlr::ConstructL |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void TMSRtAudioHdlr::ConstructL(const TDesC& aFileName) |
|
59 { |
|
60 TRACE_PRN_FN_ENT; |
|
61 if (iFormat == EFormatTone) |
|
62 { |
|
63 iTonePlayer = CMdaAudioToneUtility::NewL(*this); |
|
64 iTonePlayer->PrepareToPlayFileSequence(aFileName); |
|
65 iPlayerStatus = EToneLoading; |
|
66 } |
|
67 else |
|
68 { |
|
69 iSamplePlayer = CMdaAudioPlayerUtility::NewFilePlayerL(aFileName, *this, |
|
70 iPriority, iPreference); |
|
71 iPlayerStatus = EToneLoading; |
|
72 } |
|
73 TRACE_PRN_FN_EXT; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // TMSRtAudioHdlr::ConstructSeqL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void TMSRtAudioHdlr::ConstructSeqL(const TDesC8& aSequence) |
|
81 { |
|
82 TRACE_PRN_FN_ENT; |
|
83 iTonePlayer = CMdaAudioToneUtility::NewL(*this); |
|
84 iSequence = aSequence.AllocL(); |
|
85 iTonePlayer->PrepareToPlayDesSequence(*iSequence); |
|
86 iPlayerStatus = EToneLoading; |
|
87 TRACE_PRN_FN_EXT; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // TMSRtAudioHdlr::ConstructTtsL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void TMSRtAudioHdlr::ConstructTtsL(const TDesC& aTtsText, TUint aPriority, |
|
95 TUint aPreference) |
|
96 { |
|
97 TRACE_PRN_FN_ENT; |
|
98 delete iTtsPlayer; |
|
99 iTtsPlayer = NULL; |
|
100 iTtsPlayer = CMdaAudioPlayerUtility::NewL(*this, aPriority, aPreference); |
|
101 |
|
102 delete iTtsText; |
|
103 iTtsText = NULL; |
|
104 // UTF-8 strings can take up to 4 bytes per character |
|
105 iTtsText = HBufC8::NewL(aTtsText.Length() << KUTF8Multiply); |
|
106 |
|
107 TPtr8 refText = iTtsText->Des(); |
|
108 User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(refText, |
|
109 aTtsText)); |
|
110 |
|
111 // UTF-8 chars can be up to 4 bytes long, but usually |
|
112 // take 1-2 bytes, 3 for asian chars. |
|
113 HBufC8* oldText = iTtsText; |
|
114 iTtsText = iTtsText->ReAlloc(iTtsText->Length()); |
|
115 if (!iTtsText) |
|
116 { |
|
117 // ReAlloc failed, set back to original. |
|
118 iTtsText = oldText; |
|
119 } |
|
120 iTtsPlayer->OpenDesL(*iTtsText); |
|
121 TRACE_PRN_FN_EXT; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // TMSRtAudioHdlr::NewL |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 TMSRtAudioHdlr* TMSRtAudioHdlr::NewL(const TMSRtContainer& aRingingTone, |
|
129 TUint aPriority, TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, |
|
130 TInt aType, TBool aExtSecNeeded) |
|
131 { |
|
132 TRACE_PRN_FN_ENT; |
|
133 // Check file DRM property if extended security is needed. |
|
134 if (aExtSecNeeded) |
|
135 { |
|
136 if (!aRingingTone.IsFileInRom() && !aRingingTone.IsFileDrmProtected()) |
|
137 { |
|
138 // DRM extended security check permission denied |
|
139 User::Leave(KErrPermissionDenied); |
|
140 } |
|
141 // DRM extended security check ok |
|
142 } |
|
143 |
|
144 // RNG file types have to be played with CMdaAudioToneUtility player. |
|
145 // Other audio formats use sample player |
|
146 TAudioDataFormat format = (aRingingTone.MimeType().CompareF( |
|
147 KFileListRngMimeType) == KErrNone) ? EFormatTone : EFormatSample; |
|
148 |
|
149 TMSRtAudioHdlr* self = new (ELeave) TMSRtAudioHdlr(format, aObserver, |
|
150 aPriority, aPreference, aType); |
|
151 CleanupStack::PushL(self); |
|
152 self->ConstructL(aRingingTone.FileName()); |
|
153 CleanupStack::Pop(self); |
|
154 TRACE_PRN_FN_EXT; |
|
155 return self; |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // TMSRtAudioHdlr::NewL |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 TMSRtAudioHdlr* TMSRtAudioHdlr::NewL(const TDesC& aFileName, TUint aPriority, |
|
163 TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, TInt aType, |
|
164 TBool aExtSecNeeded) |
|
165 { |
|
166 TRACE_PRN_FN_ENT; |
|
167 TMSRtContainer* tone = TMSRtContainer::NewL(aFileName); |
|
168 CleanupStack::PushL(tone); |
|
169 TMSRtAudioHdlr* player = TMSRtAudioHdlr::NewL(*tone, aPriority, aPreference, |
|
170 aObserver, aType, aExtSecNeeded); |
|
171 CleanupStack::PopAndDestroy(tone); |
|
172 TRACE_PRN_FN_EXT; |
|
173 return player; |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // TMSRtAudioHdlr::NewSeqL |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 TMSRtAudioHdlr* TMSRtAudioHdlr::NewSeqL(const TDesC8& aSequence, |
|
181 TUint aPriority, TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, |
|
182 TInt aType) |
|
183 { |
|
184 TRACE_PRN_FN_ENT; |
|
185 TMSRtAudioHdlr* self = new (ELeave) TMSRtAudioHdlr(EFormatTone, |
|
186 aObserver, aPriority, aPreference, aType); |
|
187 CleanupStack::PushL(self); |
|
188 self->ConstructSeqL(aSequence); |
|
189 CleanupStack::Pop(self); |
|
190 TRACE_PRN_FN_EXT; |
|
191 return self; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // TMSRtAudioHdlr::NewTtsL |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 TMSRtAudioHdlr* TMSRtAudioHdlr::NewTtsL(const TDesC& aText, TUint aPriority, |
|
199 TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, TInt aType) |
|
200 { |
|
201 TRACE_PRN_FN_ENT; |
|
202 TMSRtAudioHdlr* self = new (ELeave) TMSRtAudioHdlr(EFormatTts, aObserver, |
|
203 aPriority, aPreference, aType); |
|
204 CleanupStack::PushL(self); |
|
205 self->ConstructTtsL(aText, aPriority, aPreference); |
|
206 CleanupStack::Pop(self); |
|
207 TRACE_PRN_FN_EXT; |
|
208 return self; |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // TMSRtAudioHdlr::~TMSRtAudioHdlr |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 TMSRtAudioHdlr::~TMSRtAudioHdlr() |
|
216 { |
|
217 TRACE_PRN_FN_ENT; |
|
218 /*if (i3DPlugin) |
|
219 { |
|
220 i3DPlugin->Stop(); |
|
221 } |
|
222 delete i3DPlugin; |
|
223 delete iAudioOutput;*/ |
|
224 delete iTonePlayer; |
|
225 delete iSamplePlayer; |
|
226 delete iTtsPlayer; |
|
227 delete iSequence; |
|
228 delete iTtsText; |
|
229 REComSession::FinalClose(); |
|
230 TRACE_PRN_FN_EXT; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // TMSRtAudioHdlr::Play |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void TMSRtAudioHdlr::Play(TRingingType aRingType, TInt aVolume, |
|
238 TInt aTTsToBePlayed) |
|
239 { |
|
240 TRACE_PRN_FN_ENT; |
|
241 iRingType = aRingType; |
|
242 iVolume = aVolume; |
|
243 iTTsToBePlayed = aTTsToBePlayed; |
|
244 |
|
245 if (iFormat == EFormatTone) |
|
246 { |
|
247 switch (iPlayerStatus) |
|
248 { |
|
249 case ETonePlaying: |
|
250 iTonePlayer->CancelPlay(); |
|
251 DoPlay(); |
|
252 break; |
|
253 case EToneReady: |
|
254 iPlayerStatus = ETonePlaying; |
|
255 DoPlay(); |
|
256 break; |
|
257 case EToneLoading: |
|
258 iToBePlaying = ETrue; |
|
259 break; |
|
260 default: |
|
261 __ASSERT_DEBUG(EFalse, |
|
262 User::Panic(KTMSPanic, TMS_RESULT_DOES_NOT_EXIST)); |
|
263 break; |
|
264 } |
|
265 } |
|
266 else if (iFormat == EFormatTts) |
|
267 { |
|
268 switch (iPlayerStatus) |
|
269 { |
|
270 case ETonePlaying: |
|
271 iTtsPlayer->Stop(); |
|
272 DoPlay(); |
|
273 break; |
|
274 case EToneReady: |
|
275 iPlayerStatus = ETonePlaying; |
|
276 DoPlay(); |
|
277 break; |
|
278 case EToneLoading: |
|
279 iToBePlaying = ETrue; |
|
280 break; |
|
281 default: |
|
282 __ASSERT_DEBUG(EFalse, |
|
283 User::Panic(KTMSPanic, TMS_RESULT_DOES_NOT_EXIST)); |
|
284 break; |
|
285 } |
|
286 } |
|
287 else |
|
288 { |
|
289 switch (iPlayerStatus) |
|
290 { |
|
291 case ETonePlaying: |
|
292 StopPlaying(); |
|
293 iPlayerStatus = ETonePlaying; |
|
294 DoPlay(); |
|
295 break; |
|
296 case EToneReady: |
|
297 iPlayerStatus = ETonePlaying; |
|
298 DoPlay(); |
|
299 break; |
|
300 case EToneLoading: |
|
301 iToBePlaying = ETrue; |
|
302 break; |
|
303 default: |
|
304 __ASSERT_DEBUG(EFalse, |
|
305 User::Panic(KTMSPanic, TMS_RESULT_DOES_NOT_EXIST)); |
|
306 break; |
|
307 } |
|
308 } |
|
309 TRACE_PRN_FN_EXT; |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // TMSRtAudioHdlr::ReStartPlaying |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void TMSRtAudioHdlr::ReStartPlaying() |
|
317 { |
|
318 TRACE_PRN_FN_ENT; |
|
319 if (iFormat == EFormatTone) |
|
320 { |
|
321 iTonePlayer->Play(); |
|
322 iPlayerStatus = ETonePlaying; |
|
323 } |
|
324 else if (iFormat == EFormatTts) |
|
325 { |
|
326 iTtsPlayer->Play(); |
|
327 iPlayerStatus = ETonePlaying; |
|
328 } |
|
329 else |
|
330 { |
|
331 iSamplePlayer->Play(); |
|
332 iPlayerStatus = ETonePlaying; |
|
333 } |
|
334 TRACE_PRN_FN_EXT; |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // TMSRtAudioHdlr::StopPlaying |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 void TMSRtAudioHdlr::StopPlaying() |
|
342 { |
|
343 TRACE_PRN_FN_ENT; |
|
344 iToBePlaying = EFalse; |
|
345 |
|
346 if (iFormat == EFormatTone) |
|
347 { |
|
348 if (EMdaAudioToneUtilityPrepared == iTonePlayer->State()) |
|
349 { |
|
350 iTonePlayer->CancelPrepare(); |
|
351 } |
|
352 else if (EMdaAudioToneUtilityPlaying == iTonePlayer->State()) |
|
353 { |
|
354 iTonePlayer->CancelPlay(); |
|
355 } |
|
356 } |
|
357 else if (iFormat == EFormatTts) |
|
358 { |
|
359 iTtsPlayer->Stop(); |
|
360 } |
|
361 else |
|
362 { |
|
363 /* if (i3DPlugin) |
|
364 { |
|
365 i3DPlugin->Stop(); |
|
366 delete i3DPlugin; |
|
367 i3DPlugin = NULL; |
|
368 } |
|
369 else |
|
370 {*/ |
|
371 iSamplePlayer->Stop(); |
|
372 /* }*/ |
|
373 } |
|
374 iPlayerStatus = EToneReady; |
|
375 TRACE_PRN_FN_EXT; |
|
376 } |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // TMSRtAudioHdlr::MapcInitComplete |
|
380 // ----------------------------------------------------------------------------- |
|
381 // |
|
382 void TMSRtAudioHdlr::MapcInitComplete(TInt aError, |
|
383 const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
384 { |
|
385 TRACE_PRN_N2( |
|
386 _L("TMS->TMSRtAudioHdlr::MapcInitComplete: player[%d], err[%d]"), |
|
387 iRtType, aError); |
|
388 |
|
389 __ASSERT_DEBUG((iFormat == EFormatSample) || |
|
390 ((iFormat == EFormatTts) && (iPlayerStatus == EToneLoading)), |
|
391 PANIC(TMS_RESULT_INVALID_STATE)); |
|
392 |
|
393 if (aError == TMS_RESULT_SUCCESS) |
|
394 { |
|
395 if (iToBePlaying) |
|
396 { |
|
397 iPlayerStatus = ETonePlaying; |
|
398 iToBePlaying = EFalse; |
|
399 DoPlay(); |
|
400 } |
|
401 else |
|
402 { |
|
403 iPlayerStatus = EToneReady; |
|
404 } |
|
405 } |
|
406 iObserver.RtAudioHdlrEvent(ECmdRingToneOpenComplete, aError, iRtType); |
|
407 } |
|
408 |
|
409 // ----------------------------------------------------------------------------- |
|
410 // TMSRtAudioHdlr::MapcPlayComplete |
|
411 // ----------------------------------------------------------------------------- |
|
412 // |
|
413 void TMSRtAudioHdlr::MapcPlayComplete(TInt aError) |
|
414 { |
|
415 TRACE_PRN_N2( |
|
416 _L("TMS->TMSRtAudioHdlr::MapcPlayComplete: player[%d], err[%d]"), |
|
417 iRtType, aError); |
|
418 |
|
419 iPlayerStatus = EToneReady; |
|
420 |
|
421 // Delete 3D plugin before RT player. In case of continuous ringing type, |
|
422 // 3D plugin is destructed in StopPlaying(). |
|
423 /* if (i3DPlugin) |
|
424 { |
|
425 i3DPlugin->Stop(); |
|
426 delete i3DPlugin; |
|
427 i3DPlugin = NULL; |
|
428 }*/ |
|
429 iObserver.RtAudioHdlrEvent(ECmdRingTonePlayComplete, aError, iRtType); |
|
430 } |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // TMSRtAudioHdlr::MatoPrepareComplete |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 void TMSRtAudioHdlr::MatoPrepareComplete(TInt aError) |
|
437 { |
|
438 TRACE_PRN_N2( |
|
439 _L("TMS->TMSRtAudioHdlr::MatoPrepareComplete: player[%d], err[%d]"), |
|
440 iRtType, aError); |
|
441 |
|
442 __ASSERT_DEBUG(((iFormat == EFormatTone) && |
|
443 (iPlayerStatus == EToneLoading)), PANIC(TMS_RESULT_INVALID_STATE)); |
|
444 |
|
445 if (aError == TMS_RESULT_SUCCESS) |
|
446 { |
|
447 if (iToBePlaying) |
|
448 { |
|
449 iPlayerStatus = ETonePlaying; |
|
450 iToBePlaying = EFalse; |
|
451 DoPlay(); |
|
452 } |
|
453 else |
|
454 { |
|
455 iPlayerStatus = EToneReady; |
|
456 } |
|
457 } |
|
458 iObserver.RtAudioHdlrEvent(ECmdRingToneOpenComplete, aError, iRtType); |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // TMSRtAudioHdlr::MatoPlayComplete |
|
463 // ----------------------------------------------------------------------------- |
|
464 // |
|
465 void TMSRtAudioHdlr::MatoPlayComplete(TInt aError) |
|
466 { |
|
467 TRACE_PRN_N2( |
|
468 _L("TMS->TMSRtAudioHdlr::MatoPlayComplete: player[%d], err[%d]"), |
|
469 iRtType, aError); |
|
470 |
|
471 iObserver.RtAudioHdlrEvent(ECmdRingTonePlayComplete, aError, iRtType); |
|
472 } |
|
473 |
|
474 // ----------------------------------------------------------------------------- |
|
475 // TMSRtAudioHdlr::DoPlay |
|
476 // ----------------------------------------------------------------------------- |
|
477 // |
|
478 void TMSRtAudioHdlr::DoPlay() |
|
479 { |
|
480 TRACE_PRN_FN_ENT; |
|
481 |
|
482 __ASSERT_DEBUG(iPlayerStatus == ETonePlaying, |
|
483 PANIC(TMS_RESULT_INVALID_STATE)); |
|
484 |
|
485 //TInt err(TMS_RESULT_SUCCESS); |
|
486 SetRingingTypeProperties(); |
|
487 |
|
488 if (iFormat == EFormatTone) |
|
489 { |
|
490 iTonePlayer->Play(); |
|
491 } |
|
492 else if (iFormat == EFormatTts) |
|
493 { |
|
494 iTtsPlayer->Play(); |
|
495 } |
|
496 else |
|
497 { |
|
498 #ifdef __WINS__ |
|
499 iSamplePlayer->Play(); |
|
500 #else |
|
501 /* |
|
502 //TODO: compare with phoneapp |
|
503 TInt err = KErrNone; |
|
504 TRAP(err, i3DPlugin = C3DRingingToneInterface::NewL(KNullUid)); |
|
505 if (!err && i3DPlugin) |
|
506 { |
|
507 i3DPlugin->SetAttr(E3DRTIAttrAudioPlayerUtility, iSamplePlayer); |
|
508 TRAP(err, i3DPlugin->PlayL()) |
|
509 } |
|
510 if (err || !i3DPlugin) |
|
511 { |
|
512 if (!iAudioOutput) |
|
513 { |
|
514 TRAP(err, iAudioOutput = CAudioOutput::NewL(*iSamplePlayer)); |
|
515 } |
|
516 if (!err && iAudioOutput) |
|
517 { |
|
518 TRAP(err, iAudioOutput->SetAudioOutputL(CAudioOutput::EAll)); |
|
519 } |
|
520 }*/ |
|
521 iSamplePlayer->Play(); |
|
522 #endif //__WINS__ |
|
523 } |
|
524 |
|
525 TRACE_PRN_FN_EXT; |
|
526 } |
|
527 |
|
528 // ----------------------------------------------------------------------------- |
|
529 // TMSRtAudioHdlr::SetRingingTypeProperties |
|
530 // ----------------------------------------------------------------------------- |
|
531 // |
|
532 void TMSRtAudioHdlr::SetRingingTypeProperties() |
|
533 { |
|
534 TInt rampTime(0); |
|
535 if (iFormat == EFormatTone) |
|
536 { |
|
537 switch (iRingType) |
|
538 { |
|
539 case ETypeRinging: |
|
540 { |
|
541 // If we have TTS activated and ringing type is "ringing", then |
|
542 // we need to play TTS sequence again when ringtone restarts. |
|
543 // That's why we need to set ringing type to ETypeRingingOnce, |
|
544 // because it is the only way of knowing when ringtone playback |
|
545 // is completed. Then we can restart it with new TTS iterations. |
|
546 if (iTTsToBePlayed) |
|
547 { |
|
548 // Play only once |
|
549 iTonePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
550 KTMSRingingRepeatsTrailPause)); |
|
551 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
552 } |
|
553 else |
|
554 { |
|
555 iTonePlayer->SetRepeats(KTMSMdaAudioToneRepeatForever, |
|
556 TTimeIntervalMicroSeconds( |
|
557 KTMSRingingRepeatsTrailPause)); |
|
558 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
559 } |
|
560 break; |
|
561 } |
|
562 case ETypeRingingOnce: |
|
563 { |
|
564 // Play only once |
|
565 iTonePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
566 KTMSRingingRepeatsTrailPause)); |
|
567 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
568 break; |
|
569 } |
|
570 case ETypeAscending: |
|
571 { |
|
572 iTonePlayer->SetRepeats(KTMSMdaAudioToneRepeatForever, |
|
573 TTimeIntervalMicroSeconds( |
|
574 KTMSRingingRepeatsTrailPause)); |
|
575 |
|
576 // Special case for TTS + ascending profile. Volume and |
|
577 // ramptime need to be different then usual |
|
578 if (iTTsToBePlayed) |
|
579 { |
|
580 // RampTime is only 3 seconds and volume is 1. |
|
581 rampTime = KTMSAudioAscendingRampDuration; |
|
582 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
583 rampTime)); |
|
584 iCurrentVolume = 1; //we start from the lowest volume |
|
585 iTonePlayer->SetVolume(ConvertVolume(iCurrentVolume)); |
|
586 } |
|
587 else |
|
588 { |
|
589 // RampTime: time for one step * volume level |
|
590 rampTime = KTMSAudioAscendingRampDuration * iVolume; |
|
591 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
592 rampTime)); |
|
593 iCurrentVolume = 1; //we start from the lowest volume |
|
594 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
595 } |
|
596 break; |
|
597 } |
|
598 default: |
|
599 //PANIC(TMS_RESULT_DOES_NOT_EXIST); |
|
600 break; |
|
601 } |
|
602 //Set priority and preference |
|
603 iTonePlayer->SetPriority(iPriority, iPreference); |
|
604 } |
|
605 else if (iFormat == EFormatTts) |
|
606 { |
|
607 switch (iRingType) |
|
608 { |
|
609 case ETypeRinging: |
|
610 case ETypeAscending: |
|
611 { |
|
612 // Not allowed for TTS. |
|
613 break; |
|
614 } |
|
615 case ETypeRingingOnce: |
|
616 { |
|
617 iTtsPlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
618 KTMSRingingRepeatsTrailPause)); |
|
619 iTtsPlayer->SetVolume(ConvertVolume(iVolume)); |
|
620 break; |
|
621 } |
|
622 default: |
|
623 { |
|
624 __ASSERT_DEBUG(EFalse, PANIC(TMS_RESULT_DOES_NOT_EXIST)); |
|
625 break; |
|
626 } |
|
627 } |
|
628 } |
|
629 else |
|
630 { |
|
631 switch (iRingType) |
|
632 { |
|
633 case ETypeRinging: |
|
634 { |
|
635 // If we have TTS activated and ringing type is "ringing", then |
|
636 // we need to play TTS sequence again when ringtone restarts. |
|
637 // That's why we need to set ringingtype to ETypeRingingOnce, |
|
638 // because it is the only way of knowing when ringtone playback |
|
639 // is completed. Then we can restart it with new TTS iterations. |
|
640 if (iTTsToBePlayed) |
|
641 { |
|
642 // Play only once |
|
643 iSamplePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
644 KTMSRingingRepeatsTrailPause)); |
|
645 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
646 } |
|
647 else |
|
648 { |
|
649 iSamplePlayer->SetRepeats( |
|
650 KTMSMdaAudioToneRepeatForever, |
|
651 TTimeIntervalMicroSeconds( |
|
652 KTMSRingingRepeatsTrailPause)); |
|
653 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
654 } |
|
655 break; |
|
656 } |
|
657 case ETypeRingingOnce: |
|
658 { |
|
659 iSamplePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
660 KTMSRingingRepeatsTrailPause)); |
|
661 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
662 break; |
|
663 } |
|
664 case ETypeAscending: |
|
665 { |
|
666 iSamplePlayer->SetRepeats(KTMSMdaAudioToneRepeatForever, |
|
667 TTimeIntervalMicroSeconds( |
|
668 KTMSRingingRepeatsTrailPause)); |
|
669 |
|
670 // Special case for TTS + ascending profile. Volume and |
|
671 // ramptime need to be different then usual |
|
672 if (iTTsToBePlayed) |
|
673 { |
|
674 // RampTime is only 3 seconds and volume is 1. |
|
675 rampTime = KTMSAudioAscendingRampDuration; |
|
676 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
677 rampTime)); |
|
678 iCurrentVolume = 1; //we start from the lowest volume |
|
679 iSamplePlayer->SetVolume(ConvertVolume(iCurrentVolume)); |
|
680 } |
|
681 else |
|
682 { |
|
683 // RampTime: time for one step * volume level |
|
684 rampTime = KTMSAudioAscendingRampDuration * iVolume; |
|
685 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
686 rampTime)); |
|
687 |
|
688 iCurrentVolume = 1; //we start from the lowest volume |
|
689 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
690 } |
|
691 break; |
|
692 } |
|
693 default: |
|
694 { |
|
695 break; |
|
696 } |
|
697 } |
|
698 } |
|
699 } |
|
700 |
|
701 // ----------------------------------------------------------------------------- |
|
702 // TMSRtAudioHdlr::SetNewVolumeAndRamptime |
|
703 // ----------------------------------------------------------------------------- |
|
704 // |
|
705 void TMSRtAudioHdlr::SetNewVolumeAndRamptime(TInt aVolume, TInt aRamptime) |
|
706 { |
|
707 // Check that volume is in a valid range. |
|
708 TInt volume = aVolume < 1 ? 1 : aVolume; |
|
709 |
|
710 if (iFormat == EFormatTone && iTonePlayer) |
|
711 { |
|
712 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(aRamptime)); |
|
713 iTonePlayer->SetVolume(ConvertVolume(volume)); |
|
714 } |
|
715 else if (iFormat == EFormatTts && iTtsPlayer) |
|
716 { |
|
717 iTtsPlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(aRamptime)); |
|
718 iTtsPlayer->SetVolume(ConvertVolume(volume)); |
|
719 } |
|
720 else |
|
721 { |
|
722 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(aRamptime)); |
|
723 iSamplePlayer->SetVolume(ConvertVolume(volume)); |
|
724 } |
|
725 } |
|
726 |
|
727 // ----------------------------------------------------------------------------- |
|
728 // TMSRtAudioHdlr::ConvertVolume |
|
729 // ----------------------------------------------------------------------------- |
|
730 // |
|
731 TInt TMSRtAudioHdlr::ConvertVolume(TInt aVolume) |
|
732 { |
|
733 TInt result(0); |
|
734 |
|
735 if (iFormat == EFormatTone) |
|
736 { |
|
737 result = iTonePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
738 } |
|
739 else if (iFormat == EFormatTts) |
|
740 { |
|
741 result = iTtsPlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
742 } |
|
743 else |
|
744 { |
|
745 result = iSamplePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
746 } |
|
747 |
|
748 // If user selected minimum volume level set HW volume 1 |
|
749 if (aVolume == KMinVolumeLevel && result == 0) |
|
750 { |
|
751 result = 1; |
|
752 } |
|
753 return result; |
|
754 } |
|
755 |
|
756 // ----------------------------------------------------------------------------- |
|
757 // TMSRtAudioHdlr::SetTTsToBePlayed |
|
758 // ----------------------------------------------------------------------------- |
|
759 // |
|
760 void TMSRtAudioHdlr::SetTTsToBePlayed(const TBool aTTsToBePlayed) |
|
761 { |
|
762 iTTsToBePlayed = aTTsToBePlayed; |
|
763 } |
|
764 |
|
765 // ----------------------------------------------------------------------------- |
|
766 // TMSRtAudioHdlr::MutePlaying |
|
767 // ----------------------------------------------------------------------------- |
|
768 // |
|
769 void TMSRtAudioHdlr::MutePlaying() |
|
770 { |
|
771 if (iPlayerStatus == ETonePlaying) |
|
772 { |
|
773 if (iFormat == EFormatTone) |
|
774 { |
|
775 iTonePlayer->SetVolume(0); |
|
776 } |
|
777 else if (iFormat == EFormatTts) |
|
778 { |
|
779 iTtsPlayer->SetVolume(0); |
|
780 } |
|
781 else // EFormatSample |
|
782 { |
|
783 iSamplePlayer->SetVolume(0); |
|
784 } |
|
785 } |
|
786 else |
|
787 { |
|
788 // Mute during EToneLoading state. |
|
789 iToBePlaying = EFalse; |
|
790 } |
|
791 } |
|
792 |
|
793 // End of File |