sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// ToneGenerator.h
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#ifndef __TONEGENERATOR_H__
|
sl@0
|
19 |
#define __TONEGENERATOR_H__
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <e32base.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
//
|
sl@0
|
24 |
// Sine tone generator
|
sl@0
|
25 |
//
|
sl@0
|
26 |
|
sl@0
|
27 |
const TInt KMaxSineTable = 256;
|
sl@0
|
28 |
const TUint KToneBufferSize = 8192;
|
sl@0
|
29 |
|
sl@0
|
30 |
// one second in microseconds
|
sl@0
|
31 |
const TInt KOneMillionMicroSeconds = 1000000;
|
sl@0
|
32 |
|
sl@0
|
33 |
|
sl@0
|
34 |
class TSineGen
|
sl@0
|
35 |
/**
|
sl@0
|
36 |
*@internalTechnology
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
{
|
sl@0
|
39 |
public:
|
sl@0
|
40 |
void SetFrequency(TInt aFrequency,TInt aAmplitude);
|
sl@0
|
41 |
TInt NextSample();
|
sl@0
|
42 |
private:
|
sl@0
|
43 |
TUint iPosition;
|
sl@0
|
44 |
TUint iStep;
|
sl@0
|
45 |
TInt iAmplitude;
|
sl@0
|
46 |
static const TInt16 SineTable[KMaxSineTable];
|
sl@0
|
47 |
static const TInt16 IncTable[KMaxSineTable];
|
sl@0
|
48 |
};
|
sl@0
|
49 |
|
sl@0
|
50 |
class TSineWave
|
sl@0
|
51 |
/**
|
sl@0
|
52 |
*@internalTechnology
|
sl@0
|
53 |
*/
|
sl@0
|
54 |
{
|
sl@0
|
55 |
public:
|
sl@0
|
56 |
void Generate(TInt16* aDest,TInt aCount);
|
sl@0
|
57 |
void SetFrequency(TInt aFrequency,TInt aAmplitude);
|
sl@0
|
58 |
void SetFrequency(TInt aFrequency1,TInt aAmplitude1,TInt aFrequency2,TInt aAmplitude2);
|
sl@0
|
59 |
private:
|
sl@0
|
60 |
TSineGen iGen1;
|
sl@0
|
61 |
TSineGen iGen2;
|
sl@0
|
62 |
};
|
sl@0
|
63 |
|
sl@0
|
64 |
//
|
sl@0
|
65 |
// Tone synthesis interface
|
sl@0
|
66 |
// Defines the abstract interface for tone synthesis
|
sl@0
|
67 |
// Capable of filling buffers with audio data
|
sl@0
|
68 |
//
|
sl@0
|
69 |
|
sl@0
|
70 |
class MMdaToneSynthesis
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
*@internalTechnology
|
sl@0
|
73 |
*/
|
sl@0
|
74 |
{
|
sl@0
|
75 |
public:
|
sl@0
|
76 |
// Allocate necessary resources for this kind of synthesis
|
sl@0
|
77 |
virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp)=0;
|
sl@0
|
78 |
// Begin generating data from start again
|
sl@0
|
79 |
virtual void Reset()=0;
|
sl@0
|
80 |
// Fill supplied buffer with next block of 16bit PCM audio data
|
sl@0
|
81 |
virtual TInt FillBuffer(TDes8& aBuffer)=0;
|
sl@0
|
82 |
};
|
sl@0
|
83 |
|
sl@0
|
84 |
//
|
sl@0
|
85 |
// Tone generator base class
|
sl@0
|
86 |
//
|
sl@0
|
87 |
|
sl@0
|
88 |
class TMdaToneGenerator : public MMdaToneSynthesis
|
sl@0
|
89 |
{
|
sl@0
|
90 |
public:
|
sl@0
|
91 |
virtual void Configure(TInt aRate, TInt aChannels, TInt aRepeats, TInt aSilence, TInt aRampUp);
|
sl@0
|
92 |
virtual TInt FillBuffer(TDes8& aBuffer);
|
sl@0
|
93 |
protected:
|
sl@0
|
94 |
virtual TInt GetNextTone()=0;
|
sl@0
|
95 |
//
|
sl@0
|
96 |
TInt DurationToSamples(const TTimeIntervalMicroSeconds& aDuration);
|
sl@0
|
97 |
protected:
|
sl@0
|
98 |
TSineWave iSineWave;
|
sl@0
|
99 |
TInt iRate;
|
sl@0
|
100 |
TInt iChannels;
|
sl@0
|
101 |
TInt iSamplesLeft;
|
sl@0
|
102 |
TInt iTrailingSilence;
|
sl@0
|
103 |
TBool iRampUp;
|
sl@0
|
104 |
TBool iRampDown;
|
sl@0
|
105 |
TInt iRepeats;
|
sl@0
|
106 |
TInt iSilenceBetweenRepeats;
|
sl@0
|
107 |
TBool iAfterRepeatSilence;
|
sl@0
|
108 |
TInt iRampUpCount;
|
sl@0
|
109 |
TInt iRampUpLeft;
|
sl@0
|
110 |
};
|
sl@0
|
111 |
|
sl@0
|
112 |
//
|
sl@0
|
113 |
// Simple tone synthesis
|
sl@0
|
114 |
//
|
sl@0
|
115 |
|
sl@0
|
116 |
class TMdaSimpleToneGenerator : public TMdaToneGenerator
|
sl@0
|
117 |
/**
|
sl@0
|
118 |
*@internalTechnology
|
sl@0
|
119 |
*/
|
sl@0
|
120 |
{
|
sl@0
|
121 |
public:
|
sl@0
|
122 |
void SetFrequencyAndDuration(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
|
sl@0
|
123 |
virtual void Reset();
|
sl@0
|
124 |
virtual TInt GetNextTone();
|
sl@0
|
125 |
private:
|
sl@0
|
126 |
TTimeIntervalMicroSeconds iDuration;
|
sl@0
|
127 |
TInt iFrequency;
|
sl@0
|
128 |
TBool iPlayed;
|
sl@0
|
129 |
};
|
sl@0
|
130 |
|
sl@0
|
131 |
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
* Dual tone synthesis
|
sl@0
|
134 |
* Generates a tone consisting of two sine waves of different
|
sl@0
|
135 |
* frequencies summed together.
|
sl@0
|
136 |
*
|
sl@0
|
137 |
* @internalTechnology
|
sl@0
|
138 |
*/
|
sl@0
|
139 |
class TMdaDualToneGenerator : public TMdaToneGenerator
|
sl@0
|
140 |
{
|
sl@0
|
141 |
public:
|
sl@0
|
142 |
void SetFrequencyAndDuration(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
|
sl@0
|
143 |
virtual void Reset();
|
sl@0
|
144 |
virtual TInt GetNextTone();
|
sl@0
|
145 |
private:
|
sl@0
|
146 |
TTimeIntervalMicroSeconds iDuration;
|
sl@0
|
147 |
TInt iFrequencyOne;
|
sl@0
|
148 |
TInt iFrequencyTwo;
|
sl@0
|
149 |
TBool iPlayed;
|
sl@0
|
150 |
};
|
sl@0
|
151 |
|
sl@0
|
152 |
//
|
sl@0
|
153 |
// DTMF tone synthesis
|
sl@0
|
154 |
//
|
sl@0
|
155 |
|
sl@0
|
156 |
class TMdaDTMFGenerator : public TMdaToneGenerator
|
sl@0
|
157 |
/**
|
sl@0
|
158 |
*@internalTechnology
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
{
|
sl@0
|
161 |
public:
|
sl@0
|
162 |
virtual void Reset();
|
sl@0
|
163 |
void SetToneDurations( const TTimeIntervalMicroSeconds32 aOn,
|
sl@0
|
164 |
const TTimeIntervalMicroSeconds32 aOff,
|
sl@0
|
165 |
const TTimeIntervalMicroSeconds32 aPause);
|
sl@0
|
166 |
void SetString(const TDesC& aDTMFString);
|
sl@0
|
167 |
private:
|
sl@0
|
168 |
virtual TInt GetNextTone();
|
sl@0
|
169 |
private:
|
sl@0
|
170 |
const TDesC* iDTMFString;
|
sl@0
|
171 |
TTimeIntervalMicroSeconds32 iOn;
|
sl@0
|
172 |
TTimeIntervalMicroSeconds32 iOff;
|
sl@0
|
173 |
TTimeIntervalMicroSeconds32 iPause;
|
sl@0
|
174 |
TInt iOnSamples;
|
sl@0
|
175 |
TInt iOffSamples;
|
sl@0
|
176 |
TInt iPauseSamples;
|
sl@0
|
177 |
TInt iChar;
|
sl@0
|
178 |
TBool iPlayToneOff;
|
sl@0
|
179 |
};
|
sl@0
|
180 |
|
sl@0
|
181 |
//
|
sl@0
|
182 |
// Tone sequence synthesis
|
sl@0
|
183 |
//
|
sl@0
|
184 |
|
sl@0
|
185 |
const TInt KMaxSequenceStack = 6;
|
sl@0
|
186 |
class TMdaSequenceGenerator : public TMdaToneGenerator
|
sl@0
|
187 |
/**
|
sl@0
|
188 |
*@internalTechnology
|
sl@0
|
189 |
*/
|
sl@0
|
190 |
{
|
sl@0
|
191 |
public:
|
sl@0
|
192 |
virtual void Reset();
|
sl@0
|
193 |
void SetSequenceData(const TDesC8& aSequenceData);
|
sl@0
|
194 |
private:
|
sl@0
|
195 |
virtual TInt GetNextTone();
|
sl@0
|
196 |
private:
|
sl@0
|
197 |
const TDesC8* iSequenceData;
|
sl@0
|
198 |
const TInt16* iInstructionPtr;
|
sl@0
|
199 |
const TInt16* iLastInstruction;
|
sl@0
|
200 |
TInt iStack[KMaxSequenceStack];
|
sl@0
|
201 |
TInt iStackIndex;
|
sl@0
|
202 |
};
|
sl@0
|
203 |
|
sl@0
|
204 |
const TInt KBufferLength = 0x1000;
|
sl@0
|
205 |
|
sl@0
|
206 |
// Public Media Server includes
|
sl@0
|
207 |
|
sl@0
|
208 |
class TMdaPtr8 : public TPtr8 //needed for this WINS Impl of Tone Gen
|
sl@0
|
209 |
{
|
sl@0
|
210 |
public:
|
sl@0
|
211 |
TMdaPtr8()
|
sl@0
|
212 |
: TPtr8(0,0,0) {};
|
sl@0
|
213 |
inline void Set(const TDes8& aDes)
|
sl@0
|
214 |
{ TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.MaxLength()); };
|
sl@0
|
215 |
inline void SetLengthOnly(const TDes8& aDes)
|
sl@0
|
216 |
{ TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
|
sl@0
|
217 |
inline void Set(const TPtrC8& aDes)
|
sl@0
|
218 |
{ TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); };
|
sl@0
|
219 |
inline void Shift(TInt aOffset)
|
sl@0
|
220 |
{ SetLength(Length()-aOffset); iMaxLength-=aOffset; iPtr+=aOffset; };
|
sl@0
|
221 |
};
|
sl@0
|
222 |
|
sl@0
|
223 |
|
sl@0
|
224 |
#endif
|