javauis/amms_qt/mmacontrol/src/cammsdistanceattenuationcontrol.cpp
changeset 23 98ccebc37403
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     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:  Controls how the sound is attenuated with its distance.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <logger.h>
       
    22 #include "cammsdistanceattenuationcontrol.h"
       
    23 
       
    24 // CONSTANTS
       
    25 namespace
       
    26 {
       
    27 const TInt KAMMSRoomRollOffFactor = 0; // The logical default value set to 0
       
    28 // Rolloff factor 1000 in AMMS is 100 in Effect API
       
    29 const TInt KAMMSRolloffDivider = 10;
       
    30 
       
    31 #ifdef _DEBUG
       
    32 const TInt KAMMSMinDistance = 1;
       
    33 const TInt KAMMSMinRollofFactor = 0;
       
    34 #endif // _DEBUG
       
    35 }
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CAMMSDistanceAttenuationControl::NewLC
       
    41 // Two-phased constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 CAMMSDistanceAttenuationControl* CAMMSDistanceAttenuationControl::NewLC(
       
    44     CMMAPlayer* aPlayer)
       
    45 {
       
    46     CAMMSDistanceAttenuationControl* self =
       
    47         new(ELeave)CAMMSDistanceAttenuationControl(aPlayer);
       
    48 
       
    49     CleanupStack::PushL(self);
       
    50 
       
    51     return self;
       
    52 }
       
    53 
       
    54 // Destructor
       
    55 CAMMSDistanceAttenuationControl::~CAMMSDistanceAttenuationControl()
       
    56 {
       
    57     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSDistanceAttenuationControl::~CAMMSDistanceAttenuationControl");
       
    58 
       
    59     // Perform DeallocateControl, if the state change has not yet performed it.
       
    60     DeallocateControl();
       
    61     delete iDistanceAttenuation;
       
    62 }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CAMMSDistanceAttenuationControl::SetParametersL
       
    66 // Sets all the 3D audio distance attenuation parameters simultaneously.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CAMMSDistanceAttenuationControl::SetParametersL(
       
    70     TInt aMinDistance,
       
    71     TInt aMaxDistance,
       
    72     TBool aMuteAfterMax,
       
    73     TInt aRolloffFactor)
       
    74 {
       
    75     // Check in debug build that parameters are within valid range.
       
    76     __ASSERT_DEBUG(
       
    77         (aMaxDistance > aMinDistance) &&
       
    78         (aMinDistance >= KAMMSMinDistance) &&
       
    79         (aMaxDistance >= KAMMSMinDistance) &&
       
    80         (aRolloffFactor >= KAMMSMinRollofFactor),
       
    81         User::Invariant());
       
    82 
       
    83     // NOTE: Effect API uses hundreths (100 corresponds to 1.00),
       
    84     // but JSR234 uses thousandths (1000 represents a rolloff factor of 1.0)
       
    85     //
       
    86     LOG4( EJavaMMAPI, EInfo, "AMMS::CAMMSDistanceAttenuationControl::SetParametersL %d, %d, %d, %d",
       
    87                aMinDistance, aMaxDistance, aMuteAfterMax, aRolloffFactor);
       
    88 
       
    89     TInt convertedRolloffFactor = aRolloffFactor / KAMMSRolloffDivider;
       
    90 
       
    91     iDistanceAttenuation->SetDistanceAttenuationL(aMinDistance, aMaxDistance,
       
    92             aMuteAfterMax, convertedRolloffFactor, KAMMSRoomRollOffFactor);
       
    93 
       
    94     // Apply updated settings to Effect API.
       
    95     iDistanceAttenuation->ApplyL();
       
    96 }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CAMMSDistanceAttenuationControl::PrepareControlL
       
   100 // Function which is called after the correct state is set in Player.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CAMMSDistanceAttenuationControl::PrepareControlL()
       
   104 {
       
   105     // Perform the action only for the first time, skip if called afterwards
       
   106     if (!iDistanceAttenuation)
       
   107     {
       
   108         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSDistanceAttenuationControl::PrepareControlL");
       
   109 
       
   110         CCustomCommandUtility* customCommandUtility =
       
   111             CreateCustomCommandUtilityL();
       
   112 
       
   113         // Effect API takes the ownership of customCommandUtility.
       
   114         iDistanceAttenuation = CDistanceAttenuation::NewL(
       
   115                                    customCommandUtility);
       
   116 
       
   117         // Enable the Effect API Control
       
   118         iDistanceAttenuation->EnableL();
       
   119     }
       
   120 }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CAMMSDistanceAttenuationControl::DeallocateControl
       
   124 // Function which is called after the correct state is set in Player.
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CAMMSDistanceAttenuationControl::DeallocateControl()
       
   128 {
       
   129     if (iDistanceAttenuation)
       
   130     {
       
   131         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSDistanceAttenuationControl::DeallocateControl");
       
   132 
       
   133         // Disable the Effect API Control
       
   134         TRAPD(err, iDistanceAttenuation->DisableL());
       
   135         if (err != KErrNone)
       
   136         {
       
   137             // The only even theoritically possible error code here would be
       
   138             // KErrAccessDenied which is a result from Effect API calling ApplyL
       
   139             // method without having update rights, but since the Effect
       
   140             // is already created, that situation can be discarded here.
       
   141         }
       
   142 
       
   143         // Delete the Effect API class (it deletes CustomCommandUtility)
       
   144         delete iDistanceAttenuation;
       
   145         iDistanceAttenuation = NULL;
       
   146     }
       
   147 }
       
   148 
       
   149 const TDesC& CAMMSDistanceAttenuationControl::ClassName() const
       
   150 {
       
   151     return KAMMSDistanceAttenuationControl;
       
   152 }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CAMMSDistanceAttenuationControl::CAMMSDistanceAttenuationControl
       
   156 // C++ default constructor can NOT contain any code, that
       
   157 // might leave.
       
   158 // -----------------------------------------------------------------------------
       
   159 CAMMSDistanceAttenuationControl::CAMMSDistanceAttenuationControl(
       
   160     CMMAPlayer* aPlayer)
       
   161         : CAMMSBaseDistanceAttenuationControl(aPlayer)
       
   162 {
       
   163 }
       
   164 
       
   165 //  End of File