os/mm/devsoundextensions/effects/AudioEqualizer/AudioEqualizerProxy/Src/AudioEqualizerProxy.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 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:   Implementation of the audio equalizer proxy class
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 // INCLUDE FILES
    22 
    23 #ifdef _DEBUG
    24 #include <e32svr.h>
    25 #endif
    26 
    27 #include "AudioEqualizerProxy.h"
    28 #include "AudioEqualizerEventObserver.h"
    29 #include <CustomInterfaceUtility.h>
    30 
    31 
    32 // ============================ MEMBER FUNCTIONS ===============================
    33 
    34 // -----------------------------------------------------------------------------
    35 // CAudioEqualizerProxy::CAudioEqualizerProxy
    36 // C++ default constructor can NOT contain any code, that
    37 // might leave.
    38 // -----------------------------------------------------------------------------
    39 //
    40 CAudioEqualizerProxy::CAudioEqualizerProxy(
    41 	TMMFMessageDestinationPckg aMessageHandler,
    42 	MCustomCommand& aCustomCommand,
    43 	CCustomInterfaceUtility* aCustomInterfaceUtility )
    44 	: 	iCustomCommand(&aCustomCommand),
    45 		iMessageHandler(aMessageHandler),
    46 		iCustomInterfaceUtility(aCustomInterfaceUtility)
    47 
    48     {
    49     }
    50 
    51 // Destructor
    52 CAudioEqualizerProxy::~CAudioEqualizerProxy()
    53     {
    54     // Remove the custom interface message handler before we destroy the proxy.
    55     if(iCustomInterfaceUtility)
    56         iCustomInterfaceUtility->RemoveCustomInterface(iMessageHandler);
    57 	delete iAudioEqualizerEventObserver;
    58 	delete iCustomInterfaceUtility;
    59 	}
    60 
    61 // -----------------------------------------------------------------------------
    62 // CAudioEqualizerProxy::NewL
    63 // Static function for creating an instance of the Audio Equalizer object.
    64 // -----------------------------------------------------------------------------
    65 //
    66 EXPORT_C CAudioEqualizerProxy* CAudioEqualizerProxy::NewL(
    67 	TMMFMessageDestinationPckg aMessageHandler,
    68     MCustomCommand& aCustomCommand,
    69     CCustomInterfaceUtility* aCustomInterfaceUtility )
    70     {
    71     CAudioEqualizerProxy* self = new (ELeave) CAudioEqualizerProxy(aMessageHandler, aCustomCommand, aCustomInterfaceUtility);
    72     CleanupStack::PushL(self);
    73     self->ConstructL();
    74     CleanupStack::Pop(self);
    75     return self;
    76 	}
    77 
    78 // -----------------------------------------------------------------------------
    79 // CAudioEqualizerProxy::ConstructL
    80 // -----------------------------------------------------------------------------
    81 //
    82 void CAudioEqualizerProxy::ConstructL()
    83     {
    84 #ifdef _DEBUG
    85     RDebug::Print(_L("CAudioEqualizerProxy::ConstructL"));
    86 #endif
    87     iAudioEqualizerEventObserver = CAudioEqualizerEventObserver::NewL(iMessageHandler, *iCustomCommand, *this);
    88     StartObserver();
    89     // sends a message to fetch initial data.
    90     TEfAudioEqualizerDataPckg dataPckgFrom;
    91 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefInitialize, KNullDesC8, KNullDesC8, dataPckgFrom);
    92 	SetEffectData(dataPckgFrom);
    93 
    94 	TUint8 band = 0;
    95 	TPckgBuf<TUint8> bandPckg;
    96 	bandPckg() = 0;
    97 
    98 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefGetNumberOfBands, KNullDesC8, KNullDesC8, bandPckg);
    99 	band = bandPckg();
   100 
   101 	if ( !band ) // Number of bands should be > 0.
   102 		{
   103 		User::Leave(KErrNotReady);
   104 		}
   105 
   106 	TEfAudioEqualizerBand bandData;
   107 	TEfAudioEqualizerBandDataPckg bandDataPckg;
   108 	TInt8 numberOfBands = band;
   109 	for(TInt i=1; i<=numberOfBands; i++)
   110 		{
   111 		band = i;
   112 		bandPckg() = band;
   113 		iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefInitializeBand, bandPckg, KNullDesC8, bandDataPckg);
   114 		bandData = bandDataPckg();
   115 		if(iBandsData.Append(bandData))
   116 			{
   117 			User::Leave(KErrNoMemory);
   118 			}
   119 		}
   120 
   121 	}
   122 
   123 
   124 // -----------------------------------------------------------------------------
   125 // CAudioEqualizerProxy::ApplyL
   126 // Apply the Audio Equalizer settings.
   127 // -----------------------------------------------------------------------------
   128 //
   129 EXPORT_C void CAudioEqualizerProxy::ApplyL()
   130 	{
   131 #ifdef _DEBUG
   132     RDebug::Print(_L("CAudioEqualizerProxy::Apply"));
   133 #endif
   134 
   135 	if ( !iHaveUpdateRights )
   136 		{
   137 		User::Leave(KErrAccessDenied);
   138 		}
   139 
   140 //	TUint32 mask = 1;
   141 	iAudioEqualizerData.iEnabled = iEnabled;
   142 	iAudioEqualizerData.iEnforced = iEnforced;
   143 	iAudioEqualizerData.iHaveUpdateRights = iHaveUpdateRights;
   144 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefApply, DoEffectData(), KNullDesC8);
   145 
   146 #ifdef _DEBUG
   147     RDebug::Print(_L("CAudioEqualizerProxy::Apply - BandChange = %x"), iBandChange);
   148 #endif
   149 	iCustomCommand->CustomCommandSync(iMessageHandler, (TInt)EAefApplyBand, DoBandDataL(1, ETrue), KNullDesC8);
   150 
   151 		iBandChange = 0; // clear flags
   152 	}
   153 
   154 // -----------------------------------------------------------------------------
   155 // CAudioEqualizerProxy::StartObserver
   156 // Starts the event observer. The event observer monitors asynchronous events
   157 // from the message handler.
   158 // -----------------------------------------------------------------------------
   159 //
   160 void CAudioEqualizerProxy::StartObserver()
   161 	{
   162 #ifdef _DEBUG
   163     RDebug::Print(_L("CAudioEqualizerProxy::StartObserver"));
   164 #endif
   165 
   166 	iAudioEqualizerEventObserver->Start();
   167 	}
   168 
   169 // -----------------------------------------------------------------------------
   170 // CAudioEqualizerProxy::AudioEqualizerEvent
   171 // Checks which data member has changed and notify the observers.
   172 // -----------------------------------------------------------------------------
   173 //
   174 void CAudioEqualizerProxy::AudioEqualizerEventL(
   175 	const TDesC8& aBuffer )
   176 	{
   177 #ifdef _DEBUG
   178     RDebug::Print(_L("CAudioEqualizerProxy::AudioEqualizerEventL"));
   179 #endif
   180 
   181 	TEfAudioEqualizerCombinedDataPckg dataPckgFrom;
   182 	dataPckgFrom.Copy(aBuffer);
   183 	TEfAudioEqualizerCombined newEqualizerCombinedData = dataPckgFrom();
   184 
   185 	TUint8 event = 0;
   186 
   187 	if ( newEqualizerCombinedData.iAudioEqualizerDataValid ) // Equalizer Data Changed
   188 		{
   189 		if ( newEqualizerCombinedData.iEnabled != iAudioEqualizerData.iEnabled )
   190 			{
   191 			iAudioEqualizerData.iEnabled = newEqualizerCombinedData.iEnabled;
   192 			iEnabled = newEqualizerCombinedData.iEnabled;
   193 			if ( iAudioEqualizerData.iEnabled )
   194 				{
   195 				event = MAudioEffectObserver::KEnabled;
   196 				}
   197 			else
   198 				{
   199 				event = MAudioEffectObserver::KDisabled;
   200 				}
   201 			}
   202 		else if ( newEqualizerCombinedData.iEnforced != iAudioEqualizerData.iEnforced )
   203 			{
   204 			iAudioEqualizerData.iEnforced = newEqualizerCombinedData.iEnforced;
   205 			iEnforced = newEqualizerCombinedData.iEnforced;
   206 			if ( iAudioEqualizerData.iEnforced )
   207 				{
   208 				event = MAudioEffectObserver::KEnforced;
   209 				}
   210 			else
   211 				{
   212 				event = MAudioEffectObserver::KNotEnforced;
   213 				}
   214 			}
   215 		else if ( newEqualizerCombinedData.iHaveUpdateRights != iAudioEqualizerData.iHaveUpdateRights )
   216 			{
   217 			iAudioEqualizerData.iHaveUpdateRights = newEqualizerCombinedData.iHaveUpdateRights;
   218 			iHaveUpdateRights = newEqualizerCombinedData.iHaveUpdateRights;
   219 			if ( iAudioEqualizerData.iHaveUpdateRights )
   220 				{
   221 				event = MAudioEffectObserver::KGainedUpdateRights;
   222 				}
   223 			else
   224 				{
   225 				event = MAudioEffectObserver::KLostUpdateRights;
   226 				}
   227 			}
   228 
   229 		}
   230 
   231 	else if ( newEqualizerCombinedData.iAudioEqualizerBandDataValid ) // Equalizer band data changed
   232 		{
   233 		TInt bandId = newEqualizerCombinedData.iBandId-1;
   234 		iBandsData[bandId].iBandLevel = newEqualizerCombinedData.iBandLevel;
   235 		iBandsData[bandId].iBandWidth = newEqualizerCombinedData.iBandWidth;
   236 		iBandsData[bandId].iCenterFrequency = newEqualizerCombinedData.iCenterFrequency;
   237 		iBandsData[bandId].iCrossoverFrequency = newEqualizerCombinedData.iCrossoverFrequency;
   238 		event = MAudioEffectObserver::KSpecificEffectBase + newEqualizerCombinedData.iBandId;
   239 		}
   240 
   241 
   242 
   243 	if (!event)
   244 		return;
   245 
   246 	for ( TInt i = 0; i < iObservers.Count(); i++ )
   247 		{
   248 		iObservers[i]->EffectChanged(this, event);
   249 		}
   250 	}
   251 
   252 
   253 // ========================== OTHER EXPORTED FUNCTIONS =========================
   254 
   255 
   256