sl@0: /* sl@0: * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Implementation of the doppler effect class sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: sl@0: // INCLUDE FILES sl@0: sl@0: #ifdef _DEBUG sl@0: #include sl@0: #endif sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: sl@0: //360 degrees: sl@0: #define TWO_PI 6283 sl@0: //180 degrees: sl@0: #define PI 3142 sl@0: //90 degrees: sl@0: #define QUARTER_PI 1570 sl@0: sl@0: // ============================ MEMBER FUNCTIONS =============================== sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::CDoppler sl@0: // C++ default constructor can NOT contain any code, that sl@0: // might leave. sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C CDoppler::CDoppler() sl@0: : iDopplerData(), sl@0: iDataPckgTo(iDopplerData), sl@0: iDataPckgFrom(iDopplerData) sl@0: { sl@0: } sl@0: sl@0: // Destructor sl@0: EXPORT_C CDoppler::~CDoppler() sl@0: { sl@0: } sl@0: sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::CartesianVelocity sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C void CDoppler::CartesianVelocity( TInt32& aX, TInt32& aY, TInt32& aZ ) sl@0: { sl@0: aX = iDopplerData.iVelocityX; sl@0: aY = iDopplerData.iVelocityY; sl@0: aZ = iDopplerData.iVelocityZ; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::Factor sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C TUint32 CDoppler::Factor() const sl@0: { sl@0: return iDopplerData.iFactor; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::FactorMax sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C TUint32 CDoppler::FactorMax() const sl@0: { sl@0: return iDopplerData.iMaxFactor; sl@0: } sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::SetCartesianVelocityL sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C void CDoppler::SetCartesianVelocityL( TInt32 aX, TInt32 aY, TInt32 aZ ) sl@0: { sl@0: iDopplerData.iVelocityX = aX; sl@0: iDopplerData.iVelocityY = aY; sl@0: iDopplerData.iVelocityZ = aZ; sl@0: sl@0: sl@0: TReal SqrtXYZ = 0, squareX = 0, squareY = 0, squareZ = 0; sl@0: Math::Pow(squareX, aX, 2); sl@0: Math::Pow(squareY, aY, 2); sl@0: Math::Pow(squareZ, aZ, 2); sl@0: sl@0: TReal sum = squareX + squareY + squareZ; sl@0: sl@0: Math::Sqrt(SqrtXYZ, sum); sl@0: sl@0: //Singularity region sl@0: if(!((aX==0) && (aZ==0))) sl@0: { sl@0: sl@0: TReal zDividedByXAtan = atan2 (-aX, -aZ); sl@0: sl@0: if (zDividedByXAtan > 0) sl@0: iDopplerData.iAzimuth = -(TInt32) (zDividedByXAtan * 1000 + 0.5); sl@0: else sl@0: iDopplerData.iAzimuth = -(TInt32) (zDividedByXAtan * 1000 - 0.5); sl@0: } sl@0: // else { we are exactly on Y-axis and therefore azimuth is undefined; let's use the previous azimuth value instead } sl@0: sl@0: sl@0: if (!((aX ==0) && (aY == 0) && (aZ == 0))) sl@0: { sl@0: sl@0: TReal result; sl@0: TReal yDividedBySqrtXYZ = aY/SqrtXYZ; sl@0: User::LeaveIfError(Math::ASin(result, yDividedBySqrtXYZ)); //was ACos sl@0: sl@0: if (result > 0) sl@0: iDopplerData.iElevation = (TInt32) (result * 1000 + 0.5); sl@0: else sl@0: iDopplerData.iElevation = (TInt32) (result * 1000 - 0.5); sl@0: sl@0: } sl@0: // else { we are exactly in origin and therefore elevation is undefined; let's use the previous elevation value instead } sl@0: sl@0: iDopplerData.iRadius= (TInt32) (SqrtXYZ + 0.5); sl@0: sl@0: sl@0: while(iDopplerData.iElevation > PI) sl@0: { sl@0: iDopplerData.iElevation = iDopplerData.iElevation - TWO_PI; sl@0: } sl@0: sl@0: if(iDopplerData.iElevation > QUARTER_PI) sl@0: { sl@0: iDopplerData.iElevation = iDopplerData.iElevation - (iDopplerData.iElevation - QUARTER_PI) * 2; sl@0: iDopplerData.iAzimuth = iDopplerData.iAzimuth + PI; sl@0: } sl@0: sl@0: while(iDopplerData.iElevation < -PI) sl@0: { sl@0: iDopplerData.iElevation = iDopplerData.iElevation + TWO_PI; sl@0: } sl@0: if(iDopplerData.iElevation < -QUARTER_PI) sl@0: { sl@0: iDopplerData.iElevation = iDopplerData.iElevation + (QUARTER_PI - iDopplerData.iElevation) * 2; sl@0: iDopplerData.iAzimuth = iDopplerData.iAzimuth + PI; sl@0: } sl@0: sl@0: while (iDopplerData.iAzimuth < 0) sl@0: iDopplerData.iAzimuth = iDopplerData.iAzimuth + TWO_PI; sl@0: while (iDopplerData.iAzimuth > TWO_PI) sl@0: iDopplerData.iAzimuth = iDopplerData.iAzimuth - TWO_PI; sl@0: sl@0: sl@0: } sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::SetFactorL sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C void CDoppler::SetFactorL( TUint32 aFactor ) sl@0: { sl@0: if ( (aFactor <= iDopplerData.iMaxFactor) ) sl@0: { sl@0: iDopplerData.iFactor = aFactor; sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: } sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::SetSphericalVelocityL sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C void CDoppler::SetSphericalVelocityL( TInt32 aAzimuth, TInt32 aElevation, TInt32 aRadius ) sl@0: { sl@0: sl@0: while(aElevation > PI) sl@0: { sl@0: aElevation = aElevation - TWO_PI; sl@0: } sl@0: sl@0: if(aElevation > QUARTER_PI) sl@0: { sl@0: aElevation = aElevation - (aElevation - QUARTER_PI) * 2; sl@0: aAzimuth = aAzimuth + PI; sl@0: } sl@0: sl@0: while(aElevation < -PI) sl@0: { sl@0: aElevation = aElevation + TWO_PI; sl@0: } sl@0: if(aElevation < -QUARTER_PI) sl@0: { sl@0: aElevation = aElevation + (QUARTER_PI - aElevation) * 2; sl@0: aAzimuth = aAzimuth + PI; sl@0: } sl@0: sl@0: while (aAzimuth < 0) sl@0: aAzimuth = aAzimuth + TWO_PI; sl@0: while (aAzimuth > TWO_PI) sl@0: aAzimuth = aAzimuth - TWO_PI; sl@0: sl@0: sl@0: iDopplerData.iAzimuth = aAzimuth; sl@0: iDopplerData.iElevation = aElevation; sl@0: iDopplerData.iRadius = aRadius; sl@0: sl@0: sl@0: TReal elevation = aElevation / 1000.0; // conversion from milliradians to radians because Sin and Cos functions eat radians sl@0: sl@0: TReal elevationSin; sl@0: TReal elevationCos; sl@0: User::LeaveIfError( Math::Sin( elevationSin, elevation ) ); sl@0: User::LeaveIfError( Math::Cos( elevationCos, elevation ) ); sl@0: sl@0: TReal azimuthSin; sl@0: TReal azimuthCos; sl@0: User::LeaveIfError( Math::Sin( azimuthSin, aAzimuth / 1000.0) ); sl@0: User::LeaveIfError( Math::Cos(azimuthCos, aAzimuth / 1000.0) ); sl@0: sl@0: sl@0: iDopplerData.iVelocityX = (TInt32)(0.5 + aRadius * elevationCos * azimuthSin); sl@0: iDopplerData.iVelocityY = (TInt32)(0.5 + aRadius * elevationSin); sl@0: iDopplerData.iVelocityZ = (TInt32)(0.5 - aRadius * elevationCos * azimuthCos); sl@0: } sl@0: sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::SphericalVelocity sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C void CDoppler::SphericalVelocity( TInt32& aAzimuth, TInt32& aElevation, TInt32& aRadius ) sl@0: { sl@0: aAzimuth = iDopplerData.iAzimuth; sl@0: aElevation = iDopplerData.iElevation; sl@0: aRadius = iDopplerData.iRadius ; sl@0: sl@0: } sl@0: sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::DoEffectData sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C const TDesC8& CDoppler::DoEffectData() sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CDoppler::DoEffectData")); sl@0: #endif sl@0: iDataPckgTo = iDopplerData; sl@0: return iDataPckgTo; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // CDoppler::SetEffectData sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: EXPORT_C void CDoppler::SetEffectData( sl@0: const TDesC8& aEffectDataBuffer ) sl@0: { sl@0: #ifdef _DEBUG sl@0: RDebug::Print(_L("CDoppler::SetEffectData")); sl@0: #endif sl@0: TEfDopplerDataPckg dataPckg; sl@0: dataPckg.Copy(aEffectDataBuffer); sl@0: iDopplerData = dataPckg(); sl@0: iEnabled = iDopplerData.iEnabled; sl@0: iEnforced = iDopplerData.iEnforced; sl@0: iHaveUpdateRights = iDopplerData.iHaveUpdateRights; sl@0: sl@0: } sl@0: sl@0: sl@0: // ========================== OTHER EXPORTED FUNCTIONS ========================= sl@0: sl@0: // End of File sl@0: