|
1 /* |
|
2 * Copyright (c) 2002-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 module contains the implementation of CPEAudioDtmfTonePlayer class |
|
15 * member functions |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cpeaudiodtmftoneplayer.h" |
|
22 #include "pepanic.pan" |
|
23 #include <utility.h> |
|
24 #include <mdaaudiotoneplayer.h> |
|
25 #include <talogger.h> |
|
26 #include <AudioPreference.h> |
|
27 |
|
28 // EXTERNAL DATA STRUCTURES |
|
29 // None |
|
30 |
|
31 // EXTERNAL FUNCTION PROTOTYPES |
|
32 // None |
|
33 |
|
34 // CONSTANTS |
|
35 const TInt KDtmfSilent = 0; |
|
36 const TInt KDtmfPauseAfterTone = 100000; |
|
37 const TInt KDtmfToneZero = 0; |
|
38 const TInt KBufSize = 10; |
|
39 _LIT( KPhoneTone_Asterisk, "*+w" ); |
|
40 |
|
41 const TInt KMaxVolumeLevel = 10; |
|
42 |
|
43 // MACROS |
|
44 // None |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 // None |
|
48 |
|
49 // MODULE DATA STRUCTURES |
|
50 // None |
|
51 |
|
52 // LOCAL FUNCTION PROTOTYPES |
|
53 // None |
|
54 |
|
55 // FORWARD DECLARATIONS |
|
56 // None. |
|
57 |
|
58 // ==================== LOCAL FUNCTIONS ===================================== |
|
59 // None |
|
60 |
|
61 // ================= MEMBER FUNCTIONS ======================================= |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPEAudioDtmfTonePlayer::NewL |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CPEAudioDtmfTonePlayer* CPEAudioDtmfTonePlayer::NewL() |
|
69 { |
|
70 CPEAudioDtmfTonePlayer* self = |
|
71 new ( ELeave ) CPEAudioDtmfTonePlayer; |
|
72 |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop( self ); |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 //Destructor |
|
81 CPEAudioDtmfTonePlayer::~CPEAudioDtmfTonePlayer() |
|
82 { |
|
83 TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioDtmfTonePlayer::~CPEAudioDtmfTonePlayer"); |
|
84 Cancel(); |
|
85 delete iDTMFPlayer; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CPEAudioDtmfTonePlayer::CPEAudioDtmfTonePlayer |
|
90 // C++ default constructor can NOT contain any code, that |
|
91 // might leave. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CPEAudioDtmfTonePlayer::CPEAudioDtmfTonePlayer() |
|
95 { |
|
96 TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioDtmfTonePlayer::CPEAudioDtmfTonePlayer"); |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CPEAudioDtmfTonePlayer::ConstructL |
|
101 // Symbian 2nd phase constructor can leave. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CPEAudioDtmfTonePlayer::ConstructL() |
|
105 { |
|
106 TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioDtmfTonePlayer::ConstructL start"); |
|
107 TMMFPrioritySettings dtmfClickPlayerPrioritySettings; |
|
108 iDTMFPlayer = CMMFDevSound::NewL(); |
|
109 |
|
110 iDTMFPlayer->InitializeL( *this, EMMFStateTonePlaying ); |
|
111 |
|
112 TEFLOGSTRING( KTAOBJECT, "AUD CPEAudioDtmfTonePlayer::ConstructL completed"); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CPEAudioDtmfTonePlayer::SetVolume |
|
117 // Sets the volume level that is used when the dtmf tone is played. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CPEAudioDtmfTonePlayer::SetVolume( |
|
121 TInt aVolume //Volume to be set |
|
122 ) |
|
123 { |
|
124 TInt vol = ConvertVolume( aVolume ); |
|
125 |
|
126 if ( vol != iVolume ) |
|
127 { |
|
128 iVolume = vol; |
|
129 iDTMFPlayer->SetVolume( iVolume ); |
|
130 TEFLOGSTRING2( KTAINT, "AUD CPEAudioDtmfTonePlayer::SetVolume, iVolume = %d", |
|
131 iVolume ); |
|
132 } |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CPEAudioDtmfTonePlayer::PlayDtmfTone |
|
137 // Searches the given DTMF tone from iToneArray and calls PlayCurrentTone -member function. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 void CPEAudioDtmfTonePlayer::PlayDtmfTone( |
|
141 TChar aTone ) |
|
142 { |
|
143 TEFLOGSTRING( KTAINT, "AUD CPEAudioDtmfTonePlayer::PlayDtmfTone"); |
|
144 Cancel(); |
|
145 Normalize( aTone ); |
|
146 |
|
147 // DTMF signalling. |
|
148 if ( iDTMFPlayer ) |
|
149 { |
|
150 TBuf<KBufSize> key; |
|
151 key.Append( aTone ); |
|
152 TEFLOGSTRING( KTAREQOUT, "AUD CPEAudioDtmfTonePlayer::PlayDtmfTone > CMMFDevSound::PlayDTMFStringL"); |
|
153 TRAP_IGNORE( iDTMFPlayer->PlayDTMFStringL( key ) ); |
|
154 } |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CPEAudioDtmfTonePlayer::Cancel |
|
159 // Cancels the currently playing tone. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CPEAudioDtmfTonePlayer::Cancel() |
|
163 { |
|
164 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::Cancel"); |
|
165 iDTMFPlayer->Stop(); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CPEAudioDtmfTonePlayer::Normalize |
|
170 // Lowers case for chars and if its '*','+', or 'w' sets it to asterisk char ('*'). |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CPEAudioDtmfTonePlayer::Normalize( |
|
174 TChar& aTone ) |
|
175 { |
|
176 TEFLOGSTRING( KTAINT, "AUD CPEAudioDtmfTonePlayer::Normalize"); |
|
177 aTone.LowerCase(); |
|
178 |
|
179 TPtrC ast( KPhoneTone_Asterisk ); |
|
180 |
|
181 if ( ast.Locate( aTone ) != KErrNotFound ) |
|
182 { |
|
183 aTone = ast[ 0 ]; |
|
184 TEFLOGSTRING( KTAINT, "AUD CPEAudioDtmfTonePlayer::Normalize"); |
|
185 } |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CPEAudioDtmfTonePlayer::InitializeComplete |
|
190 // --------------------------------------------------------- |
|
191 // |
|
192 void CPEAudioDtmfTonePlayer::InitializeComplete( |
|
193 TInt aError ) |
|
194 { |
|
195 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::InitializeComplete"); |
|
196 __ASSERT_DEBUG( aError == KErrNone , Panic( EPEPanicAudioInitializeError ) ); |
|
197 |
|
198 if( aError == KErrNone) |
|
199 { |
|
200 TMMFPrioritySettings dtmfClickPlayerSettings; |
|
201 |
|
202 dtmfClickPlayerSettings.iPref = |
|
203 ( TMdaPriorityPreference ) KAudioPrefKeyDownDTMF; |
|
204 dtmfClickPlayerSettings.iPriority = KAudioPriorityDtmfKeyPress; |
|
205 dtmfClickPlayerSettings.iState = EMMFStateTonePlaying; |
|
206 |
|
207 iDTMFPlayer->SetPrioritySettings( dtmfClickPlayerSettings ); |
|
208 |
|
209 TTimeIntervalMicroSeconds32 length( KMdaInfiniteDurationDTMFToneOnLength ); |
|
210 TTimeIntervalMicroSeconds32 pause( KDtmfPauseAfterTone ); |
|
211 TTimeIntervalMicroSeconds32 zero( KDtmfToneZero ); |
|
212 |
|
213 iDTMFPlayer->SetDTMFLengths( length, pause, zero ); |
|
214 |
|
215 iDTMFPlayer->SetToneRepeats( |
|
216 KMdaAudioToneRepeatForever, |
|
217 TTimeIntervalMicroSeconds( KDtmfToneZero ) ); |
|
218 // Must initialize volume to dtmf player. Otherwise it will be |
|
219 // 5 by default in audio SW. |
|
220 iDTMFPlayer->SetVolume( iVolume ); |
|
221 } |
|
222 |
|
223 |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------- |
|
227 // CPEAudioDtmfTonePlayer::ToneFinished |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 void CPEAudioDtmfTonePlayer::ToneFinished( |
|
231 TInt /*aError*/ ) |
|
232 { |
|
233 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::ToneFinished"); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // CPEAudioDtmfTonePlayer::BufferToBeFilled |
|
238 // --------------------------------------------------------- |
|
239 // |
|
240 void CPEAudioDtmfTonePlayer::BufferToBeFilled( CMMFBuffer* /*aBuffer*/ ) |
|
241 { |
|
242 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::BufferToBeFilled"); |
|
243 } |
|
244 |
|
245 // --------------------------------------------------------- |
|
246 // CPEAudioDtmfTonePlayer::PlayError |
|
247 // --------------------------------------------------------- |
|
248 // |
|
249 void CPEAudioDtmfTonePlayer::PlayError( TInt /*aError*/ ) |
|
250 { |
|
251 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::PlayError"); |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------- |
|
255 // CPEAudioDtmfTonePlayer::BufferToBeEmptied |
|
256 // --------------------------------------------------------- |
|
257 // |
|
258 void CPEAudioDtmfTonePlayer::BufferToBeEmptied( CMMFBuffer* /*aBuffer*/ ) |
|
259 { |
|
260 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::BufferToBeEmptied"); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CPEAudioDtmfTonePlayer::RecordError |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 void CPEAudioDtmfTonePlayer::RecordError( TInt /*aError*/ ) |
|
268 { |
|
269 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::RecordError"); |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------- |
|
273 // CPEAudioDtmfTonePlayer::ConvertError |
|
274 // --------------------------------------------------------- |
|
275 // |
|
276 void CPEAudioDtmfTonePlayer::ConvertError( TInt /*aError*/ ) |
|
277 { |
|
278 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::ConvertError"); |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------- |
|
282 // CPEAudioDtmfTonePlayer::DeviceMessage |
|
283 // --------------------------------------------------------- |
|
284 // |
|
285 void CPEAudioDtmfTonePlayer::DeviceMessage( TUid /*aMessageType*/, |
|
286 const TDesC8& /*aMsg*/ ) |
|
287 { |
|
288 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::DeviceMessage"); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CPEAudioDtmfTonePlayer::ConvertVolume |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CPEAudioDtmfTonePlayer::ConvertVolume( TInt aVolume ) |
|
296 { |
|
297 TEFLOGSTRING( KTAREQEND, "AUD CPEAudioDtmfTonePlayer::ConvertVolume"); |
|
298 TInt result = iDTMFPlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
299 |
|
300 TEFLOGSTRING3( KTAREQEND, |
|
301 "AUD CPEAudioDtmfTonePlayer::ConvertVolume, result = %d, maxVol=%d", |
|
302 result, iDTMFPlayer->MaxVolume() ); |
|
303 return result; |
|
304 } |
|
305 |
|
306 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
307 // None. |
|
308 |
|
309 // End of File |