javauis/amms_qt/mmacontrol/src.emc/cammsemcspectatorlocationcontrol.cpp
branchRCL_3
changeset 25 ae942d28ec0e
parent 17 0fd27995241b
equal deleted inserted replaced
24:6c158198356e 25:ae942d28ec0e
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Manipulates the virtual location of the SoundSource3D.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <logger.h>
       
    21 #include <e32math.h>
       
    22 #include "cammsemcspectatorlocationcontrol.h"
       
    23 
       
    24 #ifdef _DEBUG
       
    25 // CONSTANTS
       
    26 const TInt KAMMSMinRadius = 0;
       
    27 #endif // _DEBUG
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CAMMSEMCSpectatorLocationControl::NewLC
       
    34 // Two-phased constructor.
       
    35 // -----------------------------------------------------------------------------
       
    36 CAMMSEMCSpectatorLocationControl* CAMMSEMCSpectatorLocationControl::NewLC(
       
    37     CMMAPlayer* aPlayer)
       
    38 {
       
    39     CAMMSEMCSpectatorLocationControl* self =
       
    40         new(ELeave) CAMMSEMCSpectatorLocationControl(aPlayer);
       
    41 
       
    42     CleanupStack::PushL(self);
       
    43 
       
    44     return self;
       
    45 }
       
    46 
       
    47 // Destructor
       
    48 CAMMSEMCSpectatorLocationControl::~CAMMSEMCSpectatorLocationControl()
       
    49 {
       
    50     LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorLocationControl::CAMMSEMCSpectatorLocationControl");
       
    51     // Perform DeallocateControl, if the state change has not yet performed it.
       
    52     DeallocateControl();
       
    53 }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CAMMSEMCSpectatorLocationControl::PrepareControlL
       
    57 // Function which is called after the correct state is set in Player.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CAMMSEMCSpectatorLocationControl::PrepareControlL()
       
    61 {
       
    62     // Perform the action only for the first time, skip if called afterwards
       
    63     if (!iMListenerLocationControl)
       
    64     {
       
    65         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorLocationControl::PrepareControlL");
       
    66         //Create Location Effect Control
       
    67         iStreamControl = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->StreamControl();
       
    68         iFactory = (static_cast<CMMAEMCAudioPlayer*>(iMMAPlayer))->MMFactory();
       
    69 
       
    70         MEffectControl* temp(NULL);
       
    71         User::LeaveIfError(iFactory->CreateEffectControl(KListenerLocationEffectControl, temp));
       
    72         iMListenerLocationControl  = static_cast<MListenerLocationControl*>(temp);
       
    73         User::LeaveIfError(iStreamControl->AddEffect(*iMListenerLocationControl));
       
    74         iMListenerLocationControl->Enable();
       
    75     }
       
    76 }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CAMMSEMCSpectatorLocationControl::DeallocateControl
       
    80 // Function which is called after the correct state is set in Player.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CAMMSEMCSpectatorLocationControl::DeallocateControl()
       
    84 {
       
    85     if (iMListenerLocationControl)
       
    86     {
       
    87         LOG( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorLocationControl::DeallocateControl");
       
    88 
       
    89         // Location for Audio can be disabled or enabled
       
    90         iMListenerLocationControl->Disable();
       
    91         //return the control to factory
       
    92         MEffectControl* temp = iMListenerLocationControl;
       
    93         iStreamControl->RemoveEffect(*temp);
       
    94         // Delete the Effect
       
    95         MEffectControl* tempCtrl = iMListenerLocationControl;
       
    96         iFactory->DeleteEffectControl(tempCtrl);
       
    97         iMListenerLocationControl = NULL;
       
    98     }
       
    99 }
       
   100 
       
   101 const TDesC& CAMMSEMCSpectatorLocationControl::ClassName() const
       
   102 {
       
   103     return KAMMSEMCSpectatorLocationControl;
       
   104 }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CAMMSEMCSpectatorLocationControl::SetLocationCartesianL
       
   109 // Moves the object to the new location.
       
   110 // -----------------------------------------------------------------------------
       
   111 void CAMMSEMCSpectatorLocationControl::SetLocationCartesianL(
       
   112     TInt& aX,
       
   113     TInt& aY,
       
   114     TInt& aZ)
       
   115 {
       
   116     // Sets the cartesian coordinates for the source location.
       
   117 
       
   118     LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorLocationControl::SetLocationCartesianL: %d, %d, %d",
       
   119                aX, aY, aZ);
       
   120 
       
   121     iMListenerLocationControl->SetLocationCartesian(aX, aY, aZ);
       
   122 
       
   123     // Apply updated settings to EMC API.
       
   124     iMListenerLocationControl->Apply();
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CAMMSEMCSpectatorLocationControl::LocationCartesian
       
   129 // Gets the coordinates of the current location.
       
   130 // -----------------------------------------------------------------------------
       
   131 void CAMMSEMCSpectatorLocationControl::LocationCartesian(
       
   132     TInt& aX, TInt& aY, TInt& aZ)
       
   133 {
       
   134     // Gets the cartesian coordinates for the location of the Listener position.
       
   135     // The coordinates of the positions are in millimeters.
       
   136     iMListenerLocationControl->LocationCartesian(aX, aY, aZ);
       
   137 }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CAMMSEMCSpectatorLocationControl::SetLocationSphericalL
       
   141 // Moves the object to the new location.
       
   142 // -----------------------------------------------------------------------------
       
   143 void CAMMSEMCSpectatorLocationControl::SetLocationSphericalL(
       
   144     TInt& aAzimuth,
       
   145     TInt& aElevation,
       
   146     TInt& aRadius)
       
   147 {
       
   148     // Check in debug build that aRadius is within valid range.
       
   149     __ASSERT_DEBUG(aRadius >= KAMMSMinRadius, User::Invariant());
       
   150 
       
   151     // Sets the spherical coordinates for the location of the source position.
       
   152     // The parameters are thousandths of radians
       
   153 
       
   154     LOG3( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorLocationControl::SetLocationSphericalL: %d, %d, %d",
       
   155                aAzimuth, aElevation, aRadius);
       
   156 
       
   157     TInt32 convertedAzimuth = (TInt32)(aAzimuth *
       
   158                                        KDegToRad * 1000);
       
   159 
       
   160     TInt32 convertedElevation = (TInt32)(aElevation *
       
   161                                          KDegToRad * 1000);
       
   162 
       
   163     LOG2( EJavaAMMS, EInfo, "AMMS::CAMMSEMCSpectatorLocationControl::SetLocationSphericalL: %d, %d",
       
   164                convertedAzimuth, convertedElevation);
       
   165 
       
   166     iMListenerLocationControl->SetLocationSpherical(
       
   167         convertedAzimuth, convertedElevation, (TInt32&)aRadius);
       
   168 
       
   169     // Apply updated settings to EMC API.
       
   170     iMListenerLocationControl->Apply();
       
   171 }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CAMMSEMCSpectatorLocationControl::CAMMSEMCSpectatorLocationControl
       
   175 // C++ default constructor can NOT contain any code, that
       
   176 // might leave.
       
   177 // -----------------------------------------------------------------------------
       
   178 CAMMSEMCSpectatorLocationControl::CAMMSEMCSpectatorLocationControl(CMMAPlayer* aPlayer)
       
   179         : CAMMSLocationControl(aPlayer)
       
   180 {
       
   181     iMMAPlayer = aPlayer;
       
   182 }
       
   183 
       
   184 //  End of File