Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __TONEGENERATOR_H__
17 #define __TONEGENERATOR_H__
22 // Sine tone generator
25 const TInt KMaxSineTable = 256;
26 const TUint KToneBufferSize = 8192;
28 // one second in microseconds
29 const TInt KOneMillionMicroSeconds = 1000000;
38 void SetFrequency(TInt aFrequency,TInt aAmplitude);
44 static const TInt16 SineTable[KMaxSineTable];
45 static const TInt16 IncTable[KMaxSineTable];
54 void Generate(TInt16* aDest,TInt aCount);
55 void SetFrequency(TInt aFrequency,TInt aAmplitude);
56 void SetFrequency(TInt aFrequency1,TInt aAmplitude1,TInt aFrequency2,TInt aAmplitude2);
63 // Tone synthesis interface
64 // Defines the abstract interface for tone synthesis
65 // Capable of filling buffers with audio data
68 class MMdaToneSynthesis
74 // Allocate necessary resources for this kind of synthesis
75 virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp)=0;
76 // Begin generating data from start again
77 virtual void Reset()=0;
78 // Fill supplied buffer with next block of 16bit PCM audio data
79 virtual TInt FillBuffer(TDes8& aBuffer)=0;
83 // Tone generator base class
86 class TMdaToneGenerator : public MMdaToneSynthesis
89 virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp);
90 virtual TInt FillBuffer(TDes8& aBuffer);
92 virtual TInt GetNextTone()=0;
94 TInt DurationToSamples(const TTimeIntervalMicroSeconds& aDuration);
100 TInt iTrailingSilence;
103 TBool iIncompleteRampDown;
104 TBool iIncompleteRampUp;
105 TInt iIncompleteVolume;
106 TInt iRampUpRemainder;
108 TInt iSilenceBetweenRepeats;
109 TBool iAfterRepeatSilence;
115 // Simple tone synthesis
118 class TMdaSimpleToneGenerator : public TMdaToneGenerator
124 void SetFrequencyAndDuration(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
125 virtual void Reset();
126 virtual TInt GetNextTone();
128 TTimeIntervalMicroSeconds iDuration;
135 * Dual tone synthesis
136 * Generates a tone consisting of two sine waves of different
137 * frequencies summed together.
139 * @internalTechnology
141 class TMdaDualToneGenerator : public TMdaToneGenerator
144 void SetFrequencyAndDuration(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
145 virtual void Reset();
146 virtual TInt GetNextTone();
148 TTimeIntervalMicroSeconds iDuration;
155 // DTMF tone synthesis
158 class TMdaDTMFGenerator : public TMdaToneGenerator
164 virtual void Reset();
165 void SetToneDurations( const TTimeIntervalMicroSeconds32 aOn,
166 const TTimeIntervalMicroSeconds32 aOff,
167 const TTimeIntervalMicroSeconds32 aPause);
168 void SetString(const TDesC& aDTMFString);
170 virtual TInt GetNextTone();
172 const TDesC* iDTMFString;
173 TTimeIntervalMicroSeconds32 iOn;
174 TTimeIntervalMicroSeconds32 iOff;
175 TTimeIntervalMicroSeconds32 iPause;
184 // Tone sequence synthesis
187 const TInt KMaxSequenceStack = 6;
188 class TMdaSequenceGenerator : public TMdaToneGenerator
194 virtual void Reset();
195 void SetSequenceData(const TDesC8& aSequenceData);
197 virtual TInt GetNextTone();
199 const TDesC8* iSequenceData;
200 const TInt16* iInstructionPtr;
201 const TInt16* iLastInstruction;
202 TInt iStack[KMaxSequenceStack];
206 const TInt KBufferLength = 0x1000;
208 // Public Media Server includes
210 class TMdaPtr8 : public TPtr8 //needed for this WINS Impl of Tone Gen
215 inline void Set(const TDes8& aDes)
216 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.MaxLength()); };
217 inline void SetLengthOnly(const TDes8& aDes)
218 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
219 inline void Set(const TPtrC8& aDes)
220 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
221 inline void Shift(TInt aOffset)
222 { SetLength(Length()-aOffset); iMaxLength-=aOffset; iPtr+=aOffset; };