sl@0: /* sl@0: * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #ifndef C_TONEHWDEVICE_H sl@0: #define C_TONEHWDEVICE_H sl@0: sl@0: // INCLUDES sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "mdasoundadapter.h" sl@0: #include "ToneGenerator.h" sl@0: #include "tonedatapath.h" sl@0: #include sl@0: sl@0: sl@0: //note we need to keep this buffer at 8K as the tone utility expects 8K sl@0: const TInt KPCM16ToPCM16BufferSize = 0x2000; sl@0: sl@0: //controlls buffer sizes sl@0: const TInt KDevSoundDefaultFrameSize = 0x1000; sl@0: const TInt KDevSoundMinFrameSize = 0x800; //2K sl@0: const TInt KDevSoundMaxFrameSize = 0x4000; //16K sl@0: const TInt KDevSoundDeltaFrameSize = 0x800; //2K sl@0: const TInt KDevSoundFramesPerSecond = 4; sl@0: sl@0: // FORWARD DECLARATIONS sl@0: class CToneDataPath; sl@0: sl@0: // CLASS DECLARATION sl@0: sl@0: /** sl@0: * Implementation of custom interface class for tone play functionality created by the sl@0: * CToneCodec::CustomInterface() method. It provides sl@0: * access to miscellaneous functionality such as volume settings sl@0: */ sl@0: class TToneCustomInterface : public MPlayCustomInterface sl@0: { sl@0: public: sl@0: TToneCustomInterface() : iVolume(0),iBytesPlayed(0),iDevice(NULL),iRampDuration(0) {} sl@0: void SetVolume(TUint aVolume); sl@0: TUint Volume(); sl@0: TUint BytesPlayed(); sl@0: void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); sl@0: TTimeIntervalMicroSeconds& VolumeRamp(); sl@0: void SetDevice(RMdaDevSound* iDevice); sl@0: private: sl@0: TUint iVolume; sl@0: TUint iBytesPlayed; sl@0: RMdaDevSound* iDevice; sl@0: TTimeIntervalMicroSeconds iRampDuration; sl@0: }; sl@0: sl@0: sl@0: sl@0: /* sl@0: * Codec Implementation sl@0: */ sl@0: sl@0: class CToneCodec : public CBase sl@0: { sl@0: public: sl@0: /** sl@0: Indicates the result of processing data from the source buffer to a destination buffer sl@0: and provides functions to compare the result code. sl@0: The CToneCodec buffer sizes should be set to return EProcessComplete sl@0: The other return codes are to keep the ProcessL method compatible with sl@0: the 7.0s CMMFCodec API. sl@0: */ sl@0: class TCodecProcessResult sl@0: { sl@0: public: sl@0: /** sl@0: Flag to track the codec's processing status. sl@0: */ sl@0: enum TCodecProcessResultStatus sl@0: { sl@0: /** The codec has successfully completed its processing. */ sl@0: EProcessComplete, sl@0: /** Could not empty the source buffer because the destination buffer became full. */ sl@0: EProcessIncomplete, sl@0: /** Codec came across an end of data. */ sl@0: EEndOfData, sl@0: /** Could not fill the destination buffer because the source buffer has been emptied. */ sl@0: EDstNotFilled, sl@0: /** An error occured. */ sl@0: EProcessError sl@0: }; sl@0: sl@0: /** Overloaded operator to test equality. */ sl@0: TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);} sl@0: /** Overloaded operator to test inequality. */ sl@0: TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);} sl@0: sl@0: /** sl@0: Default constructor. sl@0: */ sl@0: TCodecProcessResult() sl@0: :iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {}; sl@0: sl@0: public: sl@0: /** sl@0: The codec's processing status sl@0: sl@0: @see enum TCodecProcessResultStatus sl@0: */ sl@0: TCodecProcessResultStatus iCodecProcessStatus; sl@0: sl@0: /** The number of source bytes processed */ sl@0: TUint iSrcBytesProcessed; sl@0: sl@0: /** The number of bytes added to the destination buffer */ sl@0: TUint iDstBytesAdded; sl@0: }; sl@0: public: sl@0: sl@0: CToneCodec(); sl@0: ~CToneCodec(); sl@0: sl@0: void ConstructL(); sl@0: sl@0: sl@0: /** sl@0: Processes the data in the specified source buffer and writes the processed data to sl@0: the specified destination buffer. sl@0: sl@0: This function is synchronous, when the function returns the data has been processed. sl@0: sl@0: @param aSource sl@0: The source buffer containing data to encode or decode. sl@0: @param aDest sl@0: The destination buffer to hold the data after encoding or decoding. sl@0: sl@0: @return The result of the processing. sl@0: sl@0: @see TCodecProcessResult sl@0: */ sl@0: TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest); sl@0: sl@0: /** sl@0: Gets the max size of the source buffer passed into the sl@0: CToneCodec::ProcessL function. sl@0: sl@0: Note that this means that this is the Max size of each buffer passed to the codec. The actual sl@0: size of the data could be less than the max size. sl@0: sl@0: @return The max size of the source buffer in bytes. sl@0: */ sl@0: TUint SourceBufferSize(); sl@0: sl@0: /** sl@0: Gets the max size of the sink (destination) buffer passed into the sl@0: CToneCodec::ProcessL method. sl@0: sl@0: Note that this means that this is the Max size of each buffer passed to the codec. The actual sl@0: size of the data written to this buffer could be less than the max size. sl@0: sl@0: @return The max size of the sink buffer in bytes. sl@0: */ sl@0: TUint SinkBufferSize(); sl@0: sl@0: TBool IsNullCodec() {return ETrue;}; sl@0: sl@0: sl@0: private: sl@0: sl@0: TUint iBufferSize; sl@0: sl@0: }; sl@0: sl@0: sl@0: class CToneHwDevice : public CMMFHwDevice, sl@0: public MMMFHwDeviceObserver sl@0: sl@0: { sl@0: public: // Constructors and destructor sl@0: sl@0: static CToneHwDevice* NewL(); sl@0: ~CToneHwDevice(); sl@0: sl@0: public: // New functions sl@0: sl@0: public: // Functions from base classes sl@0: sl@0: sl@0: TInt Init(THwDeviceInitParams& aDevInfo); sl@0: TInt Start(TDeviceFunc /*aFuncCmd*/, TDeviceFlow /*aFlowCmd*/); sl@0: TInt Stop(); sl@0: sl@0: /* This function is not used in tone playback*/ sl@0: TInt Pause(); sl@0: sl@0: TAny* CustomInterface(TUid aInterfaceUid); sl@0: sl@0: TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer); sl@0: sl@0: TInt ThisHwBufferFilled(CMMFBuffer& aMmfBuffer); sl@0: sl@0: /*From MMMFHwDeviceObserver*/ sl@0: /* This function is not used in tone playback*/ sl@0: TInt ThisHwBufferEmptied(CMMFBuffer& aMmfBuffer); sl@0: sl@0: /*From MMMFHwDeviceObserver*/ sl@0: /* This function is not used in tone playback*/ sl@0: TInt EmptyThisHwBuffer(CMMFBuffer& aMmfBuffer); sl@0: sl@0: /*From MMMFHwDeviceObserver*/ sl@0: TInt MsgFromHwDevice(TUid aMessageType, const TDesC8 &aMsg); sl@0: sl@0: /*From MMMFHwDeviceObserver*/ sl@0: void Stopped(); sl@0: sl@0: /*From MMMFHwDeviceObserver*/ sl@0: void Error(TInt aError); sl@0: sl@0: TInt SetConfig(TTaskConfig& aConfig); sl@0: sl@0: /* This function is not used in tone playback*/ sl@0: TInt StopAndDeleteCodec(); sl@0: sl@0: /* This function is not used in tone playback*/ sl@0: TInt DeleteCodec(); sl@0: sl@0: CToneCodec& Codec(); sl@0: sl@0: TInt GenerateBufferData(); sl@0: sl@0: void SetActiveToneBuffer(); sl@0: sl@0: TInt SamplingFrequency(); sl@0: sl@0: TInt NumberOfChannels(); sl@0: sl@0: TInt FillFreeToneBuffer(); sl@0: sl@0: TInt ReadToneData(); sl@0: sl@0: void FreeBuffers(); sl@0: sl@0: TBool ValidDTMFString(const TDesC& aDTMFString); sl@0: sl@0: TBool RecognizeSequence(const TDesC8& aData); sl@0: sl@0: protected: // New functions sl@0: protected: // Functions from base classes sl@0: sl@0: private: sl@0: sl@0: CToneHwDevice(); sl@0: void ConstructL(); sl@0: sl@0: public: // Data sl@0: protected: // Data sl@0: private: // Data sl@0: sl@0: /** sl@0: * Pointer to the buffer that was last sent to the observer to be filled. sl@0: * Own pointer. sl@0: */ sl@0: CMMFDataBuffer* iHwDataBufferFill; sl@0: sl@0: /** sl@0: * Hwdevice observer. Information is send to upper level by using this pointer. sl@0: */ sl@0: MMMFHwDeviceObserver* iHwDeviceObserver; sl@0: sl@0: /** sl@0: The datapath used to transfer the data sl@0: */ sl@0: CToneDataPath* iDataPath; sl@0: sl@0: MPlayCustomInterface* iPlayCustomInterface; sl@0: sl@0: /** sl@0: * Initialize status of the tone sl@0: */ sl@0: TBool iToneInitialized; sl@0: sl@0: /** sl@0: * Playback status of the tone sl@0: */ sl@0: TBool iTonePlaying; sl@0: sl@0: /** sl@0: * Pointer to information about hwdevice initializing parameters. sl@0: */ sl@0: //TSizeHwDeviceInitArgs* iSizeHwDeviceInitArgs; sl@0: sl@0: /** sl@0: * Type of the tone sl@0: */ sl@0: TToneData::TToneType iToneType; sl@0: sl@0: /** sl@0: * Tone Data sl@0: */ sl@0: TToneData myToneData; sl@0: sl@0: /** sl@0: * Tone Codec sl@0: */ sl@0: CToneCodec *iCodec; sl@0: sl@0: /** sl@0: The buffer size of the sound device sl@0: */ sl@0: TUint iDeviceBufferSize; sl@0: sl@0: /** sl@0: The sample rate of the sound device sl@0: */ sl@0: TInt iSampleRate; sl@0: sl@0: /** sl@0: The number of channels of the sound device sl@0: */ sl@0: TInt iChannels; sl@0: sl@0: TBool iLastBuffer; sl@0: sl@0: TTimeIntervalMicroSeconds iRampDuration; sl@0: sl@0: //WINS Sound Device Structures sl@0: RMdaDevSound::TCurrentSoundFormatBuf soundDeviceSettings; sl@0: sl@0: // Double buffer tone playing sl@0: CMMFDataBuffer* iToneBuffer1; sl@0: CMMFDataBuffer* iToneBuffer2; sl@0: // Reference to current tone buffer playing sl@0: CMMFDataBuffer* iActiveToneBuffer; sl@0: sl@0: TBool iFirstCallFromHwDevice; sl@0: sl@0: //Tone Stuff: sl@0: sl@0: MMdaToneSynthesis* iCurrentGenerator; sl@0: TMdaSimpleToneGenerator iToneGen; sl@0: TMdaDualToneGenerator iDualToneGen; sl@0: TMdaDTMFGenerator iDTMFGen; sl@0: TMdaSequenceGenerator iSequenceGen; // Not Supported sl@0: TInt iRepeatCount; sl@0: TInt iFrequency1; sl@0: TInt iFrequency2; sl@0: TTimeIntervalMicroSeconds iRepeatTrailingSilence; sl@0: TTimeIntervalMicroSeconds iDuration; sl@0: sl@0: TTimeIntervalMicroSeconds32 myToneOnLength; sl@0: TTimeIntervalMicroSeconds32 myToneOffLength; sl@0: TTimeIntervalMicroSeconds32 myPauseLength; sl@0: sl@0: TDesC *iDTMFString; sl@0: sl@0: TDesC8 *iSequenceData; sl@0: }; sl@0: sl@0: #include "tonehwdevice.inl" sl@0: sl@0: #endif sl@0: sl@0: // End of File