|
1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Audio Stubs - |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef TONEGENERATOR_H |
|
21 #define TONEGENERATOR_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KMaxSineTable = 256; |
|
28 const TUint KToneBufferSize = 8192; |
|
29 // one second in microseconds |
|
30 const TInt KOneMillionMicroSeconds = 1000000; |
|
31 const TInt KMaxSequenceStack = 6; |
|
32 const TInt KBufferLength = 0x1000; |
|
33 |
|
34 // CLASS DECLARATION |
|
35 |
|
36 /** |
|
37 * Utility class used by DevSound Adaptation to generage PCM data for playing |
|
38 * back tone on WINSCW Reference Implementation.. |
|
39 * |
|
40 * @lib MmfDevSoundAdaptation.lib |
|
41 * @since Series 60 3.0 |
|
42 */ |
|
43 class TSineGen |
|
44 { |
|
45 public: |
|
46 |
|
47 /** |
|
48 * Sets frequency and amplitude. |
|
49 * @since Series 60 3.0 |
|
50 * @param TInt aFrequency Frequency to generate PCM data. |
|
51 * @param TInt aAmplitude Amplitude to generate PCM data. |
|
52 * @return void |
|
53 */ |
|
54 void SetFrequency(TInt aFrequency,TInt aAmplitude); |
|
55 |
|
56 /** |
|
57 * Returns the next sample. |
|
58 * @since Series 60 3.0 |
|
59 * @return TInt Sample. |
|
60 */ |
|
61 TInt NextSample(); |
|
62 |
|
63 private: |
|
64 |
|
65 TUint iPosition; |
|
66 TUint iStep; |
|
67 TInt iAmplitude; |
|
68 static const TInt16 SineTable[KMaxSineTable]; |
|
69 static const TInt16 IncTable[KMaxSineTable]; |
|
70 }; |
|
71 |
|
72 /** |
|
73 * Utility class used by DevSound Adaptation to generage PCM data for playing |
|
74 * back tone on WINSCW Reference Implementation.. |
|
75 * |
|
76 * @lib MmfDevSoundAdaptation.lib |
|
77 * @since Series 60 3.0 |
|
78 */ |
|
79 class TSineWave |
|
80 { |
|
81 public: |
|
82 |
|
83 /** |
|
84 * Generate Sine wave representing tone. |
|
85 * @since Series 60 3.0 |
|
86 * @param TInt16* aDest Destination |
|
87 * @param TInt aCount Count |
|
88 * @return void |
|
89 */ |
|
90 void Generate(TInt16* aDest,TInt aCount); |
|
91 |
|
92 /** |
|
93 * Set frequency amplitude. |
|
94 * @since Series 60 3.0 |
|
95 * @param TInt aFrequency Frequency to generate PCM data. |
|
96 * @param TInt aAmplitude Amplitude to generate PCM data. |
|
97 * @return void |
|
98 */ |
|
99 void SetFrequency(TInt aFrequency,TInt aAmplitude); |
|
100 |
|
101 /** |
|
102 * Set frequency amplitude. |
|
103 * @since Series 60 3.0 |
|
104 * @param TInt aFrequency1 Frequency to generate PCM data. |
|
105 * @param TInt aAmplitude1 Amplitude to generate PCM data. |
|
106 * @param TInt aFrequency2 Frequency to generate PCM data. |
|
107 * @param TInt aAmplitude2 Amplitude to generate PCM data. |
|
108 * @return void |
|
109 */ |
|
110 void SetFrequency(TInt aFrequency1,TInt aAmplitude1,TInt aFrequency2,TInt aAmplitude2); |
|
111 |
|
112 private: |
|
113 TSineGen iGen1; |
|
114 TSineGen iGen2; |
|
115 }; |
|
116 |
|
117 |
|
118 /** |
|
119 * Tone synthesis interface |
|
120 * Defines the abstract interface for tone synthesis |
|
121 * Capable of filling buffers with audio data |
|
122 * |
|
123 * @lib MmfDevSoundAdaptation.lib |
|
124 * @since Series 60 3.0 |
|
125 */ |
|
126 class MMdaToneSynthesis |
|
127 { |
|
128 public: |
|
129 |
|
130 /** |
|
131 * Allocate necessary resources for this kind of synthesis |
|
132 * @since Series 60 3.0 |
|
133 * @param TInt aRate Sampling rate. |
|
134 * @param TInt aChannels Mono/Stereo. |
|
135 * @param TInt aRepeats Tone repeats. |
|
136 * @param TInt aSilence Silence duration between repetation. |
|
137 * @param TInt aRampUp Volume ramping duration. |
|
138 * @return void |
|
139 */ |
|
140 virtual void Configure(TInt aRate, |
|
141 TInt aChannels, |
|
142 TInt aRepeats, |
|
143 TInt aSilence, |
|
144 TInt aRampUp)=0; |
|
145 |
|
146 /** |
|
147 * Reset generator |
|
148 * @since Series 60 3.0 |
|
149 * @return void |
|
150 */ |
|
151 virtual void Reset()=0; |
|
152 |
|
153 /** |
|
154 * Fill supplied buffer with next block of 16bit PCM audio data |
|
155 * @since Series 60 3.0 |
|
156 * @param TDes8& aBuffer A descriptor reference to buffer where data need |
|
157 * to be filled. |
|
158 * @return KErrNone if successfull, else corresponding error code |
|
159 */ |
|
160 virtual TInt FillBuffer(TDes8& aBuffer)=0; |
|
161 }; |
|
162 |
|
163 |
|
164 /** |
|
165 * Tone generator base class |
|
166 * |
|
167 * @lib MmfDevSoundAdaptation.lib |
|
168 * @since Series 60 3.0 |
|
169 */ |
|
170 class TMdaToneGenerator : public MMdaToneSynthesis |
|
171 { |
|
172 public: |
|
173 |
|
174 /** |
|
175 * Configures Tone generator. |
|
176 * @since Series 60 3.0 |
|
177 * @param TInt aRate Sampling rate. |
|
178 * @param TInt aChannels Mono/Stereo. |
|
179 * @param TInt aRepeats Tone repeats. |
|
180 * @param TInt aSilence Silence duration between repetation. |
|
181 * @param TInt aRampUp Volume ramping duration. |
|
182 * @return void |
|
183 */ |
|
184 virtual void Configure(TInt aRate, |
|
185 TInt aChannels, |
|
186 TInt aRepeats, |
|
187 TInt aSilence, |
|
188 TInt aRampUp); |
|
189 |
|
190 /** |
|
191 * Fill supplied buffer with next block of 16bit PCM audio data |
|
192 * @since Series 60 3.0 |
|
193 * @param TDes8& aBuffer A descriptor reference to buffer where data need |
|
194 * to be filled. |
|
195 * @return KErrNone if successfull, else corresponding error code |
|
196 */ |
|
197 virtual TInt FillBuffer(TDes8& aBuffer); |
|
198 |
|
199 protected: |
|
200 |
|
201 /** |
|
202 * Gets the next tone buffer |
|
203 * @since Series 60 3.0 |
|
204 * @return KErrNone if successfull, else corresponding error code |
|
205 */ |
|
206 virtual TInt GetNextTone()=0; |
|
207 |
|
208 /** |
|
209 * Converts duration to PCM samples. |
|
210 * @since Series 60 3.0 |
|
211 * @param const TTimeIntervalMicroSeconds& aDuration Duration. |
|
212 * @return KErrNone if successfull, else corresponding error code |
|
213 */ |
|
214 TInt DurationToSamples(const TTimeIntervalMicroSeconds& aDuration); |
|
215 |
|
216 protected: |
|
217 TSineWave iSineWave; |
|
218 TInt iRate; |
|
219 TInt iChannels; |
|
220 TInt iSamplesLeft; |
|
221 TInt iTrailingSilence; |
|
222 TBool iRampUp; |
|
223 TBool iRampDown; |
|
224 TInt iRepeats; |
|
225 TInt iSilenceBetweenRepeats; |
|
226 TBool iAfterRepeatSilence; |
|
227 TInt iRampUpCount; |
|
228 TInt iRampUpLeft; |
|
229 }; |
|
230 |
|
231 |
|
232 /** |
|
233 * Simple tone synthesis |
|
234 * |
|
235 * @lib MmfDevSoundAdaptation.lib |
|
236 * @since Series 60 3.0 |
|
237 */ |
|
238 class TMdaSimpleToneGenerator : public TMdaToneGenerator |
|
239 { |
|
240 public: |
|
241 |
|
242 /** |
|
243 * Sets frequency and duration for generating PCM data. |
|
244 * @since Series 60 3.0 |
|
245 * @param TInt aFrequency Frequency of tone to be generated. |
|
246 * @param const TTimeIntervalMicroSeconds& aDuration Duration of tone to |
|
247 * be generated. |
|
248 * @return void |
|
249 */ |
|
250 void SetFrequencyAndDuration(TInt aFrequency, |
|
251 const TTimeIntervalMicroSeconds& aDuration); |
|
252 |
|
253 /** |
|
254 * Reset generator |
|
255 * @since Series 60 3.0 |
|
256 * @return void |
|
257 */ |
|
258 virtual void Reset(); |
|
259 |
|
260 /** |
|
261 * Gets the next tone buffer |
|
262 * @since Series 60 3.0 |
|
263 * @return KErrNone if successfull, else corresponding error code |
|
264 */ |
|
265 virtual TInt GetNextTone(); |
|
266 |
|
267 private: |
|
268 TTimeIntervalMicroSeconds iDuration; |
|
269 TInt iFrequency; |
|
270 TBool iPlayed; |
|
271 }; |
|
272 |
|
273 /** |
|
274 * Dual tone synthesis |
|
275 * Generates a tone consisting of two sine waves of different |
|
276 * frequencies summed together. |
|
277 * |
|
278 * @lib MmfDevSoundAdaptation.lib |
|
279 * @since Series 60 3.0 |
|
280 */ |
|
281 class TMdaDualToneGenerator : public TMdaToneGenerator |
|
282 { |
|
283 public: |
|
284 |
|
285 /** |
|
286 * ?member_description. |
|
287 * @since Series 60 3.0 |
|
288 * @param ?arg1 |
|
289 */ |
|
290 void SetFrequencyAndDuration(TInt aFrequencyOne, |
|
291 TInt aFrequencyTwo, |
|
292 const TTimeIntervalMicroSeconds& aDuration); |
|
293 |
|
294 /** |
|
295 * Reset generator |
|
296 * @since Series 60 3.0 |
|
297 * @return void |
|
298 */ |
|
299 virtual void Reset(); |
|
300 |
|
301 /** |
|
302 * Gets the next tone buffer |
|
303 * @since Series 60 3.0 |
|
304 * @return KErrNone if successfull, else corresponding error code |
|
305 */ |
|
306 virtual TInt GetNextTone(); |
|
307 |
|
308 private: |
|
309 TTimeIntervalMicroSeconds iDuration; |
|
310 TInt iFrequencyOne; |
|
311 TInt iFrequencyTwo; |
|
312 TBool iPlayed; |
|
313 }; |
|
314 |
|
315 /** |
|
316 * DTMF tone synthesis |
|
317 * ?other_description_lines |
|
318 * |
|
319 * @lib MmfDevSoundAdaptation.lib |
|
320 * @since Series 60 3.0 |
|
321 */ |
|
322 class TMdaDTMFGenerator : public TMdaToneGenerator |
|
323 { |
|
324 public: |
|
325 |
|
326 /** |
|
327 * Reset generator |
|
328 * @since Series 60 3.0 |
|
329 * @return void |
|
330 */ |
|
331 virtual void Reset(); |
|
332 |
|
333 /** |
|
334 * ?member_description. |
|
335 * @since Series 60 3.0 |
|
336 * @param ?arg1 |
|
337 */ |
|
338 void SetToneDurations( const TTimeIntervalMicroSeconds32 aOn, |
|
339 const TTimeIntervalMicroSeconds32 aOff, |
|
340 const TTimeIntervalMicroSeconds32 aPause); |
|
341 |
|
342 /** |
|
343 * ?member_description. |
|
344 * @since Series 60 3.0 |
|
345 * @param ?arg1 |
|
346 */ |
|
347 void SetString(const TDesC& aDTMFString); |
|
348 |
|
349 private: |
|
350 |
|
351 /** |
|
352 * Gets the next tone buffer |
|
353 * @since Series 60 3.0 |
|
354 * @return KErrNone if successfull, else corresponding error code |
|
355 */ |
|
356 virtual TInt GetNextTone(); |
|
357 |
|
358 private: |
|
359 const TDesC* iDTMFString; |
|
360 TTimeIntervalMicroSeconds32 iOn; |
|
361 TTimeIntervalMicroSeconds32 iOff; |
|
362 TTimeIntervalMicroSeconds32 iPause; |
|
363 TInt iOnSamples; |
|
364 TInt iOffSamples; |
|
365 TInt iPauseSamples; |
|
366 TInt iChar; |
|
367 TBool iPlayToneOff; |
|
368 }; |
|
369 |
|
370 /** |
|
371 * Tone sequence synthesis |
|
372 * ?other_description_lines |
|
373 * |
|
374 * @lib MmfDevSoundAdaptation.lib |
|
375 * @since Series 60 3.0 |
|
376 */ |
|
377 class TMdaSequenceGenerator : public TMdaToneGenerator |
|
378 { |
|
379 public: |
|
380 |
|
381 /** |
|
382 * Reset generator |
|
383 * @since Series 60 3.0 |
|
384 * @return void |
|
385 */ |
|
386 virtual void Reset(); |
|
387 |
|
388 /** |
|
389 * ?member_description. |
|
390 * @since Series 60 3.0 |
|
391 * @param ?arg1 |
|
392 */ |
|
393 void SetSequenceData(const TDesC8& aSequenceData); |
|
394 |
|
395 private: |
|
396 |
|
397 /** |
|
398 * Gets the next tone buffer |
|
399 * @since Series 60 3.0 |
|
400 * @return KErrNone if successfull, else corresponding error code |
|
401 */ |
|
402 virtual TInt GetNextTone(); |
|
403 |
|
404 private: |
|
405 const TDesC8* iSequenceData; |
|
406 const TInt16* iInstructionPtr; |
|
407 const TInt16* iLastInstruction; |
|
408 TInt iStack[KMaxSequenceStack]; |
|
409 TInt iStackIndex; |
|
410 }; |
|
411 |
|
412 |
|
413 /** |
|
414 * Public Media Server includes |
|
415 * ?other_description_lines |
|
416 * |
|
417 * @lib MmfDevSoundAdaptation.lib |
|
418 * @since Series 60 3.0 |
|
419 */ |
|
420 class TMdaPtr8 : public TPtr8 //needed for this WINS Impl of Tone Gen |
|
421 { |
|
422 public: |
|
423 TMdaPtr8() |
|
424 : TPtr8(0,0,0) {}; |
|
425 inline void Set(const TDes8& aDes) |
|
426 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.MaxLength()); }; |
|
427 inline void SetLengthOnly(const TDes8& aDes) |
|
428 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); }; |
|
429 inline void Set(const TPtrC8& aDes) |
|
430 { TPtr8::Set((TUint8*)(aDes.Ptr()),aDes.Length(),aDes.Length()); }; |
|
431 inline void Shift(TInt aOffset) |
|
432 { SetLength(Length()-aOffset); iMaxLength-=aOffset; iPtr+=aOffset; }; |
|
433 }; |
|
434 |
|
435 #endif // TONEGENERATOR_H |
|
436 |
|
437 // End of File |
|
438 |