1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmhais/refacladapt/src/tonehwdevice/ToneGenerator.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,226 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef __TONEGENERATOR_H__
1.20 +#define __TONEGENERATOR_H__
1.21 +
1.22 +#include <e32base.h>
1.23 +
1.24 +//
1.25 +// Sine tone generator
1.26 +//
1.27 +
1.28 +const TInt KMaxSineTable = 256;
1.29 +const TUint KToneBufferSize = 8192;
1.30 +
1.31 +// one second in microseconds
1.32 +const TInt KOneMillionMicroSeconds = 1000000;
1.33 +
1.34 +
1.35 +class TSineGen
1.36 +/**
1.37 +*@internalTechnology
1.38 +*/
1.39 + {
1.40 +public:
1.41 + void SetFrequency(TInt aFrequency,TInt aAmplitude);
1.42 + TInt NextSample();
1.43 +private:
1.44 + TUint iPosition;
1.45 + TUint iStep;
1.46 + TInt iAmplitude;
1.47 + static const TInt16 SineTable[KMaxSineTable];
1.48 + static const TInt16 IncTable[KMaxSineTable];
1.49 + };
1.50 +
1.51 +class TSineWave
1.52 +/**
1.53 +*@internalTechnology
1.54 +*/
1.55 + {
1.56 +public:
1.57 + void Generate(TInt16* aDest,TInt aCount);
1.58 + void SetFrequency(TInt aFrequency,TInt aAmplitude);
1.59 + void SetFrequency(TInt aFrequency1,TInt aAmplitude1,TInt aFrequency2,TInt aAmplitude2);
1.60 +private:
1.61 + TSineGen iGen1;
1.62 + TSineGen iGen2;
1.63 + };
1.64 +
1.65 +//
1.66 +// Tone synthesis interface
1.67 +// Defines the abstract interface for tone synthesis
1.68 +// Capable of filling buffers with audio data
1.69 +//
1.70 +
1.71 +class MMdaToneSynthesis
1.72 +/**
1.73 +*@internalTechnology
1.74 +*/
1.75 + {
1.76 +public:
1.77 + // Allocate necessary resources for this kind of synthesis
1.78 + virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp)=0;
1.79 + // Begin generating data from start again
1.80 + virtual void Reset()=0;
1.81 + // Fill supplied buffer with next block of 16bit PCM audio data
1.82 + virtual TInt FillBuffer(TDes8& aBuffer)=0;
1.83 + };
1.84 +
1.85 +//
1.86 +// Tone generator base class
1.87 +//
1.88 +
1.89 +class TMdaToneGenerator : public MMdaToneSynthesis
1.90 + {
1.91 +public:
1.92 + virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp);
1.93 + virtual TInt FillBuffer(TDes8& aBuffer);
1.94 +protected:
1.95 + virtual TInt GetNextTone()=0;
1.96 + //
1.97 + TInt DurationToSamples(const TTimeIntervalMicroSeconds& aDuration);
1.98 +protected:
1.99 + TSineWave iSineWave;
1.100 + TInt iRate;
1.101 + TInt iChannels;
1.102 + TInt iSamplesLeft;
1.103 + TInt iTrailingSilence;
1.104 + TBool iRampUp;
1.105 + TBool iRampDown;
1.106 + TBool iIncompleteRampDown;
1.107 + TBool iIncompleteRampUp;
1.108 + TInt iIncompleteVolume;
1.109 + TInt iRampUpRemainder;
1.110 + TInt iRepeats;
1.111 + TInt iSilenceBetweenRepeats;
1.112 + TBool iAfterRepeatSilence;
1.113 + TInt iRampUpCount;
1.114 + TInt iRampUpLeft;
1.115 + };
1.116 +
1.117 +//
1.118 +// Simple tone synthesis
1.119 +//
1.120 +
1.121 +class TMdaSimpleToneGenerator : public TMdaToneGenerator
1.122 +/**
1.123 +*@internalTechnology
1.124 +*/
1.125 + {
1.126 +public:
1.127 + void SetFrequencyAndDuration(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
1.128 + virtual void Reset();
1.129 + virtual TInt GetNextTone();
1.130 +private:
1.131 + TTimeIntervalMicroSeconds iDuration;
1.132 + TInt iFrequency;
1.133 + TBool iPlayed;
1.134 + };
1.135 +
1.136 +
1.137 +/**
1.138 + * Dual tone synthesis
1.139 + * Generates a tone consisting of two sine waves of different
1.140 + * frequencies summed together.
1.141 + *
1.142 + * @internalTechnology
1.143 + */
1.144 +class TMdaDualToneGenerator : public TMdaToneGenerator
1.145 + {
1.146 +public:
1.147 + void SetFrequencyAndDuration(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
1.148 + virtual void Reset();
1.149 + virtual TInt GetNextTone();
1.150 +private:
1.151 + TTimeIntervalMicroSeconds iDuration;
1.152 + TInt iFrequencyOne;
1.153 + TInt iFrequencyTwo;
1.154 + TBool iPlayed;
1.155 + };
1.156 +
1.157 +//
1.158 +// DTMF tone synthesis
1.159 +//
1.160 +
1.161 +class TMdaDTMFGenerator : public TMdaToneGenerator
1.162 +/**
1.163 +*@internalTechnology
1.164 +*/
1.165 + {
1.166 +public:
1.167 + virtual void Reset();
1.168 + void SetToneDurations( const TTimeIntervalMicroSeconds32 aOn,
1.169 + const TTimeIntervalMicroSeconds32 aOff,
1.170 + const TTimeIntervalMicroSeconds32 aPause);
1.171 + void SetString(const TDesC& aDTMFString);
1.172 +private:
1.173 + virtual TInt GetNextTone();
1.174 +private:
1.175 + const TDesC* iDTMFString;
1.176 + TTimeIntervalMicroSeconds32 iOn;
1.177 + TTimeIntervalMicroSeconds32 iOff;
1.178 + TTimeIntervalMicroSeconds32 iPause;
1.179 + TInt iOnSamples;
1.180 + TInt iOffSamples;
1.181 + TInt iPauseSamples;
1.182 + TInt iChar;
1.183 + TBool iPlayToneOff;
1.184 + };
1.185 +
1.186 +//
1.187 +// Tone sequence synthesis
1.188 +//
1.189 +
1.190 +const TInt KMaxSequenceStack = 6;
1.191 +class TMdaSequenceGenerator : public TMdaToneGenerator
1.192 +/**
1.193 +*@internalTechnology
1.194 +*/
1.195 + {
1.196 +public:
1.197 + virtual void Reset();
1.198 + void SetSequenceData(const TDesC8& aSequenceData);
1.199 +private:
1.200 + virtual TInt GetNextTone();
1.201 +private:
1.202 + const TDesC8* iSequenceData;
1.203 + const TInt16* iInstructionPtr;
1.204 + const TInt16* iLastInstruction;
1.205 + TInt iStack[KMaxSequenceStack];
1.206 + TInt iStackIndex;
1.207 + };
1.208 +
1.209 +const TInt KBufferLength = 0x1000;
1.210 +
1.211 +// Public Media Server includes
1.212 +
1.213 +class TMdaPtr8 : public TPtr8 //needed for this WINS Impl of Tone Gen
1.214 + {
1.215 +public:
1.216 + TMdaPtr8()
1.217 + : TPtr8(0,0,0) {};
1.218 + inline void Set(const TDes8& aDes)
1.219 + { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.MaxLength()); };
1.220 + inline void SetLengthOnly(const TDes8& aDes)
1.221 + { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
1.222 + inline void Set(const TPtrC8& aDes)
1.223 + { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
1.224 + inline void Shift(TInt aOffset)
1.225 + { SetLength(Length()-aOffset); iMaxLength-=aOffset; iPtr+=aOffset; };
1.226 + };
1.227 +
1.228 +
1.229 +#endif