javauis/amms_qt/mmacontrol/src.emc/cammsemcaudiovirtualizercontrol.cpp
branchRCL_3
changeset 18 9ac0a0a7da70
parent 17 0fd27995241b
child 19 71c436fe3ce0
equal deleted inserted replaced
17:0fd27995241b 18:9ac0a0a7da70
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Virtualizes audio channels.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <logger.h>
       
    22 #include "cammsemcaudiovirtualizercontrol.h"
       
    23 
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KAMMSEMCDefaultStereoWideningLevel = 100;
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CAMMSEMCAudioVirtualizerControl::NewLC
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 CAMMSEMCAudioVirtualizerControl* CAMMSEMCAudioVirtualizerControl::NewLC(
       
    36     CMMAPlayer* aPlayer)
       
    37 {
       
    38     CAMMSEMCAudioVirtualizerControl* self =
       
    39         new(ELeave) CAMMSEMCAudioVirtualizerControl(aPlayer);
       
    40 
       
    41     CleanupStack::PushL(self);
       
    42     self->ConstructL();
       
    43 
       
    44     return self;
       
    45 }
       
    46 
       
    47 // Destructor
       
    48 CAMMSEMCAudioVirtualizerControl::~CAMMSEMCAudioVirtualizerControl()
       
    49 {
       
    50     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::~CAMMSEMCAudioVirtualizerControl");
       
    51 
       
    52     // Perform DeallocateControl, if the state change has not yet performed it.
       
    53     DeallocateControl();
       
    54     if (iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility)
       
    55         delete iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility;
       
    56     delete iPresetNames;
       
    57 
       
    58 }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CAMMSEMCAudioVirtualizerControl::SetPresetL
       
    62 // Sets the effect according to the given preset.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CAMMSEMCAudioVirtualizerControl::SetPresetL(const TDesC& aPreset)
       
    66 {
       
    67 
       
    68     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::SetPresetL \"%S\"",
       
    69               aPreset.Ptr());
       
    70     CStereoWidening *iStereoWidening = NULL;
       
    71     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->PrepareEmptyStereoWideningUtilitiesL();
       
    72     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->GetPresetNamesL(*iPresetNames);
       
    73     TInt presetPosition = 0;
       
    74     TInt findPreset = iPresetNames->Find(aPreset, presetPosition);
       
    75     if (findPreset == 0)  // Find returns zero, if a matching element is found.
       
    76     {
       
    77         iStereoWidening = iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->GetStereoWideningAtPresetIndexL(presetPosition);
       
    78         iCurrentPreset = presetPosition;
       
    79     }
       
    80     else
       
    81     {
       
    82         iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->DeleteEmptyStereoWideningUtilities();
       
    83         User::Leave(KErrArgument);
       
    84     }
       
    85 
       
    86     if (!iStereoWidening)
       
    87     {
       
    88         iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->DeleteEmptyStereoWideningUtilities();
       
    89         return;
       
    90     }
       
    91     //Get all preset data here
       
    92     TUint8 iStereoWideningLevel = iStereoWidening->StereoWideningLevel();
       
    93     // Set all preset data to EMC
       
    94     iMStereoWideningControl->SetStereoWideningLevel(iStereoWideningLevel);
       
    95     iMStereoWideningControl->Apply();
       
    96     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->DeleteEmptyStereoWideningUtilities();
       
    97     LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::SetPresetL \"%S\" GetPresetL OK",
       
    98               aPreset.Ptr());
       
    99 }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CAMMSEMCAudioVirtualizerControl::PresetNamesL
       
   103 // Gets the available preset names.
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 const CDesCArray& CAMMSEMCAudioVirtualizerControl::PresetNamesL()
       
   107 {
       
   108     // Returns an array of all preset names (pre-defined and user-defined).
       
   109     // The pre-defined presets are in the beginning of the list.
       
   110     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->PrepareEmptyStereoWideningUtilitiesL();
       
   111     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->GetPresetNamesL(*iPresetNames);
       
   112     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->DeleteEmptyStereoWideningUtilities();
       
   113     return *iPresetNames;
       
   114 }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CAMMSEMCAudioVirtualizerControl::PresetL
       
   118 // Gets the current preset.
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 const TDesC& CAMMSEMCAudioVirtualizerControl::PresetL()
       
   122 {
       
   123     //if no preset is set, return null
       
   124     if (iCurrentPreset < 0)
       
   125     {
       
   126         return KNullDesC;
       
   127     }
       
   128 
       
   129     else
       
   130     {
       
   131         // Retrieves a Preset with the given index from the utility class
       
   132         iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->PrepareEmptyStereoWideningUtilitiesL();
       
   133         iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->GetPresetAtIndexL(iPresetName , iCurrentPreset);
       
   134         iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->DeleteEmptyStereoWideningUtilities();
       
   135         return iPresetName;
       
   136     }
       
   137 }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CAMMSEMCAudioVirtualizerControl::SetEnabledL
       
   141 // Enables/disables the effect.
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CAMMSEMCAudioVirtualizerControl::SetEnabledL(TBool aEnable)
       
   145 {
       
   146     if (aEnable)
       
   147     {
       
   148         // Enable the effect.
       
   149         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::SetEnabledL(true).");
       
   150         iMStereoWideningControl->Enable();
       
   151         iMStereoWideningControl->SetStereoWideningLevel(KAMMSEMCDefaultStereoWideningLevel);
       
   152         iMStereoWideningControl->Apply();
       
   153     }
       
   154     else
       
   155     {
       
   156         // Disable the effect
       
   157 
       
   158         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::SetEnabledL(false).");
       
   159         iMStereoWideningControl->Disable();
       
   160     }
       
   161 
       
   162 }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CAMMSEMCAudioVirtualizerControl::PrepareControlL
       
   166 // Function which is called after the correct state is set in Player.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CAMMSEMCAudioVirtualizerControl::PrepareControlL()
       
   170 {
       
   171     // Perform the action only for the first time, skip if called afterwards
       
   172     if (!iMStereoWideningControl)
       
   173     {
       
   174         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::PrepareControlL");
       
   175         //Create AudioVirtualizer Effect Control
       
   176         iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl();
       
   177         iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory();
       
   178 
       
   179         MEffectControl* temp(NULL);
       
   180         User::LeaveIfError(iFactory->CreateEffectControl(KStereoWideningEffectControl, temp));
       
   181         iMStereoWideningControl  = static_cast<MStereoWideningControl*>(temp);
       
   182         User::LeaveIfError(iStreamControl->AddEffect(*iMStereoWideningControl));
       
   183     }
       
   184 }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CAMMSEMCAudioVirtualizerControl::DeallocateControl
       
   188 // Function which is called after the correct state is set in Player.
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CAMMSEMCAudioVirtualizerControl::DeallocateControl()
       
   192 {
       
   193 
       
   194     if (iMStereoWideningControl)
       
   195     {
       
   196         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl::DeallocateControl");
       
   197 
       
   198         // StereoWidening for Audio can be disabled or enabled
       
   199         TRAPD(err,iMStereoWideningControl->Disable());
       
   200         if (err != KErrNone)
       
   201         {
       
   202             //Some EMC Error
       
   203             ELOG1( EJavaAMMS, "AMMS::CAMMSEMCAudioVirtualizerControl::DeallocateControl err = %d",err);
       
   204         }
       
   205         //return the control to factory
       
   206         MEffectControl* temp = iMStereoWideningControl;
       
   207         iStreamControl->RemoveEffect(*temp);
       
   208         // Delete the Effect
       
   209         MEffectControl* tempCtrl = iMStereoWideningControl;
       
   210         iFactory->DeleteEffectControl(tempCtrl);
       
   211         iMStereoWideningControl = NULL;
       
   212     }
       
   213 }
       
   214 
       
   215 const TDesC& CAMMSEMCAudioVirtualizerControl::ClassName() const
       
   216 {
       
   217     return KAMMSEMCAudioVirtualizerControl;
       
   218 }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CAMMSEMCAudioVirtualizerControl::SetEnforcedL
       
   223 // Enforces the effect to be in use.
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CAMMSEMCAudioVirtualizerControl::SetEnforcedL(TBool aEnforced)
       
   227 {
       
   228     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl:SetEnforcedL");
       
   229     // Indicate the effect is to be enforced or not. ETrue = Enforced.
       
   230 
       
   231     iMStereoWideningControl->Enforce(aEnforced);
       
   232 
       
   233     ApplySettingsL();
       
   234 
       
   235 }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CAMMSEMCAudioVirtualizerControl::Enforced
       
   239 // Returns the current enforced setting of the effect.
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 TBool CAMMSEMCAudioVirtualizerControl::Enforced()
       
   243 {
       
   244     // Returns ETrue if the effect is enforced, EFalse if not enforced.
       
   245     TBool enforced;
       
   246     iMStereoWideningControl->IsEnforced(enforced);
       
   247     return enforced;
       
   248 
       
   249 }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CAMMSEMCAudioVirtualizerControl::SetScopeL
       
   253 // Sets the scope of the effect.
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CAMMSEMCAudioVirtualizerControl::SetScopeL(TInt aScope)
       
   257 {
       
   258     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl:SetScopeL");
       
   259     __ASSERT_DEBUG(
       
   260         (aScope == CAMMSEffectControlGroup::EScopeLiveOnly),
       
   261         User::Invariant());
       
   262     // Just to suppress warning in release build
       
   263     (void)aScope;
       
   264 }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CAMMSEMCAudioVirtualizerControl::Scope
       
   268 // Returns the scope in which the effect is present.
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 TInt CAMMSEMCAudioVirtualizerControl::Scope()
       
   272 {
       
   273     // For now only the (LIVE_ONLY) scope is supported.
       
   274     return CAMMSEffectControlGroup::EScopeLiveOnly;
       
   275 }
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CAMMSEMCAudioVirtualizerControl::ApplySettingsL
       
   279 // Apply changed settings if Effect is in enabled state.
       
   280 // -----------------------------------------------------------------------------
       
   281 void CAMMSEMCAudioVirtualizerControl::ApplySettingsL()
       
   282 {
       
   283     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl:ApplySettingsL called, checking state");
       
   284     TBool enabled;
       
   285     iMStereoWideningControl->IsEnabled(enabled);
       
   286     if (enabled)
       
   287     {
       
   288         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCAudioVirtualizerControl:ApplySettingsL calling ApplyL");
       
   289         iMStereoWideningControl->Apply();
       
   290     }
       
   291 }
       
   292 
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CAMMSEMCAudioVirtualizerControl::ConstructL
       
   296 // Symbian 2nd phase constructor can leave.
       
   297 // -----------------------------------------------------------------------------
       
   298 void CAMMSEMCAudioVirtualizerControl::ConstructL()
       
   299 {
       
   300     // Create array for preset names
       
   301     iPresetNames = new(ELeave) CDesCArrayFlat(1);
       
   302 
       
   303     // Set current preset to a negative value as it is not set yet
       
   304     iCurrentPreset = -1;
       
   305 
       
   306     CAMMSEffectControl::ConstructL();
       
   307     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility =
       
   308         new(ELeave)CAMMSEMCAudioVirtualizerEnvironmentalPresetUtility;
       
   309     iAMMSEMCAudioVirtualizerEnvironmentalPresetUtility->ConstructL();
       
   310 }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CAMMSEMCAudioVirtualizerControl::CAMMSEMCAudioVirtualizerControl
       
   314 // C++ default constructor can NOT contain any code, that
       
   315 // might leave.
       
   316 // -----------------------------------------------------------------------------
       
   317 CAMMSEMCAudioVirtualizerControl::CAMMSEMCAudioVirtualizerControl(
       
   318     CMMAPlayer* aPlayer)
       
   319         : CAMMSEffectControl(aPlayer)
       
   320 {
       
   321     iMMAPlayer = aPlayer;
       
   322 }
       
   323 
       
   324 //  End of File