sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#ifndef C_TONEHWDEVICE_H
|
sl@0
|
21 |
#define C_TONEHWDEVICE_H
|
sl@0
|
22 |
|
sl@0
|
23 |
// INCLUDES
|
sl@0
|
24 |
#include <mmf/server/mmfhwdevice.h>
|
sl@0
|
25 |
#include <mmf/server/sounddevice.h>
|
sl@0
|
26 |
#include <mmf/server/mmfhwdevicesetup.h>
|
sl@0
|
27 |
#include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
|
sl@0
|
28 |
#include <a3f/a3f_trace_utils.h>
|
sl@0
|
29 |
#include "mdasoundadapter.h"
|
sl@0
|
30 |
#include "ToneGenerator.h"
|
sl@0
|
31 |
#include "tonedatapath.h"
|
sl@0
|
32 |
#include <a3f/tonedata.h>
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
//note we need to keep this buffer at 8K as the tone utility expects 8K
|
sl@0
|
36 |
const TInt KPCM16ToPCM16BufferSize = 0x2000;
|
sl@0
|
37 |
|
sl@0
|
38 |
//controlls buffer sizes
|
sl@0
|
39 |
const TInt KDevSoundDefaultFrameSize = 0x1000;
|
sl@0
|
40 |
const TInt KDevSoundMinFrameSize = 0x800; //2K
|
sl@0
|
41 |
const TInt KDevSoundMaxFrameSize = 0x4000; //16K
|
sl@0
|
42 |
const TInt KDevSoundDeltaFrameSize = 0x800; //2K
|
sl@0
|
43 |
const TInt KDevSoundFramesPerSecond = 4;
|
sl@0
|
44 |
|
sl@0
|
45 |
// FORWARD DECLARATIONS
|
sl@0
|
46 |
class CToneDataPath;
|
sl@0
|
47 |
|
sl@0
|
48 |
// CLASS DECLARATION
|
sl@0
|
49 |
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
* Implementation of custom interface class for tone play functionality created by the
|
sl@0
|
52 |
* CToneCodec::CustomInterface() method. It provides
|
sl@0
|
53 |
* access to miscellaneous functionality such as volume settings
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
class TToneCustomInterface : public MPlayCustomInterface
|
sl@0
|
56 |
{
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
TToneCustomInterface() : iVolume(0),iBytesPlayed(0),iDevice(NULL),iRampDuration(0) {}
|
sl@0
|
59 |
void SetVolume(TUint aVolume);
|
sl@0
|
60 |
TUint Volume();
|
sl@0
|
61 |
TUint BytesPlayed();
|
sl@0
|
62 |
void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
|
sl@0
|
63 |
TTimeIntervalMicroSeconds& VolumeRamp();
|
sl@0
|
64 |
void SetDevice(RMdaDevSound* iDevice);
|
sl@0
|
65 |
private:
|
sl@0
|
66 |
TUint iVolume;
|
sl@0
|
67 |
TUint iBytesPlayed;
|
sl@0
|
68 |
RMdaDevSound* iDevice;
|
sl@0
|
69 |
TTimeIntervalMicroSeconds iRampDuration;
|
sl@0
|
70 |
};
|
sl@0
|
71 |
|
sl@0
|
72 |
|
sl@0
|
73 |
|
sl@0
|
74 |
/*
|
sl@0
|
75 |
* Codec Implementation
|
sl@0
|
76 |
*/
|
sl@0
|
77 |
|
sl@0
|
78 |
class CToneCodec : public CBase
|
sl@0
|
79 |
{
|
sl@0
|
80 |
public:
|
sl@0
|
81 |
/**
|
sl@0
|
82 |
Indicates the result of processing data from the source buffer to a destination buffer
|
sl@0
|
83 |
and provides functions to compare the result code.
|
sl@0
|
84 |
The CToneCodec buffer sizes should be set to return EProcessComplete
|
sl@0
|
85 |
The other return codes are to keep the ProcessL method compatible with
|
sl@0
|
86 |
the 7.0s CMMFCodec API.
|
sl@0
|
87 |
*/
|
sl@0
|
88 |
class TCodecProcessResult
|
sl@0
|
89 |
{
|
sl@0
|
90 |
public:
|
sl@0
|
91 |
/**
|
sl@0
|
92 |
Flag to track the codec's processing status.
|
sl@0
|
93 |
*/
|
sl@0
|
94 |
enum TCodecProcessResultStatus
|
sl@0
|
95 |
{
|
sl@0
|
96 |
/** The codec has successfully completed its processing. */
|
sl@0
|
97 |
EProcessComplete,
|
sl@0
|
98 |
/** Could not empty the source buffer because the destination buffer became full. */
|
sl@0
|
99 |
EProcessIncomplete,
|
sl@0
|
100 |
/** Codec came across an end of data. */
|
sl@0
|
101 |
EEndOfData,
|
sl@0
|
102 |
/** Could not fill the destination buffer because the source buffer has been emptied. */
|
sl@0
|
103 |
EDstNotFilled,
|
sl@0
|
104 |
/** An error occured. */
|
sl@0
|
105 |
EProcessError
|
sl@0
|
106 |
};
|
sl@0
|
107 |
|
sl@0
|
108 |
/** Overloaded operator to test equality. */
|
sl@0
|
109 |
TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);}
|
sl@0
|
110 |
/** Overloaded operator to test inequality. */
|
sl@0
|
111 |
TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);}
|
sl@0
|
112 |
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
Default constructor.
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
TCodecProcessResult()
|
sl@0
|
117 |
:iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {};
|
sl@0
|
118 |
|
sl@0
|
119 |
public:
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
The codec's processing status
|
sl@0
|
122 |
|
sl@0
|
123 |
@see enum TCodecProcessResultStatus
|
sl@0
|
124 |
*/
|
sl@0
|
125 |
TCodecProcessResultStatus iCodecProcessStatus;
|
sl@0
|
126 |
|
sl@0
|
127 |
/** The number of source bytes processed */
|
sl@0
|
128 |
TUint iSrcBytesProcessed;
|
sl@0
|
129 |
|
sl@0
|
130 |
/** The number of bytes added to the destination buffer */
|
sl@0
|
131 |
TUint iDstBytesAdded;
|
sl@0
|
132 |
};
|
sl@0
|
133 |
public:
|
sl@0
|
134 |
|
sl@0
|
135 |
CToneCodec();
|
sl@0
|
136 |
~CToneCodec();
|
sl@0
|
137 |
|
sl@0
|
138 |
void ConstructL();
|
sl@0
|
139 |
|
sl@0
|
140 |
|
sl@0
|
141 |
/**
|
sl@0
|
142 |
Processes the data in the specified source buffer and writes the processed data to
|
sl@0
|
143 |
the specified destination buffer.
|
sl@0
|
144 |
|
sl@0
|
145 |
This function is synchronous, when the function returns the data has been processed.
|
sl@0
|
146 |
|
sl@0
|
147 |
@param aSource
|
sl@0
|
148 |
The source buffer containing data to encode or decode.
|
sl@0
|
149 |
@param aDest
|
sl@0
|
150 |
The destination buffer to hold the data after encoding or decoding.
|
sl@0
|
151 |
|
sl@0
|
152 |
@return The result of the processing.
|
sl@0
|
153 |
|
sl@0
|
154 |
@see TCodecProcessResult
|
sl@0
|
155 |
*/
|
sl@0
|
156 |
TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest);
|
sl@0
|
157 |
|
sl@0
|
158 |
/**
|
sl@0
|
159 |
Gets the max size of the source buffer passed into the
|
sl@0
|
160 |
CToneCodec::ProcessL function.
|
sl@0
|
161 |
|
sl@0
|
162 |
Note that this means that this is the Max size of each buffer passed to the codec. The actual
|
sl@0
|
163 |
size of the data could be less than the max size.
|
sl@0
|
164 |
|
sl@0
|
165 |
@return The max size of the source buffer in bytes.
|
sl@0
|
166 |
*/
|
sl@0
|
167 |
TUint SourceBufferSize();
|
sl@0
|
168 |
|
sl@0
|
169 |
/**
|
sl@0
|
170 |
Gets the max size of the sink (destination) buffer passed into the
|
sl@0
|
171 |
CToneCodec::ProcessL method.
|
sl@0
|
172 |
|
sl@0
|
173 |
Note that this means that this is the Max size of each buffer passed to the codec. The actual
|
sl@0
|
174 |
size of the data written to this buffer could be less than the max size.
|
sl@0
|
175 |
|
sl@0
|
176 |
@return The max size of the sink buffer in bytes.
|
sl@0
|
177 |
*/
|
sl@0
|
178 |
TUint SinkBufferSize();
|
sl@0
|
179 |
|
sl@0
|
180 |
TBool IsNullCodec() {return ETrue;};
|
sl@0
|
181 |
|
sl@0
|
182 |
|
sl@0
|
183 |
private:
|
sl@0
|
184 |
|
sl@0
|
185 |
TUint iBufferSize;
|
sl@0
|
186 |
|
sl@0
|
187 |
};
|
sl@0
|
188 |
|
sl@0
|
189 |
|
sl@0
|
190 |
class CToneHwDevice : public CMMFHwDevice,
|
sl@0
|
191 |
public MMMFHwDeviceObserver
|
sl@0
|
192 |
|
sl@0
|
193 |
{
|
sl@0
|
194 |
public: // Constructors and destructor
|
sl@0
|
195 |
|
sl@0
|
196 |
static CToneHwDevice* NewL();
|
sl@0
|
197 |
~CToneHwDevice();
|
sl@0
|
198 |
|
sl@0
|
199 |
public: // New functions
|
sl@0
|
200 |
|
sl@0
|
201 |
public: // Functions from base classes
|
sl@0
|
202 |
|
sl@0
|
203 |
|
sl@0
|
204 |
TInt Init(THwDeviceInitParams& aDevInfo);
|
sl@0
|
205 |
TInt Start(TDeviceFunc /*aFuncCmd*/, TDeviceFlow /*aFlowCmd*/);
|
sl@0
|
206 |
TInt Stop();
|
sl@0
|
207 |
|
sl@0
|
208 |
/* This function is not used in tone playback*/
|
sl@0
|
209 |
TInt Pause();
|
sl@0
|
210 |
|
sl@0
|
211 |
TAny* CustomInterface(TUid aInterfaceUid);
|
sl@0
|
212 |
|
sl@0
|
213 |
TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
|
sl@0
|
214 |
|
sl@0
|
215 |
TInt ThisHwBufferFilled(CMMFBuffer& aMmfBuffer);
|
sl@0
|
216 |
|
sl@0
|
217 |
/*From MMMFHwDeviceObserver*/
|
sl@0
|
218 |
/* This function is not used in tone playback*/
|
sl@0
|
219 |
TInt ThisHwBufferEmptied(CMMFBuffer& aMmfBuffer);
|
sl@0
|
220 |
|
sl@0
|
221 |
/*From MMMFHwDeviceObserver*/
|
sl@0
|
222 |
/* This function is not used in tone playback*/
|
sl@0
|
223 |
TInt EmptyThisHwBuffer(CMMFBuffer& aMmfBuffer);
|
sl@0
|
224 |
|
sl@0
|
225 |
/*From MMMFHwDeviceObserver*/
|
sl@0
|
226 |
TInt MsgFromHwDevice(TUid aMessageType, const TDesC8 &aMsg);
|
sl@0
|
227 |
|
sl@0
|
228 |
/*From MMMFHwDeviceObserver*/
|
sl@0
|
229 |
void Stopped();
|
sl@0
|
230 |
|
sl@0
|
231 |
/*From MMMFHwDeviceObserver*/
|
sl@0
|
232 |
void Error(TInt aError);
|
sl@0
|
233 |
|
sl@0
|
234 |
TInt SetConfig(TTaskConfig& aConfig);
|
sl@0
|
235 |
|
sl@0
|
236 |
/* This function is not used in tone playback*/
|
sl@0
|
237 |
TInt StopAndDeleteCodec();
|
sl@0
|
238 |
|
sl@0
|
239 |
/* This function is not used in tone playback*/
|
sl@0
|
240 |
TInt DeleteCodec();
|
sl@0
|
241 |
|
sl@0
|
242 |
CToneCodec& Codec();
|
sl@0
|
243 |
|
sl@0
|
244 |
TInt GenerateBufferData();
|
sl@0
|
245 |
|
sl@0
|
246 |
void SetActiveToneBuffer();
|
sl@0
|
247 |
|
sl@0
|
248 |
TInt SamplingFrequency();
|
sl@0
|
249 |
|
sl@0
|
250 |
TInt NumberOfChannels();
|
sl@0
|
251 |
|
sl@0
|
252 |
TInt FillFreeToneBuffer();
|
sl@0
|
253 |
|
sl@0
|
254 |
TInt ReadToneData();
|
sl@0
|
255 |
|
sl@0
|
256 |
void FreeBuffers();
|
sl@0
|
257 |
|
sl@0
|
258 |
TBool ValidDTMFString(const TDesC& aDTMFString);
|
sl@0
|
259 |
|
sl@0
|
260 |
TBool RecognizeSequence(const TDesC8& aData);
|
sl@0
|
261 |
|
sl@0
|
262 |
protected: // New functions
|
sl@0
|
263 |
protected: // Functions from base classes
|
sl@0
|
264 |
|
sl@0
|
265 |
private:
|
sl@0
|
266 |
|
sl@0
|
267 |
CToneHwDevice();
|
sl@0
|
268 |
void ConstructL();
|
sl@0
|
269 |
|
sl@0
|
270 |
public: // Data
|
sl@0
|
271 |
protected: // Data
|
sl@0
|
272 |
private: // Data
|
sl@0
|
273 |
|
sl@0
|
274 |
/**
|
sl@0
|
275 |
* Pointer to the buffer that was last sent to the observer to be filled.
|
sl@0
|
276 |
* Own pointer.
|
sl@0
|
277 |
*/
|
sl@0
|
278 |
CMMFDataBuffer* iHwDataBufferFill;
|
sl@0
|
279 |
|
sl@0
|
280 |
/**
|
sl@0
|
281 |
* Hwdevice observer. Information is send to upper level by using this pointer.
|
sl@0
|
282 |
*/
|
sl@0
|
283 |
MMMFHwDeviceObserver* iHwDeviceObserver;
|
sl@0
|
284 |
|
sl@0
|
285 |
/**
|
sl@0
|
286 |
The datapath used to transfer the data
|
sl@0
|
287 |
*/
|
sl@0
|
288 |
CToneDataPath* iDataPath;
|
sl@0
|
289 |
|
sl@0
|
290 |
MPlayCustomInterface* iPlayCustomInterface;
|
sl@0
|
291 |
|
sl@0
|
292 |
/**
|
sl@0
|
293 |
* Initialize status of the tone
|
sl@0
|
294 |
*/
|
sl@0
|
295 |
TBool iToneInitialized;
|
sl@0
|
296 |
|
sl@0
|
297 |
/**
|
sl@0
|
298 |
* Playback status of the tone
|
sl@0
|
299 |
*/
|
sl@0
|
300 |
TBool iTonePlaying;
|
sl@0
|
301 |
|
sl@0
|
302 |
/**
|
sl@0
|
303 |
* Pointer to information about hwdevice initializing parameters.
|
sl@0
|
304 |
*/
|
sl@0
|
305 |
//TSizeHwDeviceInitArgs* iSizeHwDeviceInitArgs;
|
sl@0
|
306 |
|
sl@0
|
307 |
/**
|
sl@0
|
308 |
* Type of the tone
|
sl@0
|
309 |
*/
|
sl@0
|
310 |
TToneData::TToneType iToneType;
|
sl@0
|
311 |
|
sl@0
|
312 |
/**
|
sl@0
|
313 |
* Tone Data
|
sl@0
|
314 |
*/
|
sl@0
|
315 |
TToneData myToneData;
|
sl@0
|
316 |
|
sl@0
|
317 |
/**
|
sl@0
|
318 |
* Tone Codec
|
sl@0
|
319 |
*/
|
sl@0
|
320 |
CToneCodec *iCodec;
|
sl@0
|
321 |
|
sl@0
|
322 |
/**
|
sl@0
|
323 |
The buffer size of the sound device
|
sl@0
|
324 |
*/
|
sl@0
|
325 |
TUint iDeviceBufferSize;
|
sl@0
|
326 |
|
sl@0
|
327 |
/**
|
sl@0
|
328 |
The sample rate of the sound device
|
sl@0
|
329 |
*/
|
sl@0
|
330 |
TInt iSampleRate;
|
sl@0
|
331 |
|
sl@0
|
332 |
/**
|
sl@0
|
333 |
The number of channels of the sound device
|
sl@0
|
334 |
*/
|
sl@0
|
335 |
TInt iChannels;
|
sl@0
|
336 |
|
sl@0
|
337 |
TBool iLastBuffer;
|
sl@0
|
338 |
|
sl@0
|
339 |
TTimeIntervalMicroSeconds iRampDuration;
|
sl@0
|
340 |
|
sl@0
|
341 |
//WINS Sound Device Structures
|
sl@0
|
342 |
RMdaDevSound::TCurrentSoundFormatBuf soundDeviceSettings;
|
sl@0
|
343 |
|
sl@0
|
344 |
// Double buffer tone playing
|
sl@0
|
345 |
CMMFDataBuffer* iToneBuffer1;
|
sl@0
|
346 |
CMMFDataBuffer* iToneBuffer2;
|
sl@0
|
347 |
// Reference to current tone buffer playing
|
sl@0
|
348 |
CMMFDataBuffer* iActiveToneBuffer;
|
sl@0
|
349 |
|
sl@0
|
350 |
TBool iFirstCallFromHwDevice;
|
sl@0
|
351 |
|
sl@0
|
352 |
//Tone Stuff:
|
sl@0
|
353 |
|
sl@0
|
354 |
MMdaToneSynthesis* iCurrentGenerator;
|
sl@0
|
355 |
TMdaSimpleToneGenerator iToneGen;
|
sl@0
|
356 |
TMdaDualToneGenerator iDualToneGen;
|
sl@0
|
357 |
TMdaDTMFGenerator iDTMFGen;
|
sl@0
|
358 |
TMdaSequenceGenerator iSequenceGen; // Not Supported
|
sl@0
|
359 |
TInt iRepeatCount;
|
sl@0
|
360 |
TInt iFrequency1;
|
sl@0
|
361 |
TInt iFrequency2;
|
sl@0
|
362 |
TTimeIntervalMicroSeconds iRepeatTrailingSilence;
|
sl@0
|
363 |
TTimeIntervalMicroSeconds iDuration;
|
sl@0
|
364 |
|
sl@0
|
365 |
TTimeIntervalMicroSeconds32 myToneOnLength;
|
sl@0
|
366 |
TTimeIntervalMicroSeconds32 myToneOffLength;
|
sl@0
|
367 |
TTimeIntervalMicroSeconds32 myPauseLength;
|
sl@0
|
368 |
|
sl@0
|
369 |
TDesC *iDTMFString;
|
sl@0
|
370 |
|
sl@0
|
371 |
TDesC8 *iSequenceData;
|
sl@0
|
372 |
};
|
sl@0
|
373 |
|
sl@0
|
374 |
#include "tonehwdevice.inl"
|
sl@0
|
375 |
|
sl@0
|
376 |
#endif
|
sl@0
|
377 |
|
sl@0
|
378 |
// End of File
|