voiceui/voiceuivoicerecognition/src/vuictoneplayer.cpp
changeset 0 bf1d17376201
child 19 33b357311f14
equal deleted inserted replaced
-1:000000000000 0:bf1d17376201
       
     1 /*
       
     2 * Copyright (c) 2004-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:  Handles the tone playing for the VoiceUIRecognition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknsoundsystem.h>
       
    21 #include <aknappui.h>
       
    22 
       
    23 #include <centralrepository.h>
       
    24 
       
    25 #include <StringLoader.h>
       
    26 #include <AudioPreference.h>
       
    27 
       
    28 #include <srsfdomaincrkeys.h>
       
    29 
       
    30 #include <vuivoicerecognition.rsg>
       
    31 #include "vuictoneplayer.h"
       
    32 
       
    33 #include "rubydebug.h"
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 // Maximum value of the volume setting in Central Repository
       
    38 const TInt KMaxRepositoryVolume = 10;
       
    39 
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CTonePlayer* CTonePlayer::NewL
       
    45 // Two-phased constructor.
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 CTonePlayer* CTonePlayer::NewL()
       
    49     {
       
    50     CTonePlayer* self = new (ELeave) CTonePlayer;    
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56     
       
    57 // Destructor
       
    58 CTonePlayer::~CTonePlayer()
       
    59     {
       
    60     RUBY_DEBUG0( "CTonePlayer::~CTonePlayer START" );
       
    61 
       
    62     if ( iAudioPlayer )
       
    63         {
       
    64         iAudioPlayer->Close();
       
    65         delete iAudioPlayer;
       
    66         }
       
    67 
       
    68     delete iStartSound;
       
    69     delete iConfirmationSound;
       
    70 
       
    71     iObserver = NULL;
       
    72     
       
    73     RUBY_DEBUG0( "CTonePlayer::~CTonePlayer EXIT" );
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CTonePlayer::CTonePlayer
       
    78 // C++ default constructor can NOT contain any code, that
       
    79 // might leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CTonePlayer::CTonePlayer()
       
    83     {
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CTonePlayer::ConstructL
       
    88 // Symbian 2nd phase constructor can leave.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CTonePlayer::ConstructL()
       
    92     {
       
    93     RUBY_DEBUG_BLOCK( "CTonePlayer::ConstructL" );
       
    94 
       
    95     iAudioPlayer = CMdaAudioPlayerUtility::NewL( *this,
       
    96                                                  KAudioPriorityVoiceDial, 
       
    97                                                  TMdaPriorityPreference( KAudioPrefVoiceStarting ) );
       
    98 
       
    99     iVolume = KErrGeneral;
       
   100     
       
   101     CRepository* client = CRepository::NewLC( KCRUidSRSFSettings );
       
   102     client->Get( KSRSFPlaybackVolume, iVolume );
       
   103     CleanupStack::PopAndDestroy( client );
       
   104 
       
   105     iStartSound = StringLoader::LoadL( R_VOICE_START_SOUND_PATH );
       
   106     iConfirmationSound = StringLoader::LoadL( R_VOICE_CONFIRMATION_SOUND_PATH );
       
   107     }
       
   108   
       
   109  // ---------------------------------------------------------
       
   110 // CTonePlayer::RegisterObserver
       
   111 // Sets the observer
       
   112 // ---------------------------------------------------------
       
   113 //  
       
   114 void CTonePlayer::RegisterObserver( MMdaAudioPlayerCallback* aObserver )
       
   115     {
       
   116     RUBY_DEBUG0( "CTonePlayer::RegisterObserver START" );
       
   117     
       
   118     iObserver = aObserver;
       
   119     
       
   120     RUBY_DEBUG0( "CTonePlayer::RegisterObserver EXIT" );
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------
       
   124 // CTonePlayer::InitToneL
       
   125 // Perform initialization for Playing the appropriate tone
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CTonePlayer::InitToneL( TInt aSid )
       
   129    {
       
   130     RUBY_DEBUG_BLOCK( "CTonePlayer::PlayToneInitL" );
       
   131     
       
   132     iAudioPlayer->Stop();
       
   133     iAudioPlayer->Close();
       
   134 
       
   135     if ( aSid == EAvkonSIDNameDiallerStartTone )
       
   136         {
       
   137         RUBY_DEBUG0( "CTonePlayer::InitToneL - case: EAvkonSIDNameDiallerStartTone" );
       
   138 
       
   139         TRAPD( err, iAudioPlayer->OpenFileL( *iStartSound ) );
       
   140         if ( err )
       
   141             {
       
   142             RUBY_ERROR1( "CTonePlayer::InitToneL - err [%d]", err );
       
   143                     
       
   144             // Cannot play sound, but observer still needs to be notified
       
   145             iObserver->MapcInitComplete( err, 0 );
       
   146             }
       
   147         }
       
   148     else if ( aSid == EAvkonSIDConfirmationTone )
       
   149         {
       
   150         RUBY_DEBUG0( "CTonePlayer::InitToneL - case: EAvkonSIDConfirmationTone" );
       
   151 
       
   152         TRAPD( err, iAudioPlayer->OpenFileL( *iConfirmationSound ) );
       
   153         if ( err )
       
   154             {
       
   155             RUBY_ERROR1( "CTonePlayer::InitToneL - err [%d]", err );
       
   156                     
       
   157             // Cannot play sound, but observer still needs to be notified
       
   158             iObserver->MapcInitComplete( err, 0 );
       
   159             }
       
   160         }
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CTonePlayer::PlayTone
       
   165 // Plays the appropriate tone
       
   166 // ---------------------------------------------------------
       
   167 //
       
   168 void CTonePlayer::PlayTone( TInt aSid )
       
   169     {
       
   170     RUBY_DEBUG0( "CTonePlayer::PlayTone START" );
       
   171     
       
   172     switch ( aSid )
       
   173         {
       
   174         case EAvkonSIDNameDiallerStartTone:
       
   175         case EAvkonSIDConfirmationTone:
       
   176             {
       
   177             iAudioPlayer->SetVolume( ScaledVolume() );
       
   178             iAudioPlayer->Play();
       
   179             break;
       
   180             }
       
   181             
       
   182         case EAvkonSIDNameDiallerAbortTone:
       
   183         case EAvkonSIDNameDiallerErrorTone:
       
   184             {
       
   185             if ( iAvkonAppUiBase )
       
   186                 {               
       
   187                 iAudioPlayer->Stop();
       
   188                 iAudioPlayer->Close();
       
   189                 
       
   190                 iAvkonAppUiBase->KeySounds()->PlaySound( aSid );
       
   191                 }
       
   192 
       
   193             MapcPlayComplete( KErrNone );
       
   194             break;
       
   195             }
       
   196         
       
   197         default:
       
   198             break;
       
   199         }
       
   200     
       
   201     RUBY_DEBUG0( "CTonePlayer::PlayTone EXIT" );
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CTonePlayer::MapcInitComplete
       
   206 // CMdaAudioPlayerUtility initialization complete
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CTonePlayer::MapcInitComplete( TInt aError,
       
   210                                     const TTimeIntervalMicroSeconds& aDuration )
       
   211     {
       
   212     RUBY_DEBUG0( "CTonePlayer::MapcInitComplete START" );
       
   213 
       
   214     iObserver->MapcInitComplete( aError, aDuration );
       
   215     
       
   216     RUBY_DEBUG0( "CTonePlayer::MapcInitComplete EXIT" );
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // CTonePlayer::MapcPlayComplete
       
   221 // Playback complete, notify observer
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 void CTonePlayer::MapcPlayComplete( TInt aError )
       
   225     {
       
   226     RUBY_DEBUG0( "CTonePlayer::MapcPlayComplete START" );
       
   227 
       
   228     iAudioPlayer->Stop();
       
   229     iAudioPlayer->Close();
       
   230     iObserver->MapcPlayComplete( aError );
       
   231 
       
   232     RUBY_DEBUG0( "CTonePlayer::MapcPlayComplete EXIT" );
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CTonePlayer::ScaledVolume
       
   237 // ---------------------------------------------------------------------------
       
   238 //    
       
   239 TInt CTonePlayer::ScaledVolume()
       
   240     {
       
   241     TInt volume = iAudioPlayer->MaxVolume();
       
   242     if ( iVolume >= 0 )
       
   243         {
       
   244         // Scale value
       
   245         volume = ( iVolume * volume ) / KMaxRepositoryVolume;
       
   246         }
       
   247         
       
   248     return volume;
       
   249     }
       
   250 
       
   251 //  End of File
       
   252