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