accessoryservices/accessoryserver/src/accpolaudiodevicetopology/accpolvolumecontrol.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 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:  Implementation for volume control object.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <accpolvolumecontrol.h>
       
    19 #include "acc_debug.h"
       
    20 
       
    21 const TUint16 KAccVolumeIncreaseMax = 0x7FFF;
       
    22 const TUint16 KAccVolumeIncreaseMin = 0;
       
    23 const TUint16 KAccVolumeDecreaseMax = 0xFFFF;
       
    24 const TUint16 KAccVolumeDecreaseMin = 0x8000;
       
    25 const TUint16 KAccVolumeStep = 256;
       
    26 // -----------------------------------------------------------------------------
       
    27 // CAccPolVolumeControl::CAccPolVolumeControl()
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CAccPolVolumeControl::CAccPolVolumeControl( CAccPolObjectCon* aObject ) :
       
    31     CAccPolAudioControlBase( EAccPolAudioVolumeControlObject, aObject )
       
    32     {
       
    33     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::CAccPolVolumeControl() - Enter" );
       
    34     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::CAccPolVolumeControl() - Return" );
       
    35     }
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CAccPolMuteControl::CAccPolMuteControl()
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CAccPolVolumeControl::CAccPolVolumeControl( TUint32 aChannel,
       
    42     const TReal aVolumeDb,
       
    43     const TReal aMinVolumeDb,
       
    44     const TReal aMaxVolumeDb,
       
    45     const TReal aVolumeResDb ) :
       
    46     CAccPolAudioControlBase( EAccPolAudioVolumeControlObject, aChannel )
       
    47     {
       
    48     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::CAccPolVolumeControl() - Enter" );
       
    49     iVolumeDb = aVolumeDb;
       
    50     iMinVolumeDb = aMinVolumeDb;
       
    51     iMaxVolumeDb = aMaxVolumeDb;
       
    52     iVolumeResDb = aVolumeResDb;
       
    53     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::CAccPolVolumeControl() - Return" );
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CAccPolVolumeControl::NewL()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CAccPolVolumeControl* CAccPolVolumeControl::NewL(
       
    61     CAccPolObjectCon* aObject )
       
    62     {
       
    63     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewL() - Enter" );
       
    64     CAccPolVolumeControl* self = CAccPolVolumeControl::NewLC( aObject );
       
    65     CleanupStack::Pop( self );
       
    66     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewL() - Return" );
       
    67     return self;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CAccPolVolumeControl::NewLC()
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CAccPolVolumeControl* CAccPolVolumeControl::NewLC(
       
    75     CAccPolObjectCon* aObject )
       
    76     {
       
    77     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewLC() - Enter" );
       
    78     CAccPolVolumeControl* self = new ( ELeave ) CAccPolVolumeControl( aObject );
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewLC() - Return" );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // CAccPolVolumeControl::NewL()
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CAccPolVolumeControl* CAccPolVolumeControl::NewL( TUint32 aChannel,
       
    90     const TReal aVolumeDb,
       
    91     const TReal aMinVolumeDb,
       
    92     const TReal aMaxVolumeDb,
       
    93     const TReal aVolumeResDb )
       
    94     {
       
    95     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewL() - Enter" );
       
    96     CAccPolVolumeControl* self = CAccPolVolumeControl::NewLC( aChannel,
       
    97         aVolumeDb, aMinVolumeDb, aMaxVolumeDb, aVolumeResDb );
       
    98 
       
    99     CleanupStack::Pop( self );
       
   100     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewL() - Return" );
       
   101     return self;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CAccPolVolumeControl::NewLC()
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 EXPORT_C CAccPolVolumeControl* CAccPolVolumeControl::NewLC( TUint32 aChannel,
       
   109     const TReal aVolumeDb,
       
   110     const TReal aMinVolumeDb,
       
   111     const TReal aMaxVolumeDb,
       
   112     const TReal aVolumeResDb )
       
   113 
       
   114     {
       
   115     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewLC() - Enter" );
       
   116     CAccPolVolumeControl* self = new ( ELeave ) CAccPolVolumeControl( aChannel,
       
   117         aVolumeDb, aMinVolumeDb, aMaxVolumeDb, aVolumeResDb );
       
   118 
       
   119     CleanupStack::PushL( self );
       
   120     self->ConstructL();
       
   121     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::NewLC() - Return" );
       
   122     return self;
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CAccPolVolumeControl::ConstructL()
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CAccPolVolumeControl::ConstructL()
       
   130     {
       
   131     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::ConstructL() - Enter" );
       
   132     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::ConstructL() - Return" );
       
   133     }
       
   134 
       
   135 // Destructor
       
   136 EXPORT_C CAccPolVolumeControl::~CAccPolVolumeControl()
       
   137     {
       
   138     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::~CAccPolVolumeControl() - Enter" );
       
   139     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::~CAccPolVolumeControl() - Return" );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CAccPolVolumeControl::MapToDb()
       
   144 // Maps volume level from USB specific integer value to real decibel value
       
   145 // -----------------------------------------------------------------------------
       
   146 // 
       
   147 TReal CAccPolVolumeControl::MapToDb( TUint16 aValue ) const
       
   148     {
       
   149     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MapToDb() - Enter" );
       
   150     TReal value;
       
   151     TReal integer = aValue;
       
   152     TReal step = KAccVolumeStep;
       
   153 
       
   154     if( ( aValue <= KAccVolumeIncreaseMax )
       
   155         && ( aValue > KAccVolumeIncreaseMin ) )
       
   156         {
       
   157         value = integer / step;
       
   158         }
       
   159     else
       
   160         if( ( aValue <= KAccVolumeDecreaseMax ) && ( aValue
       
   161             >= KAccVolumeDecreaseMin ) )
       
   162             {
       
   163             value = -( ( ( static_cast<TReal> ( KAccVolumeDecreaseMax )
       
   164                 - integer ) + 1 ) / step );
       
   165             }
       
   166         else
       
   167             {
       
   168             value = aValue;
       
   169             }
       
   170     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MapToDb() - Return=%f", value );
       
   171     return value;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CAccPolVolumeControl::CAccPolVolumeControl()
       
   176 // Maps volume level from decibel value to USB specific integer value
       
   177 // -----------------------------------------------------------------------------
       
   178 // 
       
   179 TUint16 CAccPolVolumeControl::MapFromDb( TReal aValue ) const
       
   180     {
       
   181     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MapFromDb() - Enter" );
       
   182     TUint16 value;
       
   183     TReal step = KAccVolumeStep;
       
   184 
       
   185     if( aValue > 0 )
       
   186         {
       
   187         value = ( aValue * step );
       
   188         }
       
   189     else
       
   190         if( aValue < 0 )
       
   191             {
       
   192             value = ( ( static_cast<TReal> ( KAccVolumeDecreaseMax ) + ( aValue
       
   193                 * step ) ) + 1 );
       
   194             }
       
   195         else
       
   196             {
       
   197             value = 0;
       
   198             }
       
   199 
       
   200     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MapFromDb() - Return=%d", value );
       
   201     return value;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CAccPolVolumeControl::operator()
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C CAccPolVolumeControl& CAccPolVolumeControl::operator=(
       
   209     const CAccPolVolumeControl& aVolumeControlObject )
       
   210     {
       
   211     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::operator() - Enter" );
       
   212     CAccPolAudioControlBase::operator=(
       
   213         ( CAccPolAudioControlBase& )aVolumeControlObject );
       
   214     iVolumeDb = aVolumeControlObject.VolumeDb();
       
   215     iMinVolumeDb = aVolumeControlObject.MinVolumeDb();
       
   216     iMaxVolumeDb = aVolumeControlObject.MaxVolumeDb();
       
   217     iVolumeResDb = aVolumeControlObject.VolumeResDb();
       
   218     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::operator() - Return" );
       
   219     return ( *this );
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CAccPolVolumeControl::SetVolumeLevel()
       
   224 // ---------------------------------------------------------------------------
       
   225 //   
       
   226 EXPORT_C void CAccPolVolumeControl::SetVolumeDb( TReal aVolumeDb )
       
   227     {
       
   228     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetVolumeDb() - Volume level=%f", iVolumeDb );
       
   229     iVolumeDb = aVolumeDb;
       
   230     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetVolumeDb() - Return" );
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CAccPolVolumeControl::SetVolumeLevel()
       
   235 // ---------------------------------------------------------------------------
       
   236 //   
       
   237 EXPORT_C void CAccPolVolumeControl::SetMinVolumeDb( TReal aMinVolumeDb )
       
   238     {
       
   239     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetMinVolumeDb() - Min volume level=%f", iMinVolumeDb );
       
   240     iMinVolumeDb = aMinVolumeDb;
       
   241     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetMinVolumeDb() - Return" );
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // CAccPolVolumeControl::SetVolumeLevel()
       
   246 // ---------------------------------------------------------------------------
       
   247 //   
       
   248 EXPORT_C void CAccPolVolumeControl::SetMaxVolumeDb( TReal aMaxVolumeDb )
       
   249     {
       
   250     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetMaxVolumeDb() - Max volume level=%f", iMaxVolumeDb );
       
   251     iMaxVolumeDb = aMaxVolumeDb;
       
   252     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetMaxVolumeDb() - Return" );
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CAccPolVolumeControl::SetVolumeResDb()
       
   257 // ---------------------------------------------------------------------------
       
   258 //   
       
   259 EXPORT_C void CAccPolVolumeControl::SetVolumeResDb( TReal aVolumeResDb )
       
   260     {
       
   261     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetVolumeResDb() -  Volume level res=%f", iVolumeResDb );
       
   262     iVolumeResDb = aVolumeResDb;
       
   263     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::SetVolumeResDb() - Return" );
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CAccPolVolumeControl::VolumeLevel()
       
   268 // ---------------------------------------------------------------------------
       
   269 //       
       
   270 EXPORT_C TReal CAccPolVolumeControl::VolumeDb() const
       
   271     {
       
   272     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::VolumeDb() - Enter" );
       
   273     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::VolumeDb() - Return=%f", iVolumeDb );
       
   274     return iVolumeDb;
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CAccPolVolumeControl::VolumeLevel()
       
   279 // ---------------------------------------------------------------------------
       
   280 //       
       
   281 EXPORT_C TReal CAccPolVolumeControl::MinVolumeDb() const
       
   282     {
       
   283     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MinVolumeDb() - Enter" );
       
   284     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MinVolumeDb() - Return=%f", iMinVolumeDb );
       
   285     return iMinVolumeDb;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CAccPolVolumeControl::VolumeLevel()
       
   290 // ---------------------------------------------------------------------------
       
   291 //       
       
   292 EXPORT_C TReal CAccPolVolumeControl::MaxVolumeDb() const
       
   293     {
       
   294     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MaxVolumeDb() - Enter" );
       
   295     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::MaxVolumeDb() - Return=%f", iMaxVolumeDb );
       
   296     return iMaxVolumeDb;
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CAccPolVolumeControl::VolumeResDb()
       
   301 // ---------------------------------------------------------------------------
       
   302 //       
       
   303 EXPORT_C TReal CAccPolVolumeControl::VolumeResDb() const
       
   304     {
       
   305     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::VolumeResDb() - Enter" );
       
   306     API_TRACE_1( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::VolumeResDb() - Return=%f", iVolumeResDb );
       
   307     return iVolumeResDb;
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CAccPolVolumeControl::ExternalizeL()
       
   312 // ---------------------------------------------------------------------------
       
   313 //   
       
   314 void CAccPolVolumeControl::ExternalizeL( RWriteStream& aStream ) const
       
   315     {
       
   316     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolMuteControl::ExternalizeL() - Enter" );
       
   317 
       
   318     //Add object type at the beginning
       
   319     aStream.WriteUint8L( ObjectType() );
       
   320 
       
   321     // Externalize base.
       
   322     ExternalizeAudioControlbaseL( aStream );
       
   323 
       
   324     //Volume level
       
   325     aStream.WriteUint16L( MapFromDb( iVolumeDb ) );
       
   326     aStream.WriteUint16L( MapFromDb( iMinVolumeDb ) );
       
   327     aStream.WriteUint16L( MapFromDb( iMaxVolumeDb ) );
       
   328     aStream.WriteUint16L( MapFromDb( iVolumeResDb ) );
       
   329     API_TRACE_( "[AccFW:A CCPOLAUDIODEVICETOPOLOGY] CAccPolMuteControl::ExternalizeL - Return" );
       
   330     }
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // CAccPolVolumeControl::InternalizeL()
       
   334 // ---------------------------------------------------------------------------
       
   335 //  
       
   336 void CAccPolVolumeControl::InternalizeL( RReadStream& aStream )
       
   337     {
       
   338     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolMuteControl::InternalizeL() - Enter" );
       
   339     InternalizeAudioControlbaseL( aStream );
       
   340     iVolumeDb = MapToDb( aStream.ReadUint16L() );
       
   341     iMinVolumeDb = MapToDb( aStream.ReadUint16L() );
       
   342     iMaxVolumeDb = MapToDb( aStream.ReadUint16L() );
       
   343     iVolumeResDb = MapToDb( aStream.ReadUint16L() );
       
   344     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolMuteControl::InternalizeL - Return" );
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CAccPolVolumeControl::DuplicateL()
       
   349 // ---------------------------------------------------------------------------
       
   350 //
       
   351 CAccPolObjectBase* CAccPolVolumeControl::DuplicateLC( CAccPolObjectCon* aObject )
       
   352     {
       
   353     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::DuplicateLC() - Enter" );
       
   354     CAccPolVolumeControl* aVolume = CAccPolVolumeControl::NewLC( aObject );
       
   355     *aVolume = ( CAccPolVolumeControl& )*this;
       
   356     API_TRACE_( "[AccFW: ACCPOLAUDIODEVICETOPOLOGY] CAccPolVolumeControl::DuplicateLC() - Return" );
       
   357     return aVolume;
       
   358     }
       
   359 
       
   360 //  End of File