First public contribution.
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.
18 #ifndef __TONEGENERATOR_H__
19 #define __TONEGENERATOR_H__
24 // Sine tone generator
27 const TInt KMaxSineTable = 256;
28 const TUint KToneBufferSize = 8192;
30 // one second in microseconds
31 const TInt KOneMillionMicroSeconds = 1000000;
40 void SetFrequency(TInt aFrequency,TInt aAmplitude);
46 static const TInt16 SineTable[KMaxSineTable];
47 static const TInt16 IncTable[KMaxSineTable];
56 void Generate(TInt16* aDest,TInt aCount);
57 void SetFrequency(TInt aFrequency,TInt aAmplitude);
58 void SetFrequency(TInt aFrequency1,TInt aAmplitude1,TInt aFrequency2,TInt aAmplitude2);
65 // Tone synthesis interface
66 // Defines the abstract interface for tone synthesis
67 // Capable of filling buffers with audio data
70 class MMdaToneSynthesis
76 // Allocate necessary resources for this kind of synthesis
77 virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp)=0;
78 // Begin generating data from start again
79 virtual void Reset()=0;
80 // Fill supplied buffer with next block of 16bit PCM audio data
81 virtual TInt FillBuffer(TDes8& aBuffer)=0;
85 // Tone generator base class
88 class TMdaToneGenerator : public MMdaToneSynthesis
91 virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp);
92 virtual TInt FillBuffer(TDes8& aBuffer);
94 virtual TInt GetNextTone()=0;
96 TInt DurationToSamples(const TTimeIntervalMicroSeconds& aDuration);
102 TInt iTrailingSilence;
106 TInt iSilenceBetweenRepeats;
107 TBool iAfterRepeatSilence;
113 // Simple tone synthesis
116 class TMdaSimpleToneGenerator : public TMdaToneGenerator
122 void SetFrequencyAndDuration(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
123 virtual void Reset();
124 virtual TInt GetNextTone();
126 TTimeIntervalMicroSeconds iDuration;
133 * Dual tone synthesis
134 * Generates a tone consisting of two sine waves of different
135 * frequencies summed together.
137 * @internalTechnology
139 class TMdaDualToneGenerator : public TMdaToneGenerator
142 void SetFrequencyAndDuration(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
143 virtual void Reset();
144 virtual TInt GetNextTone();
146 TTimeIntervalMicroSeconds iDuration;
153 // DTMF tone synthesis
156 class TMdaDTMFGenerator : public TMdaToneGenerator
162 virtual void Reset();
163 void SetToneDurations( const TTimeIntervalMicroSeconds32 aOn,
164 const TTimeIntervalMicroSeconds32 aOff,
165 const TTimeIntervalMicroSeconds32 aPause);
166 void SetString(const TDesC& aDTMFString);
168 virtual TInt GetNextTone();
170 const TDesC* iDTMFString;
171 TTimeIntervalMicroSeconds32 iOn;
172 TTimeIntervalMicroSeconds32 iOff;
173 TTimeIntervalMicroSeconds32 iPause;
182 // Tone sequence synthesis
185 const TInt KMaxSequenceStack = 6;
186 class TMdaSequenceGenerator : public TMdaToneGenerator
192 virtual void Reset();
193 void SetSequenceData(const TDesC8& aSequenceData);
195 virtual TInt GetNextTone();
197 const TDesC8* iSequenceData;
198 const TInt16* iInstructionPtr;
199 const TInt16* iLastInstruction;
200 TInt iStack[KMaxSequenceStack];
204 const TInt KBufferLength = 0x1000;
206 // Public Media Server includes
208 class TMdaPtr8 : public TPtr8 //needed for this WINS Impl of Tone Gen
213 inline void Set(const TDes8& aDes)
214 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.MaxLength()); };
215 inline void SetLengthOnly(const TDes8& aDes)
216 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
217 inline void Set(const TPtrC8& aDes)
218 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
219 inline void Shift(TInt aOffset)
220 { SetLength(Length()-aOffset); iMaxLength-=aOffset; iPtr+=aOffset; };