First public contribution.
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #ifndef C_TONEHWDEVICE_H
21 #define C_TONEHWDEVICE_H
24 #include <mmf/server/mmfhwdevice.h>
25 #include <mmf/server/sounddevice.h>
26 #include <mmf/server/mmfhwdevicesetup.h>
27 #include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
28 #include <a3f/a3f_trace_utils.h>
29 #include "mdasoundadapter.h"
30 #include "ToneGenerator.h"
31 #include "tonedatapath.h"
32 #include <a3f/tonedata.h>
35 //note we need to keep this buffer at 8K as the tone utility expects 8K
36 const TInt KPCM16ToPCM16BufferSize = 0x2000;
38 //controlls buffer sizes
39 const TInt KDevSoundDefaultFrameSize = 0x1000;
40 const TInt KDevSoundMinFrameSize = 0x800; //2K
41 const TInt KDevSoundMaxFrameSize = 0x4000; //16K
42 const TInt KDevSoundDeltaFrameSize = 0x800; //2K
43 const TInt KDevSoundFramesPerSecond = 4;
45 // FORWARD DECLARATIONS
51 * Implementation of custom interface class for tone play functionality created by the
52 * CToneCodec::CustomInterface() method. It provides
53 * access to miscellaneous functionality such as volume settings
55 class TToneCustomInterface : public MPlayCustomInterface
58 TToneCustomInterface() : iVolume(0),iBytesPlayed(0),iDevice(NULL),iRampDuration(0) {}
59 void SetVolume(TUint aVolume);
62 void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
63 TTimeIntervalMicroSeconds& VolumeRamp();
64 void SetDevice(RMdaDevSound* iDevice);
68 RMdaDevSound* iDevice;
69 TTimeIntervalMicroSeconds iRampDuration;
75 * Codec Implementation
78 class CToneCodec : public CBase
82 Indicates the result of processing data from the source buffer to a destination buffer
83 and provides functions to compare the result code.
84 The CToneCodec buffer sizes should be set to return EProcessComplete
85 The other return codes are to keep the ProcessL method compatible with
86 the 7.0s CMMFCodec API.
88 class TCodecProcessResult
92 Flag to track the codec's processing status.
94 enum TCodecProcessResultStatus
96 /** The codec has successfully completed its processing. */
98 /** Could not empty the source buffer because the destination buffer became full. */
100 /** Codec came across an end of data. */
102 /** Could not fill the destination buffer because the source buffer has been emptied. */
104 /** An error occured. */
108 /** Overloaded operator to test equality. */
109 TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);}
110 /** Overloaded operator to test inequality. */
111 TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);}
116 TCodecProcessResult()
117 :iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {};
121 The codec's processing status
123 @see enum TCodecProcessResultStatus
125 TCodecProcessResultStatus iCodecProcessStatus;
127 /** The number of source bytes processed */
128 TUint iSrcBytesProcessed;
130 /** The number of bytes added to the destination buffer */
131 TUint iDstBytesAdded;
142 Processes the data in the specified source buffer and writes the processed data to
143 the specified destination buffer.
145 This function is synchronous, when the function returns the data has been processed.
148 The source buffer containing data to encode or decode.
150 The destination buffer to hold the data after encoding or decoding.
152 @return The result of the processing.
154 @see TCodecProcessResult
156 TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest);
159 Gets the max size of the source buffer passed into the
160 CToneCodec::ProcessL function.
162 Note that this means that this is the Max size of each buffer passed to the codec. The actual
163 size of the data could be less than the max size.
165 @return The max size of the source buffer in bytes.
167 TUint SourceBufferSize();
170 Gets the max size of the sink (destination) buffer passed into the
171 CToneCodec::ProcessL method.
173 Note that this means that this is the Max size of each buffer passed to the codec. The actual
174 size of the data written to this buffer could be less than the max size.
176 @return The max size of the sink buffer in bytes.
178 TUint SinkBufferSize();
180 TBool IsNullCodec() {return ETrue;};
190 class CToneHwDevice : public CMMFHwDevice,
191 public MMMFHwDeviceObserver
194 public: // Constructors and destructor
196 static CToneHwDevice* NewL();
199 public: // New functions
201 public: // Functions from base classes
204 TInt Init(THwDeviceInitParams& aDevInfo);
205 TInt Start(TDeviceFunc /*aFuncCmd*/, TDeviceFlow /*aFlowCmd*/);
208 /* This function is not used in tone playback*/
211 TAny* CustomInterface(TUid aInterfaceUid);
213 TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
215 TInt ThisHwBufferFilled(CMMFBuffer& aMmfBuffer);
217 /*From MMMFHwDeviceObserver*/
218 /* This function is not used in tone playback*/
219 TInt ThisHwBufferEmptied(CMMFBuffer& aMmfBuffer);
221 /*From MMMFHwDeviceObserver*/
222 /* This function is not used in tone playback*/
223 TInt EmptyThisHwBuffer(CMMFBuffer& aMmfBuffer);
225 /*From MMMFHwDeviceObserver*/
226 TInt MsgFromHwDevice(TUid aMessageType, const TDesC8 &aMsg);
228 /*From MMMFHwDeviceObserver*/
231 /*From MMMFHwDeviceObserver*/
232 void Error(TInt aError);
234 TInt SetConfig(TTaskConfig& aConfig);
236 /* This function is not used in tone playback*/
237 TInt StopAndDeleteCodec();
239 /* This function is not used in tone playback*/
244 TInt GenerateBufferData();
246 void SetActiveToneBuffer();
248 TInt SamplingFrequency();
250 TInt NumberOfChannels();
252 TInt FillFreeToneBuffer();
258 TBool ValidDTMFString(const TDesC& aDTMFString);
260 TBool RecognizeSequence(const TDesC8& aData);
262 protected: // New functions
263 protected: // Functions from base classes
275 * Pointer to the buffer that was last sent to the observer to be filled.
278 CMMFDataBuffer* iHwDataBufferFill;
281 * Hwdevice observer. Information is send to upper level by using this pointer.
283 MMMFHwDeviceObserver* iHwDeviceObserver;
286 The datapath used to transfer the data
288 CToneDataPath* iDataPath;
290 MPlayCustomInterface* iPlayCustomInterface;
293 * Initialize status of the tone
295 TBool iToneInitialized;
298 * Playback status of the tone
303 * Pointer to information about hwdevice initializing parameters.
305 //TSizeHwDeviceInitArgs* iSizeHwDeviceInitArgs;
310 TToneData::TToneType iToneType;
315 TToneData myToneData;
323 The buffer size of the sound device
325 TUint iDeviceBufferSize;
328 The sample rate of the sound device
333 The number of channels of the sound device
339 TTimeIntervalMicroSeconds iRampDuration;
341 //WINS Sound Device Structures
342 RMdaDevSound::TCurrentSoundFormatBuf soundDeviceSettings;
344 // Double buffer tone playing
345 CMMFDataBuffer* iToneBuffer1;
346 CMMFDataBuffer* iToneBuffer2;
347 // Reference to current tone buffer playing
348 CMMFDataBuffer* iActiveToneBuffer;
350 TBool iFirstCallFromHwDevice;
354 MMdaToneSynthesis* iCurrentGenerator;
355 TMdaSimpleToneGenerator iToneGen;
356 TMdaDualToneGenerator iDualToneGen;
357 TMdaDTMFGenerator iDTMFGen;
358 TMdaSequenceGenerator iSequenceGen; // Not Supported
362 TTimeIntervalMicroSeconds iRepeatTrailingSilence;
363 TTimeIntervalMicroSeconds iDuration;
365 TTimeIntervalMicroSeconds32 myToneOnLength;
366 TTimeIntervalMicroSeconds32 myToneOffLength;
367 TTimeIntervalMicroSeconds32 myPauseLength;
371 TDesC8 *iSequenceData;
374 #include "tonehwdevice.inl"