|
1 /* |
|
2 * Copyright (c) 2006-2007 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: This class provides audio playback for Alarm UI. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "AlmAlarmPlayer.h" |
|
22 #include "alarmutils.h" |
|
23 #include "pim_trace.h" |
|
24 |
|
25 #include <AudioPreference.h> |
|
26 |
|
27 // CONSTANTS AND MACROS |
|
28 const TInt KSoundInterval( 1000000 ); // 1 second |
|
29 |
|
30 // set player volume |
|
31 #define SET_VOLUME( t, v ) t->SetVolume( v ); |
|
32 |
|
33 // Copied from Phone's Toneplayer. |
|
34 _LIT8( KPhoneBeepSequence, "\x00\x11\x06\x0A\x08\x73\x0A\x40\x28\x0A\xF7\x05\xFC\x40\x64\x0A\x08\x40\x32\x0A\xF7\x06\x0B" ); |
|
35 _LIT8( KPhoneNoSoundSequence, "\x00\x11\x06\x05\xFC\x0A\x08\x40\x32\x0A\xF7\x40\x64\x06\x0B" ); |
|
36 |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // C++ default constructor. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CAlmAlarmPlayer::CAlmAlarmPlayer(CAlarmUtils* aAlarmUtils) |
|
45 : iAlarmUtils( aAlarmUtils ) |
|
46 { |
|
47 TRACE_ENTRY_POINT; |
|
48 TRACE_EXIT_POINT; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // Symbian 2nd phase constructor. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CAlmAlarmPlayer::ConstructL(void) |
|
56 { |
|
57 TRACE_ENTRY_POINT; |
|
58 PlayAlarmL(); |
|
59 TRACE_EXIT_POINT; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CAlmAlarmPlayer* CAlmAlarmPlayer::NewL(CAlarmUtils* aAlarmUtils) |
|
67 { // static |
|
68 TRACE_ENTRY_POINT; |
|
69 CAlmAlarmPlayer* self = new( ELeave )CAlmAlarmPlayer( aAlarmUtils ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 TRACE_EXIT_POINT; |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // Destructor. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CAlmAlarmPlayer::~CAlmAlarmPlayer(void) |
|
82 { |
|
83 TRACE_ENTRY_POINT; |
|
84 |
|
85 if( iSequencePlayer ) |
|
86 { |
|
87 if( iSequencePlayer->State() == EMdaAudioToneUtilityPlaying ) |
|
88 { |
|
89 iSequencePlayer->CancelPlay(); |
|
90 } |
|
91 else |
|
92 { |
|
93 iSequencePlayer->CancelPrepare(); |
|
94 } |
|
95 delete iSequencePlayer; |
|
96 } |
|
97 |
|
98 if( iSamplePlayer ) |
|
99 { |
|
100 iSamplePlayer->Stop(); |
|
101 iSamplePlayer->Close(); |
|
102 delete iSamplePlayer; |
|
103 } |
|
104 |
|
105 if( iBeepPlayer ) |
|
106 { |
|
107 if( iBeepPlayer->State() == EMdaAudioToneUtilityPlaying ) |
|
108 { |
|
109 iBeepPlayer->CancelPlay(); |
|
110 } |
|
111 else |
|
112 { |
|
113 iBeepPlayer->CancelPrepare(); |
|
114 } |
|
115 delete iBeepPlayer; |
|
116 } |
|
117 TRACE_EXIT_POINT; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // Once tone initialization is complete play the tone. |
|
122 // ----------------------------------------------------------------------------- |
|
123 // |
|
124 void CAlmAlarmPlayer::MatoPrepareComplete(TInt aError) |
|
125 { |
|
126 TRACE_ENTRY_POINT; |
|
127 if( aError != KErrNone ) |
|
128 { |
|
129 PIM_TRAPD_ASSERT( HandlePlayErrorL( aError ); ) |
|
130 } |
|
131 else if( iBeepPlayer ) |
|
132 { |
|
133 iBeepPlayer->Play(); |
|
134 } |
|
135 else |
|
136 { |
|
137 iSequencePlayer->Play(); |
|
138 } |
|
139 TRACE_EXIT_POINT; |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // Callback for completing tone player. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CAlmAlarmPlayer::MatoPlayComplete(TInt aError) |
|
147 { |
|
148 TRACE_ENTRY_POINT; |
|
149 if( aError != KErrNone ) |
|
150 { |
|
151 PIM_TRAPD_ASSERT( HandlePlayErrorL( aError ); ) |
|
152 } |
|
153 TRACE_EXIT_POINT; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // When initialization is complete set the player settings and play the sound. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CAlmAlarmPlayer::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
161 { |
|
162 TRACE_ENTRY_POINT; |
|
163 if( aError == KErrNone ) |
|
164 { |
|
165 iSamplePlayer->SetVolumeRamp( TTimeIntervalMicroSeconds( iAlarmUtils->AlarmData().iVolumeRampTime ) ); |
|
166 |
|
167 iSamplePlayer->SetRepeats( iAlarmUtils->AlarmData().iRepeatValue, |
|
168 TTimeIntervalMicroSeconds( KSoundInterval ) ); |
|
169 |
|
170 SET_VOLUME( iSamplePlayer, |
|
171 PlayerVolume( iSamplePlayer->MaxVolume(), |
|
172 iAlarmUtils->AlarmData().iVolume ) ) |
|
173 |
|
174 iSamplePlayer->Play(); |
|
175 } |
|
176 else |
|
177 { |
|
178 PIM_TRAPD_ASSERT( HandlePlayErrorL( aError ); ) |
|
179 } |
|
180 TRACE_EXIT_POINT; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // Callback for completing audio player. |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CAlmAlarmPlayer::MapcPlayComplete(TInt aError) |
|
188 { |
|
189 TRACE_ENTRY_POINT; |
|
190 if( aError != KErrNone ) |
|
191 { |
|
192 PIM_TRAPD_ASSERT( HandlePlayErrorL( aError ); ) |
|
193 } |
|
194 TRACE_EXIT_POINT; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // Play appropriate alarm type using profile ringing type setting. |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CAlmAlarmPlayer::PlayCalendarAlarmL(TBool aIsRngTone) |
|
202 { |
|
203 TRACE_ENTRY_POINT; |
|
204 if( iAlarmUtils->AlarmData().iRingType == EProfileRingingTypeBeepOnce ) |
|
205 { |
|
206 PlayCalendarBeepL(); |
|
207 } |
|
208 else if( iAlarmUtils->AlarmData().iRingType == EProfileRingingTypeSilent ) |
|
209 { |
|
210 PlaySilentCalendarAlarmL(); |
|
211 } |
|
212 else |
|
213 { |
|
214 if( aIsRngTone ) |
|
215 { |
|
216 PlayCalendarAlarmToneL(); |
|
217 } |
|
218 else // normal sound file |
|
219 { |
|
220 if( iSamplePlayer ) |
|
221 { |
|
222 iSamplePlayer->Close(); |
|
223 delete iSamplePlayer; |
|
224 iSamplePlayer = NULL; |
|
225 } |
|
226 iSamplePlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
227 iAlarmUtils->AlarmData().iAlarmTone, |
|
228 *this, |
|
229 KAudioPriorityAlarm, |
|
230 static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
231 } |
|
232 } |
|
233 TRACE_EXIT_POINT; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // Play calendar alarm tone. (KRngMimeType files only) |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CAlmAlarmPlayer::PlayCalendarAlarmToneL(void) |
|
241 { |
|
242 TRACE_ENTRY_POINT; |
|
243 if( iSequencePlayer ) |
|
244 { |
|
245 delete iSequencePlayer; |
|
246 iSequencePlayer = NULL; |
|
247 } |
|
248 iSequencePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
249 |
|
250 iSequencePlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
251 |
|
252 iSequencePlayer->SetRepeats( iAlarmUtils->AlarmData().iRepeatValue, |
|
253 TTimeIntervalMicroSeconds( KSoundInterval ) ); |
|
254 |
|
255 SET_VOLUME( iSequencePlayer, |
|
256 PlayerVolume( iSequencePlayer->MaxVolume(), |
|
257 iAlarmUtils->AlarmData().iVolume ) ) |
|
258 |
|
259 iSequencePlayer->SetVolumeRamp( TTimeIntervalMicroSeconds( iAlarmUtils->AlarmData().iVolumeRampTime ) ); |
|
260 |
|
261 iSequencePlayer->PrepareToPlayFileSequence( iAlarmUtils->AlarmData().iAlarmTone ); |
|
262 TRACE_EXIT_POINT; |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // Play silent calendar alarm. (needed to for vibra) |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CAlmAlarmPlayer::PlaySilentCalendarAlarmL(void) |
|
270 { |
|
271 TRACE_ENTRY_POINT; |
|
272 iBeepPlayer = CMdaAudioToneUtility::NewL( *this ); |
|
273 |
|
274 SET_VOLUME( iBeepPlayer, |
|
275 PlayerVolume( iBeepPlayer->MaxVolume(), |
|
276 iAlarmUtils->AlarmData().iVolume ) ) |
|
277 |
|
278 iBeepPlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
279 |
|
280 iBeepPlayer->PrepareToPlayDesSequence( KPhoneNoSoundSequence ); |
|
281 TRACE_EXIT_POINT; |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // Play beep alarm for calendar. |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 void CAlmAlarmPlayer::PlayCalendarBeepL(void) |
|
289 { |
|
290 TRACE_ENTRY_POINT; |
|
291 iBeepPlayer = CMdaAudioToneUtility::NewL( *this ); |
|
292 |
|
293 SET_VOLUME( iBeepPlayer, |
|
294 PlayerVolume( iBeepPlayer->MaxVolume(), |
|
295 iAlarmUtils->AlarmData().iVolume ) ) |
|
296 |
|
297 iBeepPlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefCalendarAlarm ) ); |
|
298 |
|
299 iBeepPlayer->PrepareToPlayDesSequence( KPhoneBeepSequence ); |
|
300 TRACE_EXIT_POINT; |
|
301 } |
|
302 |
|
303 // ----------------------------------------------------------------------------- |
|
304 // Play beep alarm for clock. |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 void CAlmAlarmPlayer::PlayClockBeepL(void) |
|
308 { |
|
309 TRACE_ENTRY_POINT; |
|
310 iBeepPlayer = CMdaAudioToneUtility::NewL( *this ); |
|
311 |
|
312 SET_VOLUME( iBeepPlayer, |
|
313 PlayerVolume( iBeepPlayer->MaxVolume(), |
|
314 iAlarmUtils->AlarmData().iVolume ) ) |
|
315 |
|
316 iBeepPlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefAlarmClock ) ); |
|
317 |
|
318 iBeepPlayer->PrepareToPlayDesSequence( KPhoneBeepSequence ); |
|
319 TRACE_EXIT_POINT; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // Play normal clock alarm. |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void CAlmAlarmPlayer::PlayClockAlarmL(void) |
|
327 { |
|
328 TRACE_ENTRY_POINT; |
|
329 if( iSamplePlayer ) |
|
330 { |
|
331 iSamplePlayer->Close(); |
|
332 delete iSamplePlayer; |
|
333 iSamplePlayer = NULL; |
|
334 } |
|
335 iSamplePlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
336 iAlarmUtils->AlarmData().iAlarmTone, |
|
337 *this, |
|
338 KAudioPriorityAlarm, |
|
339 static_cast<TMdaPriorityPreference>( KAudioPrefAlarmClock ) ); |
|
340 TRACE_EXIT_POINT; |
|
341 |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // Play calendar alarm tone. (KRngMimeType files only) |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 void CAlmAlarmPlayer::PlayClockAlarmToneL(void) |
|
349 { |
|
350 TRACE_ENTRY_POINT; |
|
351 if( iSequencePlayer ) |
|
352 { |
|
353 delete iSequencePlayer; |
|
354 iSequencePlayer = NULL; |
|
355 } |
|
356 iSequencePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
357 |
|
358 iSequencePlayer->SetPriority( KAudioPriorityAlarm, static_cast<TMdaPriorityPreference>( KAudioPrefAlarmClock ) ); |
|
359 |
|
360 iSequencePlayer->SetRepeats( iAlarmUtils->AlarmData().iRepeatValue, |
|
361 TTimeIntervalMicroSeconds( KSoundInterval ) ); |
|
362 |
|
363 SET_VOLUME( iSequencePlayer, |
|
364 PlayerVolume( iSequencePlayer->MaxVolume(), |
|
365 iAlarmUtils->AlarmData().iVolume ) ) |
|
366 |
|
367 iSequencePlayer->SetVolumeRamp( TTimeIntervalMicroSeconds( iAlarmUtils->AlarmData().iVolumeRampTime ) ); |
|
368 |
|
369 iSequencePlayer->PrepareToPlayFileSequence( iAlarmUtils->AlarmData().iAlarmTone ); |
|
370 TRACE_EXIT_POINT; |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // Check the file and alarm type and try to play the alarm. |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 void CAlmAlarmPlayer::PlayAlarmL() |
|
378 { |
|
379 TRACE_ENTRY_POINT; |
|
380 if( iAlarmUtils->AlarmData().iAlarmTone.Length() ) |
|
381 { |
|
382 const TBool isRngTone( iAlarmUtils->IsRngTone() ); |
|
383 |
|
384 if( iAlarmUtils->IsClockAlarm() ) |
|
385 { |
|
386 if( !isRngTone ) |
|
387 { |
|
388 PlayClockAlarmL(); |
|
389 } |
|
390 else |
|
391 { |
|
392 PlayClockAlarmToneL(); |
|
393 } |
|
394 } |
|
395 else |
|
396 { |
|
397 PlayCalendarAlarmL( isRngTone ); |
|
398 } |
|
399 } |
|
400 TRACE_EXIT_POINT; |
|
401 } |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // Common fallback functionality for prepare/play errors. |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void CAlmAlarmPlayer::HandlePlayErrorL(TInt aError) |
|
408 { |
|
409 TRACE_ENTRY_POINT; |
|
410 /** |
|
411 * No fallback for KErrUnderflow - alarm got replaced with the default beep. |
|
412 * Also, nothing to do if iBeepPlayer was already used. |
|
413 **/ |
|
414 if( aError != KErrUnderflow && !iBeepPlayer ) |
|
415 { |
|
416 // fallback to beep tone on OOM or if the default tone was already in use |
|
417 if( aError == KErrNoMemory || |
|
418 iAlarmUtils->AlarmData().iAlarmTone == iAlarmUtils->AlarmData().iDefaultAlarmTone ) |
|
419 { |
|
420 delete iSequencePlayer; |
|
421 iSequencePlayer = NULL; |
|
422 |
|
423 if( iSamplePlayer ) |
|
424 { |
|
425 iSamplePlayer->Close(); |
|
426 } |
|
427 delete iSamplePlayer; |
|
428 iSamplePlayer = NULL; |
|
429 |
|
430 // try playing the beep tone |
|
431 if( iAlarmUtils->IsClockAlarm() ) |
|
432 { |
|
433 PlayClockBeepL(); |
|
434 } |
|
435 else |
|
436 { |
|
437 PlayCalendarBeepL(); |
|
438 } |
|
439 } |
|
440 else // retry using the default tone |
|
441 { |
|
442 iAlarmUtils->AlarmData().iAlarmTone = iAlarmUtils->AlarmData().iDefaultAlarmTone; |
|
443 PlayAlarmL(); |
|
444 } |
|
445 } |
|
446 TRACE_EXIT_POINT; |
|
447 } |
|
448 |
|
449 // ----------------------------------------------------------------------------- |
|
450 // Set volume between zero and player's maximum volume |
|
451 // ----------------------------------------------------------------------------- |
|
452 // |
|
453 TInt CAlmAlarmPlayer::PlayerVolume(TInt aPlayerMaxVol, TInt aVol) |
|
454 { |
|
455 TRACE_ENTRY_POINT; |
|
456 const TInt profileMaxVol( iAlarmUtils->MaxProfileVolume() ); |
|
457 TInt vol( 0 ); // leave as 0 if using off tone |
|
458 if( !iAlarmUtils->IsOffTone() ) |
|
459 { |
|
460 // calculate value between 0 and aPlayerMaxVolume |
|
461 vol = Max( 0, Min( aPlayerMaxVol / profileMaxVol * aVol, aPlayerMaxVol ) ); |
|
462 } |
|
463 TRACE_EXIT_POINT; |
|
464 return vol; |
|
465 } |
|
466 |
|
467 |
|
468 // End of File |