os/mm/devsoundextensions/effects/AudioEqualizer/AudioEqualizerProxy/Src/AudioEqualizerProxy.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsoundextensions/effects/AudioEqualizer/AudioEqualizerProxy/Src/AudioEqualizerProxy.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,256 @@
1.4 +/*
1.5 +* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description: Implementation of the audio equalizer proxy class
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +
1.24 +// INCLUDE FILES
1.25 +
1.26 +#ifdef _DEBUG
1.27 +#include <e32svr.h>
1.28 +#endif
1.29 +
1.30 +#include "AudioEqualizerProxy.h"
1.31 +#include "AudioEqualizerEventObserver.h"
1.32 +#include <CustomInterfaceUtility.h>
1.33 +
1.34 +
1.35 +// ============================ MEMBER FUNCTIONS ===============================
1.36 +
1.37 +// -----------------------------------------------------------------------------
1.38 +// CAudioEqualizerProxy::CAudioEqualizerProxy
1.39 +// C++ default constructor can NOT contain any code, that
1.40 +// might leave.
1.41 +// -----------------------------------------------------------------------------
1.42 +//
1.43 +CAudioEqualizerProxy::CAudioEqualizerProxy(
1.44 + TMMFMessageDestinationPckg aMessageHandler,
1.45 + MCustomCommand& aCustomCommand,
1.46 + CCustomInterfaceUtility* aCustomInterfaceUtility )
1.47 + : iCustomCommand(&aCustomCommand),
1.48 + iMessageHandler(aMessageHandler),
1.49 + iCustomInterfaceUtility(aCustomInterfaceUtility)
1.50 +
1.51 + {
1.52 + }
1.53 +
1.54 +// Destructor
1.55 +CAudioEqualizerProxy::~CAudioEqualizerProxy()
1.56 + {
1.57 + // Remove the custom interface message handler before we destroy the proxy.
1.58 + if(iCustomInterfaceUtility)
1.59 + iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
1.60 + delete iAudioEqualizerEventObserver;
1.61 + delete iCustomInterfaceUtility;
1.62 + }
1.63 +
1.64 +// -----------------------------------------------------------------------------
1.65 +// CAudioEqualizerProxy::NewL
1.66 +// Static function for creating an instance of the Audio Equalizer object.
1.67 +// -----------------------------------------------------------------------------
1.68 +//
1.69 +EXPORT_C CAudioEqualizerProxy* CAudioEqualizerProxy::NewL(
1.70 + TMMFMessageDestinationPckg aMessageHandler,
1.71 + MCustomCommand& aCustomCommand,
1.72 + CCustomInterfaceUtility* aCustomInterfaceUtility )
1.73 + {
1.74 + CAudioEqualizerProxy* self = new (ELeave) CAudioEqualizerProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
1.75 + CleanupStack::PushL(self);
1.76 + self->ConstructL();
1.77 + CleanupStack::Pop(self);
1.78 + return self;
1.79 + }
1.80 +
1.81 +// -----------------------------------------------------------------------------
1.82 +// CAudioEqualizerProxy::ConstructL
1.83 +// -----------------------------------------------------------------------------
1.84 +//
1.85 +void CAudioEqualizerProxy::ConstructL()
1.86 + {
1.87 +#ifdef _DEBUG
1.88 + RDebug::Print(_L("CAudioEqualizerProxy::ConstructL"));
1.89 +#endif
1.90 + iAudioEqualizerEventObserver = CAudioEqualizerEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
1.91 + StartObserver();
1.92 + // sends a message to fetch initial data.
1.93 + TEfAudioEqualizerDataPckg dataPckgFrom;
1.94 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
1.95 + SetEffectData(dataPckgFrom);
1.96 +
1.97 + TUint8 band = 0;
1.98 + TPckgBuf<TUint8> bandPckg;
1.99 + bandPckg() = 0;
1.100 +
1.101 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefGetNumberOfBands, KNullDesC8, KNullDesC8, bandPckg);
1.102 + band = bandPckg();
1.103 +
1.104 + if ( !band ) // Number of bands should be > 0.
1.105 + {
1.106 + User::Leave(KErrNotReady);
1.107 + }
1.108 +
1.109 + TEfAudioEqualizerBand bandData;
1.110 + TEfAudioEqualizerBandDataPckg bandDataPckg;
1.111 + TInt8 numberOfBands = band;
1.112 + for(TInt i=1; i<=numberOfBands; i++)
1.113 + {
1.114 + band = i;
1.115 + bandPckg() = band;
1.116 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefInitializeBand, bandPckg, KNullDesC8, bandDataPckg);
1.117 + bandData = bandDataPckg();
1.118 + if(iBandsData.Append(bandData))
1.119 + {
1.120 + User::Leave(KErrNoMemory);
1.121 + }
1.122 + }
1.123 +
1.124 + }
1.125 +
1.126 +
1.127 +// -----------------------------------------------------------------------------
1.128 +// CAudioEqualizerProxy::ApplyL
1.129 +// Apply the Audio Equalizer settings.
1.130 +// -----------------------------------------------------------------------------
1.131 +//
1.132 +EXPORT_C void CAudioEqualizerProxy::ApplyL()
1.133 + {
1.134 +#ifdef _DEBUG
1.135 + RDebug::Print(_L("CAudioEqualizerProxy::Apply"));
1.136 +#endif
1.137 +
1.138 + if ( !iHaveUpdateRights )
1.139 + {
1.140 + User::Leave(KErrAccessDenied);
1.141 + }
1.142 +
1.143 +// TUint32 mask = 1;
1.144 + iAudioEqualizerData.iEnabled = iEnabled;
1.145 + iAudioEqualizerData.iEnforced = iEnforced;
1.146 + iAudioEqualizerData.iHaveUpdateRights = iHaveUpdateRights;
1.147 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefApply, DoEffectData(), KNullDesC8);
1.148 +
1.149 +#ifdef _DEBUG
1.150 + RDebug::Print(_L("CAudioEqualizerProxy::Apply - BandChange = %x"), iBandChange);
1.151 +#endif
1.152 + iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefApplyBand, DoBandDataL(1, ETrue), KNullDesC8);
1.153 +
1.154 + iBandChange = 0; // clear flags
1.155 + }
1.156 +
1.157 +// -----------------------------------------------------------------------------
1.158 +// CAudioEqualizerProxy::StartObserver
1.159 +// Starts the event observer. The event observer monitors asynchronous events
1.160 +// from the message handler.
1.161 +// -----------------------------------------------------------------------------
1.162 +//
1.163 +void CAudioEqualizerProxy::StartObserver()
1.164 + {
1.165 +#ifdef _DEBUG
1.166 + RDebug::Print(_L("CAudioEqualizerProxy::StartObserver"));
1.167 +#endif
1.168 +
1.169 + iAudioEqualizerEventObserver->Start();
1.170 + }
1.171 +
1.172 +// -----------------------------------------------------------------------------
1.173 +// CAudioEqualizerProxy::AudioEqualizerEvent
1.174 +// Checks which data member has changed and notify the observers.
1.175 +// -----------------------------------------------------------------------------
1.176 +//
1.177 +void CAudioEqualizerProxy::AudioEqualizerEventL(
1.178 + const TDesC8& aBuffer )
1.179 + {
1.180 +#ifdef _DEBUG
1.181 + RDebug::Print(_L("CAudioEqualizerProxy::AudioEqualizerEventL"));
1.182 +#endif
1.183 +
1.184 + TEfAudioEqualizerCombinedDataPckg dataPckgFrom;
1.185 + dataPckgFrom.Copy(aBuffer);
1.186 + TEfAudioEqualizerCombined newEqualizerCombinedData = dataPckgFrom();
1.187 +
1.188 + TUint8 event = 0;
1.189 +
1.190 + if ( newEqualizerCombinedData.iAudioEqualizerDataValid ) // Equalizer Data Changed
1.191 + {
1.192 + if ( newEqualizerCombinedData.iEnabled != iAudioEqualizerData.iEnabled )
1.193 + {
1.194 + iAudioEqualizerData.iEnabled = newEqualizerCombinedData.iEnabled;
1.195 + iEnabled = newEqualizerCombinedData.iEnabled;
1.196 + if ( iAudioEqualizerData.iEnabled )
1.197 + {
1.198 + event = MAudioEffectObserver::KEnabled;
1.199 + }
1.200 + else
1.201 + {
1.202 + event = MAudioEffectObserver::KDisabled;
1.203 + }
1.204 + }
1.205 + else if ( newEqualizerCombinedData.iEnforced != iAudioEqualizerData.iEnforced )
1.206 + {
1.207 + iAudioEqualizerData.iEnforced = newEqualizerCombinedData.iEnforced;
1.208 + iEnforced = newEqualizerCombinedData.iEnforced;
1.209 + if ( iAudioEqualizerData.iEnforced )
1.210 + {
1.211 + event = MAudioEffectObserver::KEnforced;
1.212 + }
1.213 + else
1.214 + {
1.215 + event = MAudioEffectObserver::KNotEnforced;
1.216 + }
1.217 + }
1.218 + else if ( newEqualizerCombinedData.iHaveUpdateRights != iAudioEqualizerData.iHaveUpdateRights )
1.219 + {
1.220 + iAudioEqualizerData.iHaveUpdateRights = newEqualizerCombinedData.iHaveUpdateRights;
1.221 + iHaveUpdateRights = newEqualizerCombinedData.iHaveUpdateRights;
1.222 + if ( iAudioEqualizerData.iHaveUpdateRights )
1.223 + {
1.224 + event = MAudioEffectObserver::KGainedUpdateRights;
1.225 + }
1.226 + else
1.227 + {
1.228 + event = MAudioEffectObserver::KLostUpdateRights;
1.229 + }
1.230 + }
1.231 +
1.232 + }
1.233 +
1.234 + else if ( newEqualizerCombinedData.iAudioEqualizerBandDataValid ) // Equalizer band data changed
1.235 + {
1.236 + TInt bandId = newEqualizerCombinedData.iBandId-1;
1.237 + iBandsData[bandId].iBandLevel = newEqualizerCombinedData.iBandLevel;
1.238 + iBandsData[bandId].iBandWidth = newEqualizerCombinedData.iBandWidth;
1.239 + iBandsData[bandId].iCenterFrequency = newEqualizerCombinedData.iCenterFrequency;
1.240 + iBandsData[bandId].iCrossoverFrequency = newEqualizerCombinedData.iCrossoverFrequency;
1.241 + event = MAudioEffectObserver::KSpecificEffectBase + newEqualizerCombinedData.iBandId;
1.242 + }
1.243 +
1.244 +
1.245 +
1.246 + if (!event)
1.247 + return;
1.248 +
1.249 + for ( TInt i = 0; i < iObservers.Count(); i++ )
1.250 + {
1.251 + iObservers[i]->EffectChanged(this, event);
1.252 + }
1.253 + }
1.254 +
1.255 +
1.256 +// ========================== OTHER EXPORTED FUNCTIONS =========================
1.257 +
1.258 +
1.259 +