mmapitest/devsoundexthaitest/src/T_CMMFDevSoundData.cpp
branchRCL_3
changeset 23 545d349d14da
equal deleted inserted replaced
20:67584cc761d1 23:545d349d14da
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "t_cmmfdevsounddata.h"
       
    21 
       
    22 /*@{*/
       
    23 //Constants for HwDevice
       
    24 const TInt KHwDeviceDefaultDataLength = 9;
       
    25 const TInt KFourCCLength = 4;
       
    26 //Supported Input Data Types
       
    27 const TInt KFourCCMaxBitDisplacement = 24;
       
    28 const TInt K8Bits = 8;
       
    29 const TInt KTFourCC = 4;
       
    30 /*@}*/
       
    31 
       
    32 /*@{*/
       
    33 //Command literals
       
    34 _LIT(KCmdNewL,                         "NewL");
       
    35 _LIT(KCmdNewLLoopL,                    "NewLLoopL");
       
    36 _LIT(KCmdDestructor,                   "~");
       
    37 _LIT(KCmdCapabilities,                 "Capabilities");
       
    38 _LIT(KCmdConfig,                       "Config");
       
    39 _LIT(KCmdMaxGain,                      "MaxGain");
       
    40 _LIT(KCmdMaxVolume,                    "MaxVolume");
       
    41 _LIT(KCmdGetPlayBalanceL,              "GetPlayBalanceL");
       
    42 _LIT(KCmdGetRecordBalanceL,            "GetRecordBalanceL");
       
    43 _LIT(KCmdGetSupportedInputDataTypesL,  "GetSupportedInputDataTypesL");
       
    44 _LIT(KCmdGetSupportedOutputDataTypesL, "GetSupportedOutputDataTypesL");
       
    45 _LIT(KCmdSamplesPlayed,                "SamplesPlayed");
       
    46 _LIT(KCmdSamplesRecorded,              "SamplesRecorded");
       
    47 _LIT(KCmdVolume,                       "Volume");
       
    48 _LIT(KCmdGain,                         "Gain");
       
    49 _LIT(KCmdFixedSequenceCount,           "FixedSequenceCount");
       
    50 _LIT(KCmdFixedSequenceName,            "FixedSequenceName");
       
    51 _LIT(KCmdSetConfigL,                   "SetConfigL");
       
    52 _LIT(KCmdSetDTMFLengths,               "SetDTMFLengths");
       
    53 _LIT(KCmdSetGain,                      "SetGain");
       
    54 _LIT(KCmdSetPlayBalanceL,              "SetPlayBalanceL");
       
    55 _LIT(KCmdSetPrioritySettings,          "SetPrioritySettings");
       
    56 _LIT(KCmdSetRecordBalanceL,            "SetRecordBalanceL");
       
    57 _LIT(KCmdSetToneRepeats,               "SetToneRepeats");
       
    58 _LIT(KCmdSetVolume,                    "SetVolume");
       
    59 _LIT(KCmdSetVolumeRamp,                "SetVolumeRamp");
       
    60 _LIT(KCmdInitializeL,                  "InitializeL");
       
    61 _LIT(KCmdPlayDTMFStringL,              "PlayDTMFStringL");
       
    62 _LIT(KCmdPlayData,                     "PlayData");
       
    63 _LIT(KCmdPlayDualToneL,                "PlayDualToneL");
       
    64 _LIT(KCmdPlayInitL,                    "PlayInitL");
       
    65 _LIT(KCmdPlayToneL,                    "PlayToneL");
       
    66 _LIT(KCmdPlayToneSequenceL,            "PlayToneSequenceL");
       
    67 _LIT(KCmdRecordData,                   "RecordData");
       
    68 _LIT(KCmdRecordInitL,                  "RecordInitL");
       
    69 _LIT(KCmdStop,                         "Stop");
       
    70 _LIT(KCmdErrorConceal,                 "ErrorConceal");
       
    71 _LIT(KCmdSetVolumeLoop,                "SetVolumeLoop");
       
    72 /*@}*/
       
    73 
       
    74 /*@{*/
       
    75 //Utility literals
       
    76 _LIT(KCmdUtilityReplaceFile,                  "ReplaceFile");
       
    77 _LIT(KCmdUtilityOpenFile,                     "OpenFile");
       
    78 _LIT(KCmdUtilityCloseFile,                    "CloseFile");
       
    79 _LIT(KCmdUtilityFileStartPosition,            "FileStartPosition");
       
    80 /*@}*/
       
    81 
       
    82 /*@{*/
       
    83 //INI Section name literals
       
    84 _LIT(KGainValue,                       "Gain");
       
    85 _LIT(KVolumeValue,                     "Volume");
       
    86 _LIT(KLeftPercentage,                  "LeftPercentage");
       
    87 _LIT(KRightPercentage,                 "RightPercentage");
       
    88 _LIT(KSequenceNumber,                  "SequenceNumber");
       
    89 _LIT(KRate,                            "Rate");
       
    90 _LIT(KEncoding,                        "Encoding");
       
    91 _LIT(KChannels,                        "Channels");
       
    92 _LIT(KBufferSize,                      "BufferSize");
       
    93 _LIT(KToneOnLength,                    "ToneOnLength");
       
    94 _LIT(KToneOffLength,                   "ToneOffLength");
       
    95 _LIT(KPause,                           "Pause");
       
    96 _LIT(KPauseLength,                     "PauseLength");
       
    97 _LIT(KPriority,                        "Priority");
       
    98 _LIT(KPreference,                      "Preference");
       
    99 _LIT(KPriorityState,                   "PriorityState");
       
   100 _LIT(KRepeatCount,                     "RepeatCount");
       
   101 _LIT(KRepeatTrailingSilence,           "RepeatTrailingSilence");
       
   102 _LIT(KRampDuration,                    "RampDuration");
       
   103 _LIT(KMode,                            "Mode");
       
   104 _LIT(KHwDevice,                        "HwDevice");
       
   105 _LIT(KFourCC,                          "FourCC");
       
   106 _LIT(KFilename,                        "Filename");
       
   107 _LIT(KDTMFString,                      "DTMFString");
       
   108 _LIT(KFrequency,                       "Frequency");
       
   109 _LIT(KFrequencyOne,                    "FrequencyOne");
       
   110 _LIT(KFrequencyTwo,                    "FrequencyTwo");
       
   111 _LIT(KDuration,                        "Duration");
       
   112 _LIT(KLoop,                            "Loop");
       
   113 _LIT(KAllowedError,                    "AllowedError");
       
   114 _LIT(KVolumeList,                      "VolumeList");
       
   115 _LIT(KVolumeLoop,                      "VolumeLoop");
       
   116 /*@}*/
       
   117 
       
   118 /*@{*/
       
   119 //Literals for iEnumChannels
       
   120 _LIT(KEMMFStereo, "EMMFStereo");
       
   121 _LIT(KEMMFMono,   "EMMFMono");
       
   122 /*@}*/
       
   123 
       
   124 const CDataWrapperBase::TEnumEntryTable CT_CMMFDevSoundData::iEnumChannels[] =
       
   125 	{
       
   126 	{KEMMFMono,   EMMFMono},
       
   127 	{KEMMFStereo, EMMFStereo}
       
   128 	};
       
   129 
       
   130 /*@{*/
       
   131 //Literals for iEnumSampleRate
       
   132 _LIT(KEMMFSampleRate8000Hz,  "EMMFSampleRate8000Hz");
       
   133 _LIT(KEMMFSampleRate11025Hz, "EMMFSampleRate11025Hz");
       
   134 _LIT(KEMMFSampleRate16000Hz, "EMMFSampleRate16000Hz");
       
   135 _LIT(KEMMFSampleRate22050Hz, "EMMFSampleRate22050Hz");
       
   136 _LIT(KEMMFSampleRate32000Hz, "EMMFSampleRate32000Hz");
       
   137 _LIT(KEMMFSampleRate44100Hz, "EMMFSampleRate44100Hz");
       
   138 _LIT(KEMMFSampleRate48000Hz, "EMMFSampleRate48000Hz");
       
   139 _LIT(KEMMFSampleRate88200Hz, "EMMFSampleRate88200Hz");
       
   140 _LIT(KEMMFSampleRate96000Hz, "EMMFSampleRate96000Hz");
       
   141 _LIT(KEMMFSampleRate12000Hz, "EMMFSampleRate12000Hz");
       
   142 _LIT(KEMMFSampleRate24000Hz, "EMMFSampleRate24000Hz");
       
   143 _LIT(KEMMFSampleRate64000Hz, "EMMFSampleRate64000Hz");
       
   144 /*@}*/
       
   145 
       
   146 const CDataWrapperBase::TEnumEntryTable CT_CMMFDevSoundData::iEnumSampleRate[] =
       
   147 	{
       
   148 	{KEMMFSampleRate8000Hz,  EMMFSampleRate8000Hz},
       
   149 	{KEMMFSampleRate11025Hz, EMMFSampleRate11025Hz},
       
   150 	{KEMMFSampleRate16000Hz, EMMFSampleRate16000Hz},
       
   151 	{KEMMFSampleRate22050Hz, EMMFSampleRate22050Hz},
       
   152 	{KEMMFSampleRate32000Hz, EMMFSampleRate32000Hz},
       
   153 	{KEMMFSampleRate44100Hz, EMMFSampleRate44100Hz},
       
   154 	{KEMMFSampleRate48000Hz, EMMFSampleRate48000Hz},
       
   155 	{KEMMFSampleRate88200Hz, EMMFSampleRate88200Hz},
       
   156 	{KEMMFSampleRate96000Hz, EMMFSampleRate96000Hz},
       
   157 	{KEMMFSampleRate12000Hz, EMMFSampleRate12000Hz},
       
   158 	{KEMMFSampleRate24000Hz, EMMFSampleRate24000Hz},
       
   159 	{KEMMFSampleRate64000Hz, EMMFSampleRate64000Hz}
       
   160 	};
       
   161 
       
   162 /*@{*/
       
   163 //Literal for iEnumMode
       
   164 _LIT(KEMMFStateIdle,             "EMMFStateIdle");
       
   165 _LIT(KEMMFStatePlaying,          "EMMFStatePlaying");
       
   166 _LIT(KEMMFStateTonePlaying,      "EMMFStateTonePlaying");
       
   167 _LIT(KEMMFStateRecording,        "EMMFStateRecording");
       
   168 _LIT(KEMMFStatePlayingRecording, "EMMFStatePlayingRecording");
       
   169 _LIT(KEMMFStateConverting,       "EMMFStateConverting");
       
   170 /*@}*/
       
   171 
       
   172 const CDataWrapperBase::TEnumEntryTable CT_CMMFDevSoundData::iEnumMode[] =
       
   173 	{
       
   174 	{KEMMFStateIdle,             EMMFStateIdle},
       
   175 	{KEMMFStatePlaying,          EMMFStatePlaying},
       
   176 	{KEMMFStateRecording,        EMMFStateRecording},
       
   177 	{KEMMFStateTonePlaying,      EMMFStateTonePlaying},
       
   178 	{KEMMFStatePlayingRecording, EMMFStatePlayingRecording},
       
   179 	{KEMMFStateConverting,       EMMFStateConverting}
       
   180 	};
       
   181 
       
   182 /*@{*/
       
   183 //Literals for iEnumInitializeLType
       
   184 _LIT(KEInitializeState,          "EInitializeState");
       
   185 _LIT(KEInitializeHwDeviceMode,   "EInitializeHwDeviceMode");
       
   186 _LIT(KEInitializeFourCCMode,     "EInitializeFourCCMode");
       
   187 /*@}*/
       
   188 
       
   189 enum TMMFInitializeMode
       
   190 	{
       
   191 	EInitializeState,
       
   192 	EInitializeHwDeviceMode,
       
   193 	EInitializeFourCCMode
       
   194 	};
       
   195 
       
   196 const CDataWrapperBase::TEnumEntryTable CT_CMMFDevSoundData::iEnumInitializeLType[] =
       
   197 	{
       
   198 	{KEInitializeState,        EInitializeState},
       
   199 	{KEInitializeHwDeviceMode, EInitializeHwDeviceMode},
       
   200 	{KEInitializeFourCCMode,   EInitializeFourCCMode}
       
   201 	};
       
   202 
       
   203 /**
       
   204  * Two phase constructor
       
   205  *
       
   206  * @leave   system wide error
       
   207  */
       
   208 CT_CMMFDevSoundData* CT_CMMFDevSoundData::NewL()
       
   209 	{
       
   210 	CT_CMMFDevSoundData* ret = new (ELeave) CT_CMMFDevSoundData();
       
   211 	CleanupStack::PushL(ret);
       
   212 	ret->ConstructL();
       
   213 	CleanupStack::Pop(ret);
       
   214 	return ret;
       
   215 	}
       
   216 
       
   217 /**
       
   218  * Private constructor. First phase construction
       
   219  */
       
   220 CT_CMMFDevSoundData::CT_CMMFDevSoundData()
       
   221 	:
       
   222 	iDevSound(NULL),
       
   223 	iPrioritySettings(),
       
   224 	iCapabilities(),
       
   225 	iVolumeValue(0),
       
   226 	iGainValue(0),
       
   227 	iLeftPercentage(0),
       
   228 	iRightPercentage(0),
       
   229 	iFs(),
       
   230 	iToneFile(),
       
   231 	iAudiofile(),
       
   232 	iBuffer(NULL),
       
   233 	iLastSample(0),
       
   234 	iPaused(EFalse),
       
   235 	iErrorConceal(EFalse),
       
   236 	iEndFile(EFalse),
       
   237 	iToneSequence(),
       
   238 	iInitializeCompleteError(0),
       
   239 	iToneFinishedError(0),
       
   240 	iBufferToBeFilledError(0),
       
   241 	iPlayErrorError(0),
       
   242 	iBufferToBeEmptiedError(0),
       
   243 	iRecordErrorError(0),
       
   244 	iConvertErrorError(0),
       
   245 	iDeviceMessageError(0),
       
   246 	iUtilityFourCCToHwDeviceUidLError(0),
       
   247     iAsyncErrorIndex_initialize(0),
       
   248     iAsyncErrorIndex_play(0),
       
   249     iAsyncErrorIndex_record(0),
       
   250     iAsyncErrorIndex_tone(0)
       
   251     
       
   252 	{
       
   253 	}
       
   254 
       
   255 /**
       
   256  * Second phase construction
       
   257  * @internalComponent
       
   258  * @return  N/A
       
   259  * @pre     None
       
   260  * @post    None
       
   261  * @leave   system wide error
       
   262  */
       
   263 void CT_CMMFDevSoundData::ConstructL()
       
   264 	{
       
   265 	iFs.Connect();
       
   266 	}
       
   267 
       
   268 /**
       
   269  * Public destructor
       
   270  */
       
   271 CT_CMMFDevSoundData::~CT_CMMFDevSoundData()
       
   272 	{
       
   273 	iFs.Close();
       
   274 	DestroyData();
       
   275 	}
       
   276 
       
   277 /**
       
   278  * Helper Destructor
       
   279  */
       
   280 void CT_CMMFDevSoundData::DestroyData()
       
   281 	{
       
   282 		INFO_PRINTF1(_L("*START* CT_CMMFDevSoundData::DestroyData()"));
       
   283 	if(iDevSound)
       
   284 		{
       
   285 			INFO_PRINTF1(_L("Delete DevSound object."));
       
   286 		delete iDevSound;
       
   287 		iDevSound = NULL;
       
   288 		}
       
   289 			INFO_PRINTF1(_L("*START* CT_CMMFDevSoundData::DestroyData()"));
       
   290 	}
       
   291 
       
   292 /**
       
   293  * Return a pointer to the object that the data wraps
       
   294  *
       
   295  * @return  pointer to the object that the data wraps
       
   296  */
       
   297 TAny* CT_CMMFDevSoundData::GetObject()
       
   298 	{
       
   299 	return iDevSound;
       
   300 	}
       
   301 
       
   302 /**
       
   303  * Process a command read from the Ini file
       
   304  * @param aCommand          - The command to process
       
   305  * @param aSection          - The section get from the *.ini file of the project T_Wlan
       
   306  * @param aAsyncErrorIndex  - Command index dor async calls to returns errors to
       
   307  * @return TBool            - ETrue if the command is process
       
   308  * @leave                   - system wide error
       
   309  */
       
   310 TBool CT_CMMFDevSoundData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   311 	{
       
   312 	TBool ret = ETrue;
       
   313 
       
   314 	if (aCommand == KCmdNewL)
       
   315 		{
       
   316 		DoCmdNewL();
       
   317 		}
       
   318 	else if(aCommand == KCmdNewLLoopL)
       
   319 		{
       
   320 		DoCmdNewLLoopL(aSection);
       
   321 		}
       
   322 	else if (aCommand == KCmdDestructor)
       
   323 		{
       
   324 		DoCmdDestructor();
       
   325 		}
       
   326 	else if (aCommand == KCmdUtilityReplaceFile)
       
   327 		{
       
   328 		DoCmdUtilityReplaceFile(aSection);
       
   329 		}
       
   330 	else if (aCommand == KCmdUtilityOpenFile)
       
   331 		{
       
   332 		DoCmdUtilityOpenFile(aSection);
       
   333 		}
       
   334 	else if (aCommand == KCmdUtilityCloseFile)
       
   335 		{
       
   336 		DoCmdUtilityCloseFile();
       
   337 		}
       
   338 	else if (aCommand == KCmdUtilityFileStartPosition)
       
   339 		{
       
   340 		DoCmdUtilityFileStartPosition();
       
   341 		}
       
   342 	else if (aCommand == KCmdCapabilities)
       
   343 		{
       
   344 		DoCmdCapabilities();
       
   345 		}
       
   346 	else if (aCommand == KCmdConfig)
       
   347 		{
       
   348 		DoCmdConfig();
       
   349 		}
       
   350 	else if (aCommand == KCmdMaxGain)
       
   351 		{
       
   352 		DoCmdMaxGain(aSection);
       
   353 		}
       
   354 	else if (aCommand == KCmdMaxVolume)
       
   355 		{
       
   356 		DoCmdMaxVolume(aSection);
       
   357 		}
       
   358 	else if (aCommand == KCmdGetPlayBalanceL)
       
   359 		{
       
   360 		DoCmdGetPlayBalanceL(aSection);
       
   361 		}
       
   362 	else if (aCommand == KCmdGetRecordBalanceL)
       
   363 		{
       
   364 		DoCmdGetRecordBalanceL(aSection);
       
   365 		}
       
   366 	else if (aCommand == KCmdGetSupportedInputDataTypesL)
       
   367 		{
       
   368 		DoCmdGetSupportedInputDataTypesL();
       
   369 		}
       
   370 	else if (aCommand == KCmdGetSupportedOutputDataTypesL)
       
   371 		{
       
   372 		DoCmdGetSupportedOutputDataTypesL();
       
   373 		}
       
   374 	else if (aCommand == KCmdSamplesPlayed)
       
   375 		{
       
   376 		DoCmdSamplesPlayed();
       
   377 		}
       
   378 	else if (aCommand == KCmdSamplesRecorded)
       
   379 		{
       
   380 		DoCmdSamplesRecorded();
       
   381 		}
       
   382 	else if (aCommand == KCmdVolume)
       
   383 		{
       
   384 		DoCmdVolume(aSection);
       
   385 		}
       
   386 	else if (aCommand == KCmdGain)
       
   387 		{
       
   388 		DoCmdGain(aSection);
       
   389 		}
       
   390 	else if (aCommand == KCmdFixedSequenceCount)
       
   391 		{
       
   392 		DoCmdFixedSequenceCount();
       
   393 		}
       
   394 	else if (aCommand == KCmdFixedSequenceName)
       
   395 		{
       
   396 		DoCmdFixedSequenceName(aSection);
       
   397 		}
       
   398 	else if (aCommand == KCmdSetConfigL)
       
   399 		{
       
   400 		DoCmdSetConfigL(aSection);
       
   401 		}
       
   402 	else if (aCommand == KCmdSetDTMFLengths)
       
   403 		{
       
   404 		DoCmdSetDTMFLengths(aSection);
       
   405 		}
       
   406 	else if (aCommand == KCmdSetGain)
       
   407 		{
       
   408 		DoCmdSetGain(aSection);
       
   409 		}
       
   410 	else if (aCommand == KCmdSetPlayBalanceL)
       
   411 		{
       
   412 		DoCmdSetPlayBalanceL(aSection);
       
   413 		}
       
   414 	else if (aCommand == KCmdSetPrioritySettings)
       
   415 		{
       
   416 		DoCmdSetPrioritySettings(aSection);
       
   417 		}
       
   418 	else if (aCommand == KCmdSetRecordBalanceL)
       
   419 		{
       
   420 		DoCmdSetRecordBalanceL(aSection);
       
   421 		}
       
   422 	else if (aCommand == KCmdSetToneRepeats)
       
   423 		{
       
   424 		DoCmdSetToneRepeats(aSection);
       
   425 		}
       
   426 	else if (aCommand == KCmdSetVolume)
       
   427 		{
       
   428 		DoCmdSetVolume(aSection);
       
   429 		}
       
   430 	else if (aCommand == KCmdSetVolumeLoop)
       
   431 		{
       
   432 		DoCmdSetVolumeLoop(aSection);
       
   433 		}
       
   434 	else if (aCommand == KCmdSetVolumeRamp)
       
   435 		{
       
   436 		DoCmdSetVolumeRamp(aSection);
       
   437 		}
       
   438 	else if (aCommand == KCmdInitializeL)
       
   439 		{
       
   440 		DoCmdInitializeL(aSection, aAsyncErrorIndex);
       
   441 		}
       
   442 	else if (aCommand == KCmdPlayDTMFStringL)
       
   443 		{
       
   444 		DoCmdPlayDTMFStringL(aSection, aAsyncErrorIndex);
       
   445 		}
       
   446 	else if (aCommand == KCmdPlayData)
       
   447 		{
       
   448 		DoCmdPlayData();
       
   449 		}
       
   450 	else if (aCommand == KCmdPlayDualToneL)
       
   451 		{
       
   452 		DoCmdPlayDualToneL(aSection);
       
   453 		}
       
   454 	else if (aCommand == KCmdPlayInitL)
       
   455 		{
       
   456 		DoCmdPlayInitL(aAsyncErrorIndex);
       
   457 		}
       
   458 	else if (aCommand == KCmdPlayToneL)
       
   459 		{
       
   460 		DoCmdPlayToneL(aSection, aAsyncErrorIndex);
       
   461 		}
       
   462 	else if (aCommand == KCmdPlayToneSequenceL)
       
   463 		{
       
   464 		DoCmdPlayToneSequenceL(aSection, aAsyncErrorIndex);
       
   465 		}
       
   466 	else if (aCommand == KCmdRecordData)
       
   467 		{
       
   468 		DoCmdRecordData();
       
   469 		}
       
   470 	else if (aCommand == KCmdRecordInitL)
       
   471 		{
       
   472 		DoCmdRecordInitL(aAsyncErrorIndex);
       
   473 		}
       
   474 	else if (aCommand == KCmdStop)
       
   475 		{
       
   476 		DoCmdStop(aSection);
       
   477 		}
       
   478 	else if(aCommand == KCmdErrorConceal)
       
   479 		{
       
   480 		DoCmdUtilityErrorConceal();
       
   481 		}
       
   482 	else
       
   483 		{
       
   484 		ERR_PRINTF1(_L("Unknown command."));
       
   485 		ret=EFalse;
       
   486 		}
       
   487 	return ret;
       
   488 	}
       
   489 
       
   490 /**
       
   491  * Handles initialization completion event.
       
   492  * CMMFDevSound object calls this function when its InitializeL() function
       
   493  * completes.
       
   494  * @param  aError - Error code. KErrNone if successful. Other values are possible
       
   495  *                  indicating a problem initializing CMMFDevSound object.
       
   496  * @return void
       
   497  */
       
   498 
       
   499 void CT_CMMFDevSoundData::InitializeComplete(TInt aError)
       
   500 	{
       
   501 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::InitializeComplete"));
       
   502 	if(KErrNone != aError)
       
   503 		{
       
   504 		ERR_PRINTF2(_L("InitializeComplete callback failed with error %d"), aError);
       
   505         SetAsyncError(iAsyncErrorIndex_initialize, aError);
       
   506         iAsyncErrorIndex_initialize = 0;
       
   507 		}
       
   508 	DecOutstanding();
       
   509 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::InitializeComplete"));
       
   510 	}
       
   511 
       
   512 /**
       
   513  * It's needed for playing o converting
       
   514  * @param aBuffer - Buffer into which data should be read. The amount of data that is
       
   515  *                  needed is specified in CMMFBuffer::RequestSize().
       
   516  */
       
   517 void CT_CMMFDevSoundData::BufferToBeFilled(CMMFBuffer* aBuffer)
       
   518 	{
       
   519 	if (!aBuffer)
       
   520 		{
       
   521 		ERR_PRINTF1(_L("BufferToBeFilled callback received a NULL CMMFBuffer!"));
       
   522 		SetBlockResult(EFail);
       
   523 		}
       
   524 	else
       
   525 		{
       
   526 		TBool dataOk = ETrue;
       
   527 		iBuffer = aBuffer;
       
   528 		iBuffer->SetLastBuffer(EFalse);
       
   529 		CMMFDataBuffer* buffer = static_cast <CMMFDataBuffer*> (iBuffer);
       
   530 		if (iPaused)
       
   531 			{
       
   532 			iPaused=EFalse;
       
   533 			TInt error = iAudiofile.Read(iLastSample,buffer->Data());
       
   534 			if (error != KErrNone)
       
   535 				{
       
   536 				ERR_PRINTF2(_L("ERROR : iFile.Read() failed with %d"), error);
       
   537 				SetBlockResult(EFail);
       
   538 				dataOk = EFalse;
       
   539 				}
       
   540 			}
       
   541 		else
       
   542 			{
       
   543 			TInt error = iAudiofile.Read(buffer->Data());
       
   544 			if (error != KErrNone)
       
   545 				{
       
   546 				ERR_PRINTF2(_L("ERROR : iFile.Read() failed with %d"), error);
       
   547 				SetBlockResult(EFail);
       
   548 				dataOk =EFalse;
       
   549 				}
       
   550 			}
       
   551 		if(dataOk)
       
   552 			{
       
   553 			if (buffer->Data().Length() != buffer->RequestSize())
       
   554 				{
       
   555 				iBuffer->SetLastBuffer(ETrue);
       
   556 				}
       
   557 			if (iErrorConceal)
       
   558 				{
       
   559 				iErrorConceal=EFalse;
       
   560 				buffer->Data().Zero();
       
   561 				INFO_PRINTF1(_L("buffer->Data().Zero()"));
       
   562 				}
       
   563 			PlayData();
       
   564 			TInt pos=0;
       
   565 			iLastSample=iAudiofile.Seek(ESeekCurrent ,pos);
       
   566 			INFO_PRINTF2(_L("Number of samples played so far: %d"), pos);
       
   567 			iLastSample=pos;
       
   568 			}
       
   569 		}
       
   570 	}
       
   571 
       
   572 /**
       
   573 * Handles play completion or cancel event.
       
   574 *
       
   575 * CMMFDevSound object calls this function when an attempt to play audio sample
       
   576 * has completed, successfully or otherwise.
       
   577 *
       
   578 *   @param  aError - Error code. The status of playback. KErrUnderflow playing of the
       
   579 *                    audio sample is complete. KErrAccessDenied the sound device is in
       
   580 *                    use by another higher priority client.
       
   581 */
       
   582 void CT_CMMFDevSoundData::PlayError(TInt aError)
       
   583 	{
       
   584 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::PlayError"));
       
   585 	if (aError == KErrUnderflow)
       
   586 		{
       
   587 		ERR_PRINTF2(_L("Playback completed normally with error %d"), aError);
       
   588 		//iAudiofile.Close();
       
   589 		}
       
   590 	else
       
   591 		{
       
   592 		ERR_PRINTF2(_L("Playback completed with error %d"), aError);
       
   593 		SetAsyncError(iAsyncErrorIndex_play,aError);
       
   594         iAsyncErrorIndex_play = 0;
       
   595 		}
       
   596 	DecOutstanding();
       
   597 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::PlayError"));
       
   598 	}
       
   599 
       
   600 
       
   601 /**
       
   602  *  Handles tone play completion event.
       
   603  *
       
   604  *
       
   605  *  CMMFDevSound object calls this function when an attempt to play tone has
       
   606  *  completed, successfully or otherwise.
       
   607  *
       
   608  *  The following are the play tone functions; PlayToneL(), PlayDMTFStringL(),
       
   609  *  PlayToneSequenceL(), and PlayFixedSequenceL().
       
   610  *
       
   611  *  @param  aError -  Error code. The status of tone playback. KErrUnderflow playing of
       
   612  *                    the tone is complete. KErrAccessDenied the sound device is in use by
       
   613  *                    another higher priority client. KErrCancel playing of the audio
       
   614  *                    sample is stopped by DevSound client another higher priority client.
       
   615  *
       
   616  */
       
   617 
       
   618 void CT_CMMFDevSoundData::ToneFinished(TInt aError)
       
   619 	{
       
   620 	ERR_PRINTF1(_L("*START*CT_CMMFDevSoundData::ToneFinished"));
       
   621 	
       
   622 	if (aError == KErrUnderflow)
       
   623 		{
       
   624 		ERR_PRINTF2(_L("Tone finished normally with error = %d"), aError);
       
   625 		}
       
   626 	else
       
   627 		{
       
   628 		ERR_PRINTF2(_L("Tone finished with error %d"), aError);
       
   629 		SetAsyncError(iAsyncErrorIndex_tone, aError);
       
   630         iAsyncErrorIndex_tone = 0;
       
   631 		}
       
   632 	DecOutstanding();
       
   633 	iToneFile.Close();
       
   634 	ERR_PRINTF1(_L("*END*CT_CMMFDevSoundData::ToneFinished"));
       
   635 	}
       
   636 
       
   637 /**
       
   638  * Handles CMMFDevSound object's data request event.
       
   639  *
       
   640  * CMMFDevSound object calls this function when the buffer, aBuffer gets filled
       
   641  * while recording or converting. The observer should notify CMMFDevSound
       
   642  * object as quickly as possible after data in the buffer is processed by
       
   643  * calling RecordData(), otherwise the implementation might callback
       
   644  * the function RecordError() on derived class object with error code KErrOverflow.
       
   645  *
       
   646  * @param  aBuffer - Buffer containing processed (recorded or converted) data. The amount
       
   647  *                   of data that is available is specified in CMMFBuffer::RequestSize().
       
   648  */
       
   649 
       
   650 void CT_CMMFDevSoundData::BufferToBeEmptied(CMMFBuffer* aBuffer)
       
   651 	{
       
   652 	if (!aBuffer)
       
   653 		{
       
   654 		INFO_PRINTF1(_L("BufferToBeEmptied callback received a NULL CMMFBuffer"));
       
   655 		SetBlockResult(EFail);
       
   656 		}
       
   657 	else
       
   658 		{
       
   659 		iBuffer = aBuffer;
       
   660 		CMMFDataBuffer* buffer = static_cast <CMMFDataBuffer*> (iBuffer);
       
   661 		TInt error = iAudiofile.Write(buffer->Data());
       
   662 		if(error == KErrNone)
       
   663 			{
       
   664 			if (!aBuffer->LastBuffer())
       
   665 				{
       
   666 				RecordData();
       
   667 				}
       
   668 			else{
       
   669 				Stop();
       
   670 				}
       
   671 			}
       
   672 		else
       
   673 			{
       
   674 			ERR_PRINTF2(_L("iFile.Write() returned the error %d"), error);
       
   675 			SetBlockResult(EFail);
       
   676 			}
       
   677 		}
       
   678 	}
       
   679 
       
   680 /**
       
   681  * Stops the ongoing operation (Play, Record, TonePlay, Convert).
       
   682  * This function should be synchronous and invoke no callbacks through MDevSoundObserver.
       
   683  */
       
   684 void CT_CMMFDevSoundData::Stop()
       
   685 	{
       
   686 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::Stop()"));
       
   687 	iDevSound->Stop();
       
   688     
       
   689 	DecOutstanding();
       
   690 
       
   691 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::Stop()"));
       
   692 	}
       
   693 
       
   694 /**
       
   695  * Handles record completion or cancel event.
       
   696  *
       
   697  * CMMFDevSound object calls this function when an attempt to record audio sample
       
   698  * has completed, successfully or otherwise.
       
   699  *
       
   700  * @param  aError - Error code. The status of recording. KErrOverflow audio devices
       
   701  *                  runs out of internal buffer. KErrAccessDenied the sound device is
       
   702  *                  in use by another higher priority client.
       
   703  *
       
   704  */
       
   705 
       
   706 void CT_CMMFDevSoundData::RecordError(TInt aError)
       
   707 	{
       
   708 	ERR_PRINTF1(_L("*START*CT_CMMFDevSoundData::RecordError"));
       
   709 	ERR_PRINTF2(_L("RecordError callback returned error = %d"), aError);
       
   710 	SetAsyncError(iAsyncErrorIndex_record, aError);
       
   711     iAsyncErrorIndex_record = 0;
       
   712 	//iAudiofile.Close();
       
   713 	ERR_PRINTF1(_L("*END*CT_CMMFDevSoundData::RecordError"));
       
   714 	}
       
   715 
       
   716 
       
   717 /**
       
   718  * Handles conversion completion or cancel event.
       
   719  *
       
   720  * CMMFDevSound object calls this function when an attempt to convert data from
       
   721  * source format to destination format has completed, successfully or otherwise.
       
   722  *
       
   723  * @param  aError - Error code. KErrCancel conversion operation is cancelled. KErrNone
       
   724  *                  conversion is complete. Other values are possible indicating a
       
   725  *                  problem converting data.
       
   726  */
       
   727 
       
   728 void CT_CMMFDevSoundData::ConvertError(TInt aError)
       
   729 	{
       
   730 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::ConvertError"));
       
   731 	ERR_PRINTF1(_L("Invalid Callback call"));
       
   732 	if (aError == KErrNone)
       
   733 		{
       
   734 		INFO_PRINTF1(_L("Data conversion completed successfully."));
       
   735 		}
       
   736 	if (aError == KErrCancel)
       
   737 		{
       
   738 		INFO_PRINTF1(_L("Data conversion operation was cancelled."));
       
   739 		}
       
   740 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::ConvertError"));
       
   741 	}
       
   742 
       
   743 /**
       
   744  * Handles device event.
       
   745  *
       
   746  * CMMFDevSound object calls this function when a message is received from the
       
   747  * audio hardware device.
       
   748  *
       
   749  * @param   aMessageType - Defines the type of message. Used to determine how to
       
   750  *                         interpret the contents of aMsg.
       
   751  * @param   aMsg         - Message that is packed in the Descriptor format.
       
   752  */
       
   753 
       
   754 
       
   755 void CT_CMMFDevSoundData::DeviceMessage(TUid aMessageType, const TDesC8& aMsg)
       
   756 	{
       
   757 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DeviceMessage"));
       
   758 	INFO_PRINTF2(_L("Message type: %d"), aMessageType.iUid);
       
   759 	INFO_PRINTF2(_L("Message type: %S"), &aMsg);
       
   760 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DeviceMessage"));
       
   761 	}
       
   762 
       
   763 
       
   764 /**
       
   765  * Create a new or Replace the existing file
       
   766  *
       
   767  */
       
   768 void CT_CMMFDevSoundData::DoCmdUtilityReplaceFile(const TTEFSectionName& aSection)
       
   769 	{
       
   770 	INFO_PRINTF1(_L("*START* CT_CMMFDevSoundData::DoCmdUtilityReplaceFile()"));
       
   771 	TPtrC fileName;
       
   772 	TBool dataOk = ETrue;
       
   773 	if (!GetStringFromConfig(aSection, KFilename, fileName))
       
   774 		{
       
   775 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFilename);
       
   776 		SetBlockResult(EFail);
       
   777 		dataOk =EFalse;
       
   778 		}
       
   779 	if(dataOk)
       
   780 		{
       
   781 		TInt error = iAudiofile.Replace(iFs, fileName, EFileRead);
       
   782 		if (error != KErrNone)
       
   783 			{
       
   784 			ERR_PRINTF2(_L("Could not open input file. Error = %d"), error);
       
   785 			SetError(error);
       
   786 			}
       
   787 		}
       
   788 
       
   789 	INFO_PRINTF1(_L("*END* CT_CMMFDevSoundData::DoCmdUtilityReplaceFile()"));
       
   790 	}
       
   791 
       
   792 /**
       
   793  * Open a file
       
   794  */
       
   795 void CT_CMMFDevSoundData::DoCmdUtilityOpenFile(const TTEFSectionName& aSection)
       
   796 	{
       
   797 
       
   798 	INFO_PRINTF1(_L("*START* CT_CMMFDevSoundData::DoCmdUtilityOpenFile()"));
       
   799 	TPtrC fileName;
       
   800 	TBool dataOk = ETrue;
       
   801 	if (!GetStringFromConfig(aSection, KFilename, fileName))
       
   802 		{
       
   803 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFilename);
       
   804 		SetBlockResult(EFail);
       
   805 		dataOk =EFalse;
       
   806 		}
       
   807 	if(dataOk)
       
   808 		{
       
   809 		TInt error = iAudiofile.Open(iFs, fileName, EFileRead);
       
   810 		if (error != KErrNone)
       
   811 			{
       
   812 			ERR_PRINTF2(_L("Could not open input file. Error = %d"), error);
       
   813 			iFs.Close();
       
   814 			SetError(error);
       
   815 			}
       
   816 		}
       
   817 	INFO_PRINTF1(_L("*END* CT_CMMFDevSoundData::DoCmdUtilityOpenFile()"));
       
   818 	}
       
   819 
       
   820 /**
       
   821  * Close the opened file
       
   822  */
       
   823 void CT_CMMFDevSoundData::DoCmdUtilityCloseFile()
       
   824 	{
       
   825 	INFO_PRINTF1(_L("*START* CT_CMMFDevSoundData::DoCmdUtilityCloseFile()"));
       
   826 	iAudiofile.Close();
       
   827 	INFO_PRINTF1(_L("*END* CT_CMMFDevSoundData::DoCmdUtilityCloseFile()"));
       
   828 	}
       
   829 
       
   830 /**
       
   831  * Place the the pointer file at the begining
       
   832  *
       
   833  */
       
   834 void CT_CMMFDevSoundData::DoCmdUtilityFileStartPosition()
       
   835 	{
       
   836 	INFO_PRINTF1(_L("*START* CT_CMMFDevSoundData::DoCmdUtilityFileStartPosition()"));
       
   837 	TInt filePosition(0);
       
   838 	TBool dataOk = ETrue;
       
   839 	TInt error = iAudiofile.Seek(ESeekStart, filePosition);
       
   840 	if (error != KErrNone)
       
   841 		{
       
   842 		ERR_PRINTF2(_L("Could not set file to the start position. Error = %d"), error);
       
   843 		SetError(error);
       
   844 		dataOk =EFalse;
       
   845 		}
       
   846 	if(dataOk)
       
   847 		{
       
   848 		INFO_PRINTF2(_L("File Position: %d"), filePosition);
       
   849 		}
       
   850 	INFO_PRINTF1(_L("*END* CT_CMMFDevSoundData::DoCmdUtilityFileStartPosition()"));
       
   851 	}
       
   852 
       
   853 /**
       
   854  * Creates "n" instance of CMMFDevSound
       
   855  * @param aSection - Section to read from the ini file
       
   856  * @return void
       
   857  */
       
   858 void CT_CMMFDevSoundData::DoCmdNewLLoopL(const TTEFSectionName&aSection)
       
   859 	{
       
   860 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdNewLLoopL"));
       
   861 	CMMFDevSound* devSound = NULL;
       
   862 	TBool dataOk = ETrue;
       
   863 	TInt loop;
       
   864 	if (!GetIntFromConfig(aSection, KLoop, loop))
       
   865 		{
       
   866 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KLoop);
       
   867 		SetBlockResult(EFail);
       
   868 		dataOk = EFalse;
       
   869 		}
       
   870 	TInt allowedError;
       
   871 	if ( !GetIntFromConfig(aSection, KAllowedError, allowedError) )
       
   872 		{
       
   873 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KAllowedError);
       
   874 		SetBlockResult(EFail);
       
   875 		dataOk = EFalse;
       
   876 		}
       
   877 	if(dataOk)
       
   878 		{
       
   879 		for(TInt i=0; i<loop; i++)
       
   880 			{
       
   881 			TRAPD(error,devSound = CMMFDevSound::NewL());
       
   882 			if(error == KErrNone)
       
   883 				{
       
   884 				INFO_PRINTF2(_L("Instance %d of DevSound was created"),i);
       
   885 				CleanupStack::PushL(devSound);
       
   886 				iObjectsDevSound.AppendL(devSound);
       
   887 				CleanupStack::Pop(devSound);
       
   888 				}
       
   889 			else if(error == allowedError)
       
   890 				{
       
   891 				INFO_PRINTF2(_L(" Allowing Error: %d"), error);
       
   892 				ERR_PRINTF2(_L(" Could not create CMMFDevSound due to error: %d"), error);
       
   893 				i = loop;
       
   894 				}
       
   895 			else if((error != KErrNone) && (error!=allowedError))
       
   896 				{
       
   897 				ERR_PRINTF2(_L("> Could not create CMMFDevSound: %d"), error);
       
   898 				SetError(error);
       
   899 				}
       
   900 			}
       
   901 		iObjectsDevSound.ResetAndDestroy();
       
   902 		INFO_PRINTF2(_L("%d DevSound instances were deleted"),loop);
       
   903 		}
       
   904 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdNewLLoopL"));
       
   905 	}
       
   906 
       
   907 
       
   908 /**
       
   909  * Create an instance of CMMFDevSound
       
   910  */
       
   911 void CT_CMMFDevSoundData::DoCmdNewL()
       
   912 	{
       
   913 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdNewL"));
       
   914 	DestroyData();
       
   915 	TRAPD(error,iDevSound = CMMFDevSound::NewL());
       
   916 	if(error!= KErrNone)
       
   917 		{
       
   918 		ERR_PRINTF2(_L("> Could not create CMMFDevSound: %d"), error);
       
   919 		SetError(error);
       
   920 		}
       
   921 	else
       
   922 		{
       
   923 		iPaused= EFalse;
       
   924 		iErrorConceal = EFalse;
       
   925 		}
       
   926 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdNewL"));
       
   927 	}
       
   928 /**
       
   929  * Destroy an instance of CMMFDevSound
       
   930  */
       
   931 
       
   932 void CT_CMMFDevSoundData::DoCmdDestructor()
       
   933 	{
       
   934 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdDestroyData"));
       
   935 	DestroyData();
       
   936 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdDestroyData"));
       
   937 	}
       
   938 
       
   939 /**
       
   940  * Show the supported Audio settings ie. encoding, sample rates, mono/stereo operation, buffer
       
   941  * size, etc.
       
   942  * @param none
       
   943  * @return none
       
   944  */
       
   945 void CT_CMMFDevSoundData::DoCmdCapabilities()
       
   946 	{
       
   947 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdCapabilities"));
       
   948 	iCapabilities = iDevSound->Capabilities();
       
   949 	INFO_PRINTF5(_L("Supported Audio settings: buffsize=%d, channels=0x%x, encoding=0x%x and rate=0x%x"),
       
   950 							iCapabilities.iBufferSize,
       
   951 							iCapabilities.iChannels,
       
   952 							iCapabilities.iEncoding,
       
   953 							iCapabilities.iRate);
       
   954 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdCapabilities"));
       
   955 	}
       
   956 
       
   957 
       
   958 /**
       
   959  * Shows the current device configuration.
       
   960  * @params none
       
   961  * @return none
       
   962  */
       
   963 void CT_CMMFDevSoundData::DoCmdConfig()
       
   964 	{
       
   965 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdConfig"));
       
   966 	TMMFCapabilities currentConfiguration = iDevSound->Config();
       
   967 	INFO_PRINTF5(_L("Current device configuration: buffsize=%d, channels=0x%x, encoding=0x%x and rate=0x%x"),
       
   968 			currentConfiguration.iBufferSize,
       
   969 			currentConfiguration.iChannels,
       
   970 			currentConfiguration.iEncoding,
       
   971 			currentConfiguration.iRate);
       
   972 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdConfig"));
       
   973 	}
       
   974 
       
   975 
       
   976 /**
       
   977  * Shows an integer representing the maximum gain the device supports.
       
   978  * This is the maximum value which can be passed to CMMFDevSound::SetGain.
       
   979  * @param aSection - The section to read the params from the ini file
       
   980  * @return none
       
   981  */
       
   982 
       
   983 void CT_CMMFDevSoundData::DoCmdMaxGain(const TTEFSectionName& aSection)
       
   984 	{
       
   985 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdMaxGain"));
       
   986 	TBool dataOk = ETrue;
       
   987 	TInt expectedGainValue;
       
   988 	if (!GetIntFromConfig(aSection, KGainValue, expectedGainValue))
       
   989 		{
       
   990 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KGainValue);
       
   991 		SetBlockResult(EFail);
       
   992 		dataOk = EFalse;
       
   993 		}
       
   994 	if(dataOk)
       
   995 		{
       
   996 		iGainValue = iDevSound->MaxGain();
       
   997 		INFO_PRINTF2(_L("Retrieved maximum gain value: %d"), iGainValue);
       
   998 		if (expectedGainValue != iGainValue)
       
   999 			{
       
  1000 			ERR_PRINTF3(_L("Expected gain value %d is different from retrieved gain value %d"), expectedGainValue, iGainValue);
       
  1001 			SetBlockResult(EFail);
       
  1002 			}
       
  1003 		}
       
  1004 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdMaxGain"));
       
  1005 	}
       
  1006 
       
  1007 /**
       
  1008  * Shows an integer representing the maximum volume device supports.
       
  1009  * This is the maximum value which can be passed to CMMFDevSound::SetVolume.
       
  1010  * @param aSection - Section to read params from the ini file
       
  1011  * @return none
       
  1012  */
       
  1013 
       
  1014 void CT_CMMFDevSoundData::DoCmdMaxVolume(const TTEFSectionName& aSection)
       
  1015 	{
       
  1016 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdMaxVolume"));
       
  1017 	TBool dataOk = ETrue;
       
  1018 	TInt expectedVolumeValue;
       
  1019 	if(!GetIntFromConfig(aSection, KVolumeValue, expectedVolumeValue))
       
  1020 		{
       
  1021 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVolumeValue);
       
  1022 		SetBlockResult(EFail);
       
  1023 		dataOk = EFalse;
       
  1024 		}
       
  1025 	if(dataOk)
       
  1026 		{
       
  1027 		iVolumeValue = iDevSound->MaxVolume();
       
  1028 		INFO_PRINTF2(_L("Retrieved maximum volume value: %d"), iVolumeValue);
       
  1029 		if(expectedVolumeValue != iVolumeValue)
       
  1030 			{
       
  1031 			ERR_PRINTF3(_L("Expected volume value %d is different from retrieved volume value %d"), expectedVolumeValue, iVolumeValue);
       
  1032 			SetBlockResult(EFail);
       
  1033 			}
       
  1034 		}
       
  1035 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdMaxVolume"));
       
  1036 	}
       
  1037 
       
  1038 /**
       
  1039  * Shows the speaker balance set for playing.
       
  1040  * @param aSection - Section to read params from the ini file
       
  1041  * @return none
       
  1042  */
       
  1043 
       
  1044 void CT_CMMFDevSoundData::DoCmdGetPlayBalanceL(const TTEFSectionName& aSection)
       
  1045 	{
       
  1046 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdGetPlayBalanceL"));
       
  1047 	TBool dataOk = ETrue;
       
  1048 	TInt expectedLeftPercentage;
       
  1049 	if (!GetIntFromConfig(aSection, KLeftPercentage, expectedLeftPercentage))
       
  1050 		{
       
  1051 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KLeftPercentage);
       
  1052 		SetBlockResult(EFail);
       
  1053 		dataOk = EFalse;
       
  1054 		}
       
  1055 	TInt expectedRightPercentage;
       
  1056 	if (!GetIntFromConfig(aSection, KRightPercentage, expectedRightPercentage))
       
  1057 		{
       
  1058 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRightPercentage);
       
  1059 		SetBlockResult(EFail);
       
  1060 		dataOk = EFalse;
       
  1061 		}
       
  1062 	if(dataOk)
       
  1063 		{
       
  1064 		TRAPD(error, iDevSound->GetPlayBalanceL(iLeftPercentage, iRightPercentage));
       
  1065 		if (error != KErrNone)
       
  1066 			{
       
  1067 			ERR_PRINTF2(_L("GetPlayBalanceL left with error %d"), error);
       
  1068 			SetError(error);
       
  1069 			}
       
  1070 		else
       
  1071 			{
       
  1072 			INFO_PRINTF3(_L("> Retrieved play balance values are left: %d, right:%d"), iLeftPercentage, iRightPercentage);
       
  1073 			if (expectedLeftPercentage !=iLeftPercentage)
       
  1074 				{
       
  1075 				ERR_PRINTF3(_L("Expected left percentage value %d is different from retrieved value %d"), expectedLeftPercentage, iLeftPercentage);
       
  1076 				SetBlockResult(EFail);
       
  1077 				}
       
  1078 			if (expectedRightPercentage !=iRightPercentage)
       
  1079 				{
       
  1080 				ERR_PRINTF3(_L("Expected right percentage value %d is different from retrieved value %d"), expectedRightPercentage, iRightPercentage);
       
  1081 				SetBlockResult(EFail);
       
  1082 				}
       
  1083 			}
       
  1084 		}
       
  1085 
       
  1086 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdGetPlayBalanceL"));
       
  1087 	}
       
  1088 
       
  1089 
       
  1090 /**
       
  1091  * Shows the microphone gain balance set for recording.
       
  1092  * @param aSection - Section to read params from the ini file
       
  1093  * @return none
       
  1094  */
       
  1095 void CT_CMMFDevSoundData::DoCmdGetRecordBalanceL(const TTEFSectionName& aSection)
       
  1096 	{
       
  1097 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdGetRecordBalanceL"));
       
  1098 	TBool dataOk = ETrue;
       
  1099 	TInt expectedLeftPercentage;
       
  1100 	if(!GetIntFromConfig(aSection, KLeftPercentage, expectedLeftPercentage))
       
  1101 		{
       
  1102 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KLeftPercentage);
       
  1103 		SetBlockResult(EFail);
       
  1104 		dataOk = EFalse;
       
  1105 		}
       
  1106 	TInt expectedRightPercentage;
       
  1107 	if(!GetIntFromConfig(aSection, KRightPercentage, expectedRightPercentage))
       
  1108 		{
       
  1109 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRightPercentage);
       
  1110 		SetBlockResult(EFail);
       
  1111 		dataOk = EFalse;
       
  1112 		}
       
  1113 	if(dataOk)
       
  1114 		{
       
  1115 		TRAPD(error, iDevSound->GetRecordBalanceL(iLeftPercentage, iRightPercentage));
       
  1116 		if (error != KErrNone)
       
  1117 			{
       
  1118 			ERR_PRINTF2(_L("GetRecordBalanceL left with error %d"), error);
       
  1119 			SetError(error);
       
  1120 			}
       
  1121 		else
       
  1122 			{
       
  1123 			INFO_PRINTF3(_L("> Retrieved record balance values are left: %d, right:%d"), iLeftPercentage, iRightPercentage);
       
  1124 			if(expectedLeftPercentage !=iLeftPercentage)
       
  1125 				{
       
  1126 				ERR_PRINTF3(_L("Expected left percentage value %d is different from retrieved value %d"), expectedLeftPercentage, iLeftPercentage);
       
  1127 				SetBlockResult(EFail);
       
  1128 				}
       
  1129 			if(expectedRightPercentage !=iRightPercentage)
       
  1130 				{
       
  1131 				ERR_PRINTF3(_L("Expected right ercentage value %d is different from retrieved value %d"), expectedRightPercentage, iRightPercentage);
       
  1132 				SetBlockResult(EFail);
       
  1133 				}
       
  1134 			}
       
  1135 
       
  1136 		}
       
  1137 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdGetRecordBalanceL"));
       
  1138 	}
       
  1139 
       
  1140 /**
       
  1141  * Shows a list of the supported input datatypes that can be sent to DevSound for playing audio.
       
  1142  * The datatypes returned are those that the DevSound supports given the priority settings passed
       
  1143  * in aPrioritySettings.
       
  1144  * @params none
       
  1145  * @return none
       
  1146  */
       
  1147 void CT_CMMFDevSoundData::DoCmdGetSupportedInputDataTypesL()
       
  1148 	{
       
  1149 	TUid outputUid= {0x0};
       
  1150 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdGetSupportedInputDataTypesL"));
       
  1151 	RArray< TFourCC > supportedDataTypes;
       
  1152 	TRAPD(error, iDevSound->GetSupportedInputDataTypesL(supportedDataTypes, iPrioritySettings));
       
  1153 	if (error != KErrNone)
       
  1154 		{
       
  1155 		ERR_PRINTF2(_L("GetSupportedInputDataTypesL left with error %d"), error);
       
  1156 		SetError(error);
       
  1157 		}
       
  1158 	else
       
  1159 		{
       
  1160 		INFO_PRINTF1(_L("List of the supported input datatypes that can be sent to DevSound for playing audio."));
       
  1161 		for (TInt i=0; i<supportedDataTypes.Count(); i++)
       
  1162 			{
       
  1163 			TFourCC fourCC = supportedDataTypes[i];
       
  1164 			TBuf<4> name;
       
  1165 			for(TInt j=0; j<= KFourCCMaxBitDisplacement; j+=K8Bits)
       
  1166 				{
       
  1167 				name.Append((TUint8)(fourCC.FourCC() >> j));
       
  1168 				}
       
  1169 			INFO_PRINTF3(_L("Supported Input Data types: 0x%x  %S "), fourCC.FourCC(), &name);
       
  1170 			UtilityFourCCToHwDeviceUidL(name,EDecoder, outputUid);
       
  1171 			if(outputUid.iUid != 0)
       
  1172 				{
       
  1173 				INFO_PRINTF3(_L("\nHwDevice Uid=0x%08x for %S"),outputUid.iUid,&name);
       
  1174 				}
       
  1175 			else
       
  1176 				{
       
  1177 				INFO_PRINTF1(_L("Not Found"));
       
  1178 				}
       
  1179 			}
       
  1180 		supportedDataTypes.Reset();
       
  1181 		}
       
  1182 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdGetSupportedInputDataTypesL"));
       
  1183 	}
       
  1184 
       
  1185 /**
       
  1186  * Shows a list of the supported output dataypes that can be received from DevSound for
       
  1187  * recording audio.  The datatypes returned are those that the DevSound supports given the priority
       
  1188  * settings passed in aPrioritySettings.
       
  1189  * @param none
       
  1190  * @return none
       
  1191  */
       
  1192 void CT_CMMFDevSoundData::DoCmdGetSupportedOutputDataTypesL()
       
  1193 	{
       
  1194 	TUid outputUid= {0x0};
       
  1195 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdGetSupportedOutputDataTypesL"));
       
  1196 	RArray< TFourCC > supportedDataTypes;
       
  1197 	TRAPD(error, iDevSound->GetSupportedOutputDataTypesL(supportedDataTypes, iPrioritySettings));
       
  1198 	if (error != KErrNone)
       
  1199 		{
       
  1200 		ERR_PRINTF2(_L("GetSupportedOutputDataTypesL left with error %d"), error);
       
  1201 		SetError(error);
       
  1202 		}
       
  1203 	else
       
  1204 		{
       
  1205 		INFO_PRINTF1(_L("List of the supported output dataypes that can be received from DevSound for recording audio."));
       
  1206 		for (TInt i=0; i<supportedDataTypes.Count(); i++)
       
  1207 			{
       
  1208 			TFourCC fourCC = supportedDataTypes[i];
       
  1209 			TBuf<4> name;
       
  1210 			for(TInt j=0; j<=KFourCCMaxBitDisplacement; j+=K8Bits)
       
  1211 				{
       
  1212 				name.Append((TUint8)(fourCC.FourCC() >> j));
       
  1213 				}
       
  1214 			INFO_PRINTF3(_L("Supported Output Data types: 0x%x  %S "), fourCC.FourCC(), &name);
       
  1215 			UtilityFourCCToHwDeviceUidL(name, EEncoder, outputUid);
       
  1216 			if(outputUid.iUid != 0)
       
  1217 				{
       
  1218 				INFO_PRINTF3(_L("\nHwDevice Uid=0x%08x for %S"),outputUid.iUid,&name);
       
  1219 				}
       
  1220 			else
       
  1221 				{
       
  1222 				INFO_PRINTF1(_L("Not Found"));
       
  1223 				}
       
  1224 			}
       
  1225 		supportedDataTypes.Reset();
       
  1226 		}
       
  1227 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdGetSupportedOutputDataTypesL"));
       
  1228 	}
       
  1229 
       
  1230 /**
       
  1231  * Shows the number of samples played
       
  1232  * @param none
       
  1233  * @return none
       
  1234  */
       
  1235 void CT_CMMFDevSoundData::DoCmdSamplesPlayed()
       
  1236 	{
       
  1237 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSamplesPlayed"));
       
  1238 	INFO_PRINTF2(_L("Number of samples played so far: %d"),iDevSound->SamplesPlayed());
       
  1239 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSamplesPlayed"));
       
  1240 	}
       
  1241 
       
  1242 /**
       
  1243  * Shows the number of samples recorded
       
  1244  * @param none
       
  1245  * @return none
       
  1246  */
       
  1247 void CT_CMMFDevSoundData::DoCmdSamplesRecorded()
       
  1248 	{
       
  1249 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSamplesRecorded"));
       
  1250 	INFO_PRINTF2(_L("Number of samples recorded so far: %d"), iDevSound->SamplesRecorded());
       
  1251 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSamplesRecorded"));
       
  1252 	}
       
  1253 
       
  1254 /**
       
  1255  * Shows an integer representing the current volume.
       
  1256  * @param aSection - Section to read param from the ini file
       
  1257  * @return none
       
  1258  */
       
  1259 void CT_CMMFDevSoundData::DoCmdVolume(const TTEFSectionName& aSection)
       
  1260 	{
       
  1261 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdVolume"));
       
  1262 	TBool dataOk = ETrue;
       
  1263 	TInt expectedVolumeValue;
       
  1264 	if(!GetIntFromConfig(aSection, KVolumeValue, expectedVolumeValue))
       
  1265 		{
       
  1266 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVolumeValue);
       
  1267 		SetBlockResult(EFail);
       
  1268 		dataOk = EFalse;
       
  1269 		}
       
  1270 	if(dataOk)
       
  1271 		{
       
  1272 		iVolumeValue = iDevSound->Volume();
       
  1273 		INFO_PRINTF2(_L("Retrieved volume value: %d"), iVolumeValue);
       
  1274 		if(expectedVolumeValue != iVolumeValue)
       
  1275 			{
       
  1276 			ERR_PRINTF3(_L("Expected volume value %d is different from retrieved volume value %d"), expectedVolumeValue, iVolumeValue);
       
  1277 			SetBlockResult(EFail);
       
  1278 			}
       
  1279 		}
       
  1280 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdVolume"));
       
  1281 	}
       
  1282 
       
  1283 /**
       
  1284  * Shows an integer representing the current gain.
       
  1285  * @param aSection - Section to read param from the ini file
       
  1286  * @return none
       
  1287  */
       
  1288 void CT_CMMFDevSoundData::DoCmdGain(const TTEFSectionName& aSection)
       
  1289 	{
       
  1290 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdGain"));
       
  1291 	TBool dataOk = ETrue;
       
  1292 	TInt expectedGainValue;
       
  1293 	if(!GetIntFromConfig(aSection, KGainValue, expectedGainValue))
       
  1294 		{
       
  1295 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KGainValue);
       
  1296 		SetBlockResult(EFail);
       
  1297 		dataOk = EFalse;
       
  1298 		}
       
  1299 	if(dataOk)
       
  1300 		{
       
  1301 		iGainValue = iDevSound->Gain();
       
  1302 		INFO_PRINTF2(_L("Retrieved gain value: %d"), iGainValue);
       
  1303 		if(expectedGainValue != iGainValue)
       
  1304 			{
       
  1305 			ERR_PRINTF3(_L("Expected gain value %d is different from retrieved gain value %d"), expectedGainValue, iGainValue);
       
  1306 			SetBlockResult(EFail);
       
  1307 			}
       
  1308 		}
       
  1309 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdGain"));
       
  1310 	}
       
  1311 
       
  1312 /**
       
  1313  * Shows the number of available pre-defined tone sequences
       
  1314  * @param none
       
  1315  * @return none
       
  1316  */
       
  1317 void CT_CMMFDevSoundData::DoCmdFixedSequenceCount()
       
  1318 	{
       
  1319 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdFixedSequenceCount"));
       
  1320 	INFO_PRINTF2(_L("Number of available pre-defined tone sequences: %d"), iDevSound->FixedSequenceCount());
       
  1321 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdFixedSequenceCount"));
       
  1322 	}
       
  1323 
       
  1324 /**
       
  1325  * Shows the name assigned to a specific pre-defined tone sequence.
       
  1326  * This is the number of the fixed sequence supported by DevSound by default.
       
  1327  * @param aSection -  Section to read params from the ini file
       
  1328  * @return none
       
  1329  */
       
  1330 void CT_CMMFDevSoundData::DoCmdFixedSequenceName(const TTEFSectionName& aSection)
       
  1331 	{
       
  1332 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdFixedSequenceName"));
       
  1333 	TBool dataOk =ETrue;
       
  1334 	TInt sequenceNumber;
       
  1335 	if(!GetIntFromConfig(aSection, KSequenceNumber, sequenceNumber))
       
  1336 		{
       
  1337 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSequenceNumber);
       
  1338 		SetBlockResult(EFail);
       
  1339 		dataOk =EFalse;
       
  1340 		}
       
  1341 	if(dataOk)
       
  1342 		{
       
  1343 		INFO_PRINTF2(_L("Name assigned to a specific pre-defined tone sequence returned: %S"),
       
  1344 					&iDevSound->FixedSequenceName(sequenceNumber));
       
  1345 		}
       
  1346 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdFixedSequenceName"));
       
  1347 	}
       
  1348 
       
  1349 
       
  1350 /**
       
  1351  * Configure CMMFDevSound object with the settings in aConfig.
       
  1352  * Use this to set sampling rate, encoding and mono/stereo.
       
  1353  * @param aSection - Section to read params from the ini file
       
  1354  * @return none
       
  1355  */
       
  1356 void CT_CMMFDevSoundData::DoCmdSetConfigL(const TTEFSectionName& aSection)
       
  1357 	{
       
  1358 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetConfigL"));
       
  1359 
       
  1360 	TInt rate;
       
  1361 	INFO_PRINTF1(_L("To use default values run Capabilities before SetConfigL"));
       
  1362 	if (!GetEnumFromConfig(aSection, KRate, iEnumSampleRate, rate))
       
  1363 		{
       
  1364 		INFO_PRINTF2(_L("Rate value was not overwritten, using default value %d."), iCapabilities.iRate);
       
  1365 		}
       
  1366 	else
       
  1367 		{
       
  1368 		iCapabilities.iRate = rate;
       
  1369 		}
       
  1370 
       
  1371 	TInt encoding;
       
  1372 	if (!GetIntFromConfig(aSection, KEncoding, encoding))
       
  1373 		{
       
  1374 		INFO_PRINTF2(_L("Encoding value was not overwritten, using default value %d."), iCapabilities.iEncoding);
       
  1375 		}
       
  1376 	else
       
  1377 		{
       
  1378 		iCapabilities.iEncoding = encoding;
       
  1379 		}
       
  1380 
       
  1381 	TInt channels;
       
  1382 	if (!GetEnumFromConfig(aSection, KChannels, iEnumChannels, channels))
       
  1383 		{
       
  1384 		INFO_PRINTF2(_L("Channels value was not overwritten, using default value %d ."), iCapabilities.iChannels);
       
  1385 		}
       
  1386 	else
       
  1387 		{
       
  1388 		iCapabilities.iChannels = channels;
       
  1389 		}
       
  1390 
       
  1391 	TInt bufferSize;
       
  1392 	if (!GetIntFromConfig(aSection, KBufferSize, bufferSize))
       
  1393 		{
       
  1394 		INFO_PRINTF2(_L("BufferSize value was not overwritten, using default value %d"), iCapabilities.iBufferSize);
       
  1395 		}
       
  1396 	else
       
  1397 		{
       
  1398 		iCapabilities.iBufferSize = bufferSize;
       
  1399 		}
       
  1400 	TRAPD(error,iDevSound->SetConfigL(iCapabilities))
       
  1401 	if(error != KErrNone)
       
  1402 		{
       
  1403 		ERR_PRINTF2(_L("SetConfigL left with error %d"), error);
       
  1404 		SetError(error);
       
  1405 		}
       
  1406 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetConfigL"));
       
  1407 	}
       
  1408 
       
  1409 
       
  1410 /**
       
  1411  * Defines the duration of tone on, tone off and tone pause to be used during the
       
  1412  * DTMF tone playback operation.
       
  1413  * Supported only during tone playing.
       
  1414  * @param aSection - Section to read param from the ini file
       
  1415  * @return none
       
  1416  */
       
  1417 void CT_CMMFDevSoundData::DoCmdSetDTMFLengths(const TTEFSectionName& aSection)
       
  1418 	{
       
  1419 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetDTMFLengths"));
       
  1420 	TInt time;
       
  1421 	TBool dataOk = ETrue;
       
  1422 	if (!GetIntFromConfig(aSection, KToneOnLength, time))
       
  1423 		{
       
  1424 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KToneOnLength);
       
  1425 		SetBlockResult(EFail);
       
  1426 		dataOk = EFalse;
       
  1427 		}
       
  1428 	TTimeIntervalMicroSeconds32 toneOnLength(time);
       
  1429 
       
  1430 	if (!GetIntFromConfig(aSection, KToneOffLength, time))
       
  1431 		{
       
  1432 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KToneOffLength);
       
  1433 		SetBlockResult(EFail);
       
  1434 		dataOk = EFalse;
       
  1435 		}
       
  1436 	TTimeIntervalMicroSeconds32 toneOffLength(time);
       
  1437 
       
  1438 	if (!GetIntFromConfig(aSection, KPauseLength, time))
       
  1439 		{
       
  1440 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KPauseLength);
       
  1441 		SetBlockResult(EFail);
       
  1442 		dataOk = EFalse;
       
  1443 		}
       
  1444 	TTimeIntervalMicroSeconds32 pauseLength(time);
       
  1445 	if(dataOk)
       
  1446 		{
       
  1447 		iDevSound->SetDTMFLengths(toneOnLength, toneOffLength, pauseLength);
       
  1448 		}
       
  1449 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetDTMFLengths"));
       
  1450 	}
       
  1451 
       
  1452 
       
  1453 /**
       
  1454  * Changes the current recording gain to a specified value.
       
  1455  * The gain can be changed before or during recording and is effective
       
  1456  * immediately.
       
  1457  * @params aSection - Section to read param from the ini file
       
  1458  */
       
  1459 void CT_CMMFDevSoundData::DoCmdSetGain(const TTEFSectionName& aSection)
       
  1460 	{
       
  1461 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetGain"));
       
  1462 	TInt gainValue = iGainValue;
       
  1463 	if(!GetIntFromConfig(aSection, KGainValue, gainValue))
       
  1464 		{
       
  1465 		INFO_PRINTF1(_L("The Gain value was not found in the ini file, using default value"));
       
  1466 		}
       
  1467 	INFO_PRINTF2(_L("Setting gain value to %d"), gainValue);
       
  1468 	iDevSound->SetGain(gainValue);
       
  1469 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetGain"));
       
  1470 	}
       
  1471 
       
  1472 /**
       
  1473  * Sets the speaker balance for playing.
       
  1474  * The speaker balance can be changed before or during playback and is
       
  1475  * effective immediately.
       
  1476  * @param aSection - The section to read params from the ini file
       
  1477  * @return none
       
  1478  */
       
  1479 void CT_CMMFDevSoundData::DoCmdSetPlayBalanceL(const TTEFSectionName& aSection)
       
  1480 	{
       
  1481 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetPlayBalanceL"));
       
  1482 	TInt leftPercentage = iLeftPercentage;
       
  1483 	if(!GetIntFromConfig(aSection, KLeftPercentage, leftPercentage))
       
  1484 		{
       
  1485 		INFO_PRINTF1(_L("The Left percentage was not found in the ini file, using default value"));
       
  1486 		}
       
  1487 	TInt rightPercentage = iRightPercentage;
       
  1488 	if(!GetIntFromConfig(aSection, KRightPercentage, rightPercentage))
       
  1489 		{
       
  1490 		INFO_PRINTF1(_L("The Right percentage was not found in the ini file, using default value"));
       
  1491 		}
       
  1492 	INFO_PRINTF3(_L("Setting play balance to left: %d, right: %d values"), leftPercentage, rightPercentage);
       
  1493 	TRAPD(error, iDevSound->SetPlayBalanceL(leftPercentage, rightPercentage));
       
  1494 	if(error != KErrNone)
       
  1495 		{
       
  1496 		ERR_PRINTF2(_L("SetPlayBalanceL left with error %d"), error);
       
  1497 		SetError(error);
       
  1498 		}
       
  1499 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetPlayBalanceL"));
       
  1500 	}
       
  1501 
       
  1502 /**
       
  1503  * Defines the priority settings that should be used for this instance.
       
  1504  * @param aSection - Section to read params from the ini file
       
  1505  * @return none
       
  1506  */
       
  1507 void CT_CMMFDevSoundData::DoCmdSetPrioritySettings(const TTEFSectionName& aSection)
       
  1508 	{
       
  1509 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetPrioritySettings"));
       
  1510 	TBool dataOk = ETrue;
       
  1511 	if(!GetIntFromConfig(aSection, KPriority, iPrioritySettings.iPriority))
       
  1512 		{
       
  1513 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KPriority);
       
  1514 		SetBlockResult(EFail);
       
  1515 		dataOk = EFalse;
       
  1516 		}
       
  1517 	TInt preference;
       
  1518 	if (!GetHexFromConfig(aSection, KPreference, preference))
       
  1519 		{
       
  1520 		ERR_PRINTF2(_L("%S parameter was not found in INI file"), &KPreference);
       
  1521 		SetBlockResult(EFail);
       
  1522 		dataOk = EFalse;
       
  1523 		}
       
  1524 	iPrioritySettings.iPref = (TMdaPriorityPreference)preference;
       
  1525 	TInt state;
       
  1526 	if (!GetEnumFromConfig(aSection, KPriorityState, iEnumMode, state))
       
  1527 		{
       
  1528 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KPriorityState);
       
  1529 		SetBlockResult(EFail);
       
  1530 		dataOk = EFalse;
       
  1531 		}
       
  1532 	iPrioritySettings.iState = (TMMFState)state;
       
  1533 	if(dataOk)
       
  1534 		{
       
  1535 		iDevSound->SetPrioritySettings(iPrioritySettings);
       
  1536 		}
       
  1537 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetPrioritySettings"));
       
  1538 	}
       
  1539 
       
  1540 /**
       
  1541  * Sets the microphone gain balance for recording.
       
  1542  * The microphone gain balance can be changed before or during recording and
       
  1543  * is effective immediately.
       
  1544  * @param aSection - Section to read params from the ini file
       
  1545  * @return none
       
  1546  */
       
  1547 void CT_CMMFDevSoundData::DoCmdSetRecordBalanceL(const TTEFSectionName& aSection)
       
  1548 	{
       
  1549 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetRecordBalanceL"));
       
  1550 	TInt leftPercentage = iLeftPercentage;
       
  1551 	if (!GetIntFromConfig(aSection, KLeftPercentage, leftPercentage))
       
  1552 		{
       
  1553 		INFO_PRINTF1(_L("The Left value was not found in the ini file, using default value"));
       
  1554 		}
       
  1555 	TInt rightPercentage = iRightPercentage;
       
  1556 	if (!GetIntFromConfig(aSection, KRightPercentage, rightPercentage))
       
  1557 		{
       
  1558 		INFO_PRINTF1(_L("The Right value was not found in the ini file, using default value"));
       
  1559 		}
       
  1560 	INFO_PRINTF3(_L("Setting record balance to left: %d, right: %d values"), leftPercentage, rightPercentage);
       
  1561 	TRAPD(error, iDevSound->SetRecordBalanceL(leftPercentage, rightPercentage));
       
  1562 	if (KErrNone != error)
       
  1563 		{
       
  1564 		ERR_PRINTF2(_L("SetRecordBalanceL left with error %d"), error);
       
  1565 		SetError(error);
       
  1566 		}
       
  1567 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetRecordBalanceL"));
       
  1568 	}
       
  1569 
       
  1570 /**
       
  1571  * Defines the number of times the audio is to be repeated during the tone
       
  1572  * playback operation.
       
  1573  * A period of silence can follow each playing of a tone. The tone playing can
       
  1574  * be repeated indefinitely.
       
  1575  * @param aSection - Section to read params from the ini file
       
  1576  * @return none
       
  1577  */
       
  1578 void CT_CMMFDevSoundData::DoCmdSetToneRepeats(const TTEFSectionName& aSection)
       
  1579 	{
       
  1580 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetToneRepeats"));
       
  1581 	TInt repeatCount;
       
  1582 	TBool dataOk = ETrue;
       
  1583 	if (!GetIntFromConfig(aSection, KRepeatCount, repeatCount))
       
  1584 		{
       
  1585 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepeatCount);
       
  1586 		SetBlockResult(EFail);
       
  1587 		dataOk = EFalse;
       
  1588 		}
       
  1589 
       
  1590 	TInt tempValue;
       
  1591 	if (!GetIntFromConfig(aSection, KRepeatTrailingSilence, tempValue))
       
  1592 		{
       
  1593 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRepeatTrailingSilence);
       
  1594 		SetBlockResult(EFail);
       
  1595 		dataOk = EFalse;
       
  1596 		}
       
  1597 	TTimeIntervalMicroSeconds repeatTrailingSilence(tempValue);
       
  1598 
       
  1599 	if(dataOk)
       
  1600 		{
       
  1601 		iDevSound->SetToneRepeats(repeatCount, repeatTrailingSilence);
       
  1602 		}
       
  1603 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetToneRepeats"));
       
  1604 	}
       
  1605 
       
  1606 /**
       
  1607  * Defines the period over which the volume level is to rise smoothly from
       
  1608  * nothing to the normal volume level.
       
  1609  * The function is only available while the tone is playing.
       
  1610  * @param aSection - Section to read params from the ini file
       
  1611  * @return none
       
  1612  */
       
  1613 void CT_CMMFDevSoundData::DoCmdSetVolume(const TTEFSectionName& aSection)
       
  1614 	{
       
  1615 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetVolume"));
       
  1616 	TInt volume = iVolumeValue;
       
  1617 	if(!GetIntFromConfig(aSection, KVolumeValue, volume))
       
  1618 		{
       
  1619 		INFO_PRINTF1(_L("The Volume value was not found in the ini file, using default value"));
       
  1620 		}
       
  1621 	INFO_PRINTF2(_L("Setting volume value to %d"), volume);
       
  1622 	iDevSound->SetVolume(volume);
       
  1623 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetVolume"));
       
  1624 	}
       
  1625 
       
  1626 /**
       
  1627  * Defines the loop over which the volume level is to rise smoothly from
       
  1628  * nothing to the normal volume level.
       
  1629  * @param aSection - Section to read params from the ini file
       
  1630  * @return none
       
  1631  */
       
  1632 void CT_CMMFDevSoundData::DoCmdSetVolumeLoop(const TTEFSectionName& aSection)
       
  1633 	{
       
  1634 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetVolumeLoop"));
       
  1635 	TInt volLoop;
       
  1636 	TBool dataOk = ETrue;
       
  1637 	if (!GetIntFromConfig(aSection, KVolumeLoop, volLoop))
       
  1638 		{
       
  1639 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVolumeLoop);
       
  1640 		SetBlockResult(EFail);
       
  1641 		dataOk = EFalse;
       
  1642 		}
       
  1643 	if(dataOk)
       
  1644 		{
       
  1645 		TPtrC parVolume;
       
  1646 		TInt volumeValue;
       
  1647 		RPointerArray<HBufC> volumeList;
       
  1648 		for (TInt i=0; i<volLoop; i++)
       
  1649 			{
       
  1650 			if (!GetArrayRectFromConfig(aSection, KVolumeList, volumeList))
       
  1651 				{
       
  1652 				ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVolumeList);
       
  1653 				volumeList.ResetAndDestroy();
       
  1654 				SetBlockResult(EFail);
       
  1655 				dataOk = EFalse;
       
  1656 				}
       
  1657 			if(dataOk)
       
  1658 				{
       
  1659 				for (TInt j=0; j<volumeList.Count(); j++)
       
  1660 					{
       
  1661 					parVolume.Set(*volumeList[j]);
       
  1662 					TLex lex(parVolume);
       
  1663 					TInt error = lex.Val(volumeValue);
       
  1664 					if (error != KErrNone)
       
  1665 						{
       
  1666 						ERR_PRINTF2(_L("Obtaining volume value failed with error %d"), error);
       
  1667 						SetError(error);
       
  1668 						volumeList.ResetAndDestroy();
       
  1669 						}
       
  1670 					else
       
  1671 						{
       
  1672 						INFO_PRINTF3(_L("Setting volume number %d in the iteration number %d"), j, i);
       
  1673 						iDevSound->SetVolume(volumeValue);
       
  1674 						}
       
  1675 					}
       
  1676 				}
       
  1677 			}
       
  1678 		volumeList.ResetAndDestroy();
       
  1679 		}
       
  1680 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetVolumeLoop"));
       
  1681 	}
       
  1682 
       
  1683 /**
       
  1684  * Defines the period over which the volume level is to rise smoothly from
       
  1685  * nothing to the normal volume level.
       
  1686  * The function is only available while the tone is playing.
       
  1687  * @param aSection - Section to read param from the ini file
       
  1688  * @return none
       
  1689  */
       
  1690 void CT_CMMFDevSoundData::DoCmdSetVolumeRamp(const TTEFSectionName& aSection)
       
  1691 	{
       
  1692 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdSetVolumeRamp"));
       
  1693 	TInt tempValue;
       
  1694 	TBool dataOk = ETrue;
       
  1695 	if (!GetIntFromConfig(aSection, KRampDuration, tempValue))
       
  1696 		{
       
  1697 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KRampDuration);
       
  1698 		SetBlockResult(EFail);
       
  1699 		dataOk = EFalse;
       
  1700 		}
       
  1701 	TTimeIntervalMicroSeconds rampDuration(tempValue);
       
  1702 
       
  1703 	if(dataOk)
       
  1704 		{
       
  1705 		iDevSound->SetVolumeRamp(rampDuration);
       
  1706 		}
       
  1707 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdSetVolumeRamp"));
       
  1708 	}
       
  1709 
       
  1710 /**
       
  1711  * Initializes DevSound object for the mode aMode for processing audio data
       
  1712  * with hardware device aHWDev and supporting FourCC.
       
  1713  * Too Initializes CMMFDevSound object to play and record PCM16 raw audio data
       
  1714  * with sampling rate of 8 KHz.
       
  1715  * @param aSection - Section to read params from the ini file
       
  1716  */
       
  1717 void CT_CMMFDevSoundData::DoCmdInitializeL(const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
  1718 	{
       
  1719 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdInitializeL"));
       
  1720 	TBool dataOk = ETrue;
       
  1721 	TInt mode;
       
  1722 	if (!GetEnumFromConfig(aSection, KMode, iEnumMode, mode))
       
  1723 		{
       
  1724 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KMode);
       
  1725 		SetBlockResult(EFail);
       
  1726 		dataOk = EFalse;
       
  1727 		}
       
  1728 	else
       
  1729 		{
       
  1730 		TInt hwDeviceInt;
       
  1731 		if (!GetHexFromConfig(aSection, KHwDevice, hwDeviceInt))
       
  1732 			{
       
  1733 			INFO_PRINTF2(_L("%S parameter was not found in INI file"), &KHwDevice);
       
  1734 			TPtrC fourCCIniString;
       
  1735 			if (!GetStringFromConfig(aSection, KFourCC, fourCCIniString))
       
  1736 				{
       
  1737 				INFO_PRINTF2(_L("%S parameter was not found in INI file"), &KFourCC);
       
  1738 				if (dataOk)
       
  1739 					{
       
  1740 					INFO_PRINTF1(_L("Initializing DevSound with overload: void InitializeL(MDevSoundObserver &aDevSoundObserver, TMMFState aMode)"));
       
  1741 					TRAPD(error, iDevSound->InitializeL(*this, (TMMFState)mode));
       
  1742 					if(KErrNone != error)
       
  1743 						{
       
  1744 						ERR_PRINTF2(_L("InitializeL(aMDevSoundObserver, mode) left with error %d"), error);
       
  1745 						SetError(error);
       
  1746 						}
       
  1747 					}
       
  1748 				}
       
  1749 			else
       
  1750 				{
       
  1751 				if (fourCCIniString.Length() > KTFourCC)
       
  1752 					{
       
  1753 					ERR_PRINTF2(_L("FourCC obtained from INI file exceeded the valid length in %d"), fourCCIniString.Length());
       
  1754 					SetBlockResult(EFail);
       
  1755 					dataOk = EFalse;
       
  1756 					}
       
  1757 				if (dataOk)
       
  1758 					{
       
  1759 					TBuf<256> fourCCString;
       
  1760 					fourCCString.Copy(fourCCIniString);
       
  1761 					while (fourCCString.Length() < KTFourCC)
       
  1762 						{
       
  1763 						fourCCString.Insert(0, _L(" "));
       
  1764 						}
       
  1765 					TFourCC fourCC;
       
  1766 					fourCC = TFourCC(fourCCString[3] << 24 | fourCCString[2] << 16 | fourCCString[1] << 8 | fourCCString[0]);
       
  1767 					INFO_PRINTF1(_L("Initializing DevSound with overload: void InitializeL(MDevSoundObserver &aDevSoundObserver, TFourCC aDesiredFourCC, TMMFState aMode)"));
       
  1768 					TRAPD(error, iDevSound->InitializeL(*this, fourCC, (TMMFState)mode));
       
  1769 					if(KErrNone!=error)
       
  1770 						{
       
  1771 						ERR_PRINTF2(_L("InitializeL(aMDevSoundObserver, fourCC, mode) left with error %d"), error);
       
  1772 						ERR_PRINTF2(_L(" %S Not supported in this device"), &fourCCString);
       
  1773 						SetError(error);
       
  1774 						}
       
  1775 					}
       
  1776 				}
       
  1777 			}
       
  1778 		else
       
  1779 			{
       
  1780 			if (dataOk)
       
  1781 				{
       
  1782 				TUid hwDevice;
       
  1783 				hwDevice.iUid = hwDeviceInt;
       
  1784 				INFO_PRINTF1(_L("Initializing DevSound with overload: void InitializeL(MDevSoundObserver &aDevSoundObserver, TUid aHWDev, TMMFState aMode)"));
       
  1785 				TRAPD(error, iDevSound->InitializeL(*this, hwDevice, (TMMFState)mode));
       
  1786 				if(KErrNone != error)
       
  1787 					{
       
  1788 					ERR_PRINTF2(_L("InitializeL(aMDevSoundObserver, hwDevice, mode) left with error %d"), error);
       
  1789 					SetError(error);
       
  1790 					}
       
  1791 				}
       
  1792 			}
       
  1793 		}
       
  1794 
       
  1795 	if (dataOk)
       
  1796 		{
       
  1797 		IncOutstanding();
       
  1798         iAsyncErrorIndex_initialize = aAsyncErrorIndex;
       
  1799 		}
       
  1800 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdInitializeL"));
       
  1801 	}
       
  1802 
       
  1803 
       
  1804 /**
       
  1805  * Initializes the audio device and starts playing the DTMF string aDTMFString.
       
  1806  * @param aSection - Section to read param from the ini file
       
  1807  * @return none
       
  1808  */
       
  1809 void CT_CMMFDevSoundData::DoCmdPlayDTMFStringL(const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
  1810 	{
       
  1811 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdPlayDTMFStringL"));
       
  1812 	TBool dataOk = ETrue;
       
  1813 	TPtrC dtmfString;
       
  1814 	if (!GetStringFromConfig(aSection, KDTMFString, dtmfString) )
       
  1815 		{
       
  1816 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDTMFString);
       
  1817 		SetBlockResult(EFail);
       
  1818 		dataOk = EFalse;
       
  1819 		}
       
  1820 	if(dataOk)
       
  1821 		{
       
  1822 		TRAPD( error, iDevSound->PlayDTMFStringL(dtmfString) );
       
  1823 		if(error != KErrNone)
       
  1824 			{
       
  1825 			ERR_PRINTF2(_L("Play DTMF string failed with error: %d "), error);
       
  1826 			SetError(error);
       
  1827 			}
       
  1828 		else
       
  1829 			{
       
  1830             iAsyncErrorIndex_tone = aAsyncErrorIndex;
       
  1831 			IncOutstanding();
       
  1832 			}
       
  1833 		}
       
  1834 
       
  1835 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdPlayDTMFStringL"));
       
  1836 	}
       
  1837 
       
  1838 /**
       
  1839  * Plays data in the buffer at the current volume.
       
  1840  * @param
       
  1841  * @return
       
  1842  */
       
  1843 void CT_CMMFDevSoundData::DoCmdPlayData()
       
  1844 	{
       
  1845 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdPlayData"));
       
  1846 	PlayData();
       
  1847 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdPlayData"));
       
  1848 	}
       
  1849 
       
  1850 /**
       
  1851  * Helper for the DoCmdPlayData command
       
  1852  */
       
  1853 void CT_CMMFDevSoundData::PlayData()
       
  1854 	{
       
  1855 	INFO_PRINTF1(_L("CT_CMMFDevSoundData::PlayData()"));
       
  1856 	iDevSound->PlayData();
       
  1857 	}
       
  1858 
       
  1859 /**
       
  1860  * Initializes audio device and starts playing a dual tone.
       
  1861  * The generated tone consists of two sine waves of different frequencies summed together.
       
  1862  * Dual Tone is played with the specified frequencies and for the specified duration.
       
  1863  * @param aSection - Section to read params from the ini file.
       
  1864  * @return none
       
  1865  */
       
  1866 void CT_CMMFDevSoundData::DoCmdPlayDualToneL(const TTEFSectionName& aSection)
       
  1867 	{
       
  1868 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdPlayDualToneL"));
       
  1869 	TBool dataOk = ETrue;
       
  1870 	TInt frequencyOne;
       
  1871 	if (!GetIntFromConfig(aSection, KFrequencyOne, frequencyOne) )
       
  1872 		{
       
  1873 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFrequencyOne);
       
  1874 		SetBlockResult(EFail);
       
  1875 		dataOk = EFalse;
       
  1876 		}
       
  1877 
       
  1878 	TInt frequencyTwo;
       
  1879 	if (!GetIntFromConfig(aSection, KFrequencyTwo, frequencyTwo) )
       
  1880 		{
       
  1881 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFrequencyTwo);
       
  1882 		SetBlockResult(EFail);
       
  1883 		dataOk = EFalse;
       
  1884 		}
       
  1885 
       
  1886 	TInt duration;
       
  1887 	if (!GetIntFromConfig(aSection, KDuration, duration) )
       
  1888 		{
       
  1889 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDuration);
       
  1890 		SetBlockResult(EFail);
       
  1891 		dataOk = EFalse;
       
  1892 		}
       
  1893 	if(dataOk)
       
  1894 		{
       
  1895 		TRAPD( error, iDevSound->PlayDualToneL(frequencyOne, frequencyTwo, duration) );
       
  1896 		if(error != KErrNone)
       
  1897 			{
       
  1898 			ERR_PRINTF2(_L("Play dual tone failed with error %d"), error);
       
  1899 			SetError(error);
       
  1900 			}
       
  1901 		else
       
  1902 			{
       
  1903 			IncOutstanding();
       
  1904 			}
       
  1905 		}
       
  1906 
       
  1907 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdPlayDualToneL"));
       
  1908 	}
       
  1909 
       
  1910 
       
  1911 /**
       
  1912  * Initializes the audio device and starts the play process.
       
  1913  *
       
  1914  * This function queries and acquires the audio policy before initializing audio device. If there was
       
  1915  * an error during policy initialization, PlayError() function will be called on    the observer with
       
  1916  * error code KErrAccessDenied, otherwise BufferToBeFilled() function will be called with a buffer
       
  1917  * reference. After reading data into the buffer reference passed, the client should call PlayData() to play data.
       
  1918  *
       
  1919  * The amount of data that can be played is specified in CMMFBuffer::RequestSize(). Any data that is read into
       
  1920  * buffer beyond this size will be ignored.
       
  1921  * @param none
       
  1922  * @return none
       
  1923  */
       
  1924 void CT_CMMFDevSoundData::DoCmdPlayInitL(const TInt aAsyncErrorIndex)
       
  1925 	{
       
  1926 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdPlayInitL"));
       
  1927 	TRAPD(error, iDevSound->PlayInitL());
       
  1928 	if (error != KErrNone)
       
  1929 		{
       
  1930 		ERR_PRINTF2(_L("PlayInitL left with error %d"), error);
       
  1931 		SetError(error);
       
  1932 		}
       
  1933 	else
       
  1934 		{
       
  1935         iAsyncErrorIndex_play = aAsyncErrorIndex;
       
  1936 		IncOutstanding();
       
  1937 		}
       
  1938 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdPlayInitL"));
       
  1939 	}
       
  1940 
       
  1941 /**
       
  1942  * Initializes the audio device and starts playing a tone. The tone is played with the
       
  1943  * frequency and duration specified.
       
  1944  * @param aSection - Section to read params from the ini file
       
  1945  * @return none
       
  1946  */
       
  1947 void CT_CMMFDevSoundData::DoCmdPlayToneL(const TTEFSectionName& aSection,  const TInt aAsyncErrorIndex)
       
  1948 	{
       
  1949 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdPlayToneL"));
       
  1950 	TBool dataOk = ETrue;
       
  1951 	TInt frequency;
       
  1952 	if (!GetIntFromConfig(aSection, KFrequency, frequency))
       
  1953 		{
       
  1954 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFrequency);
       
  1955 		SetBlockResult(EFail);
       
  1956 		dataOk = EFalse;
       
  1957 		}
       
  1958 
       
  1959 	TInt duration;
       
  1960 	if (!GetIntFromConfig(aSection, KDuration, duration))
       
  1961 		{
       
  1962 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDuration);
       
  1963 		SetBlockResult(EFail);
       
  1964 		dataOk = EFalse;
       
  1965 		}
       
  1966 	if(dataOk)
       
  1967 		{
       
  1968 		TRAPD(error, iDevSound->PlayToneL(frequency, duration));
       
  1969 		if (error != KErrNone)
       
  1970 			{
       
  1971 			ERR_PRINTF2(_L("Play tone failed with error %d"), error);
       
  1972 			SetError(error);
       
  1973 			}
       
  1974 		else
       
  1975 			{
       
  1976             iAsyncErrorIndex_tone = aAsyncErrorIndex;
       
  1977 			IncOutstanding();
       
  1978 			}
       
  1979 		}
       
  1980 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdPlayToneL"));
       
  1981 	}
       
  1982 
       
  1983 /**
       
  1984  * Initializes the audio device and starts playing a tone sequence.
       
  1985  * @param aSection - Section to read param from the ini file
       
  1986  * @return none
       
  1987  */
       
  1988 void CT_CMMFDevSoundData::DoCmdPlayToneSequenceL(const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
  1989 	{
       
  1990 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdPlayToneSequenceL"));
       
  1991 	TBool dataOk = ETrue;
       
  1992 	TPtrC toneFileParameter;
       
  1993 	if (!GetStringFromConfig(aSection, KFilename, toneFileParameter))
       
  1994 		{
       
  1995 		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KFilename);
       
  1996 		SetBlockResult(EFail);
       
  1997 		dataOk = EFalse;
       
  1998 		}
       
  1999 	if(dataOk)
       
  2000 		{
       
  2001 		TInt error = iToneFile.Open(iFs, toneFileParameter, EFileRead);
       
  2002 		if (error != KErrNone)
       
  2003 			{
       
  2004 			ERR_PRINTF2(_L("Open file failed with error %d"), error);
       
  2005 			SetError(EFail);
       
  2006 			}
       
  2007 		else
       
  2008 			{
       
  2009 			error = iToneFile.Read(iToneSequence);
       
  2010 			if (error != KErrNone)
       
  2011 				{
       
  2012 				ERR_PRINTF2(_L("Read file failed with error %d"), error);
       
  2013 				SetError(EFail);
       
  2014 				}
       
  2015 			else
       
  2016 				{
       
  2017 				TRAP(error, iDevSound->PlayToneSequenceL(iToneSequence));
       
  2018 				if (error != KErrNone)
       
  2019 					{
       
  2020 					ERR_PRINTF2(_L("Play tone sequence failed with error %d"), error);
       
  2021 					SetError(error);
       
  2022 					}
       
  2023 				else
       
  2024 					{
       
  2025                     iAsyncErrorIndex_tone = aAsyncErrorIndex;
       
  2026 					IncOutstanding();
       
  2027 					}
       
  2028 				}
       
  2029 			}
       
  2030 		}
       
  2031 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdPlayToneSequenceL"));
       
  2032 	}
       
  2033 
       
  2034 /**
       
  2035  * Contine the process of recording.
       
  2036  *
       
  2037  * Once the buffer is filled with recorded  data, the Observer gets a reference to the buffer along
       
  2038  * with the callback function BufferToBeEmptied(). After processing the buffer (copying over to a
       
  2039  * different buffer or writing to file) the client should call this function to continue the
       
  2040  * recording process.
       
  2041  * @param none
       
  2042  * @return none
       
  2043  */
       
  2044 void CT_CMMFDevSoundData::DoCmdRecordData()
       
  2045 	{
       
  2046 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdRecordData"));
       
  2047 	RecordData();
       
  2048 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdRecordData"));
       
  2049 	}
       
  2050 
       
  2051 /**
       
  2052  * Helper method to DoCmdRecordData command
       
  2053  */
       
  2054 void CT_CMMFDevSoundData::RecordData()
       
  2055 	{
       
  2056 	iDevSound->RecordData();
       
  2057 	}
       
  2058 
       
  2059 /**
       
  2060  * Initializes audio device and starts the recording process.
       
  2061  *
       
  2062  * This command queries and acquires the audio policy before initializing audio device. If there
       
  2063  * was an error during policy initialization, RecordError() function will be called on the observer
       
  2064  * with error code KErrAccessDenied, otherwise BufferToBeEmptied()  function will be called with a
       
  2065  * buffer reference. This buffer contains recorded  or encoded data. After processing data in the
       
  2066  * buffer reference passed, the client should call RecordData() to continue recording process.
       
  2067  *
       
  2068  * The amount of data that is available is specified in CMMFBuffer::RequestSize().
       
  2069  * @param none
       
  2070  * @return none
       
  2071  */
       
  2072 void CT_CMMFDevSoundData::DoCmdRecordInitL(const TInt aAsyncErrorIndex)
       
  2073 	{
       
  2074 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdRecordInitL"));
       
  2075     iAsyncErrorIndex_record = aAsyncErrorIndex;
       
  2076 	TRAPD(error, iDevSound->RecordInitL());
       
  2077 	if (error != KErrNone)
       
  2078 		{
       
  2079 		ERR_PRINTF2(_L("RecordInitL left with error %d"), error);
       
  2080 		SetError(error);
       
  2081 		}
       
  2082 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdRecordInitL"));
       
  2083 	}
       
  2084 
       
  2085 
       
  2086 /**
       
  2087  * Conceal an error
       
  2088  * @param none
       
  2089  * @return none
       
  2090  */
       
  2091 void CT_CMMFDevSoundData::DoCmdUtilityErrorConceal()
       
  2092 	{
       
  2093 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdErrorConceal"));
       
  2094 	iErrorConceal=ETrue;
       
  2095 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdErrorConceal"));
       
  2096 	}
       
  2097 
       
  2098 /**
       
  2099  * Stop an audio file
       
  2100  * @param none
       
  2101  * @return none
       
  2102  */
       
  2103 void CT_CMMFDevSoundData::DoCmdStop(const TTEFSectionName& aSection)
       
  2104 	{
       
  2105 	INFO_PRINTF1(_L("*START*CT_CMMFDevSoundData::DoCmdStop"));
       
  2106 	TBool pause;
       
  2107 	if(!GetBoolFromConfig(aSection,KPause,pause))
       
  2108 		{
       
  2109 		INFO_PRINTF1(_L("The DoCmdStop command will be execute"));
       
  2110 		pause = EFalse;
       
  2111 		}
       
  2112 	iPaused=pause;
       
  2113 	if(iPaused)
       
  2114 		{
       
  2115 		INFO_PRINTF1(_L("a Pause was required"));
       
  2116 		}
       
  2117 	Stop();
       
  2118 	INFO_PRINTF1(_L("*END*CT_CMMFDevSoundData::DoCmdStop"));
       
  2119 	}
       
  2120 
       
  2121 
       
  2122 
       
  2123 
       
  2124 /**
       
  2125  * Utility for get the HwDevice for play and recording
       
  2126  */
       
  2127 
       
  2128 void CT_CMMFDevSoundData::UtilityFourCCToHwDeviceUidL(const TDesC& aFourCC, THwDeviceType aType, TUid& aHwDeviceUid)
       
  2129 	{
       
  2130 	TPtrC8 fourCCPtr(0,0);
       
  2131 	TPtrC8 fourCCP16Ptr(0,0);
       
  2132 	RImplInfoPtrArray impArray;
       
  2133 	CleanupResetAndDestroyPushL(impArray);
       
  2134 	REComSession::ListImplementationsL(TUid::Uid(KMmfUidPluginInterfaceHwDevice), impArray);
       
  2135 	TBuf<KHwDeviceDefaultDataLength> datatype;
       
  2136 	for(TInt i = 0; i < impArray.Count(); ++i)
       
  2137 		{
       
  2138 		CImplementationInformation& entry = *(impArray[i]);
       
  2139 		// Validate lenght
       
  2140 		if (entry.DataType().Length() == KHwDeviceDefaultDataLength)
       
  2141 			{
       
  2142 			INFO_PRINTF2(_L("Implementation UID=0x%08x"),entry.ImplementationUid());
       
  2143 			datatype.Copy(entry.DataType());
       
  2144 			INFO_PRINTF2(_L("Default data (fourCCs)=%S"), &datatype);
       
  2145 			// Extract FourCC
       
  2146 			if(aType == EDecoder)
       
  2147 				{
       
  2148 				fourCCPtr.Set(entry.DataType().Left(KFourCCLength));
       
  2149 				fourCCP16Ptr.Set(entry.DataType().Right(KFourCCLength));
       
  2150 				}
       
  2151 			else if (aType == EEncoder)
       
  2152 				{
       
  2153 				fourCCPtr.Set(entry.DataType().Right(KFourCCLength));
       
  2154 				fourCCP16Ptr.Set(entry.DataType().Left(KFourCCLength));
       
  2155 				}
       
  2156 			// Compare FourCC
       
  2157 			TBuf16<4> foundFourCC;
       
  2158 			foundFourCC.Copy(fourCCPtr);
       
  2159 			if(aFourCC.CompareF(foundFourCC) == 0)
       
  2160 				{
       
  2161 				aHwDeviceUid = entry.ImplementationUid();
       
  2162 				break;
       
  2163 				}
       
  2164 			}
       
  2165 		}
       
  2166 	CleanupStack::PopAndDestroy(&impArray);
       
  2167 	REComSession::FinalClose();
       
  2168 	}