os/boardsupport/haitest/bspsvs/suite/bsp/sound/src/sound_util.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/sound/src/sound_util.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,175 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#include "sound_util.h"
    1.22 +
    1.23 +// Translation table for RMdaDevSound::TMdaSoundEncoding set
    1.24 +
    1.25 +_LIT(KStrEMdaSoundEncoding8BitPCM,			"EMdaSoundEncoding8BitPCM");
    1.26 +_LIT(KStrEMdaSoundEncoding16BitPCM,			"EMdaSoundEncoding16BitPCM");
    1.27 +_LIT(KStrEMdaSoundEncoding8BitALaw,			"EMdaSoundEncoding8BitALaw");
    1.28 +_LIT(KStrEMdaSoundEncoding8BitMuLaw,		"EMdaSoundEncoding8BitMuLaw");
    1.29 +
    1.30 +// NB! Wrong member for negative testing
    1.31 +_LIT(KStrEMdaSoundEncoding40BitPCM,			"EMdaSoundEncoding40BitPCM");
    1.32 +_LIT(KStrNull,								"");
    1.33 +
    1.34 +const CDataWrapperBase::TEnumEntryTable		TSoundUtil::iEnumTableSoundEncoding[] =
    1.35 +	{
    1.36 +//	Enum as a descriptor					Enum
    1.37 +	KStrEMdaSoundEncoding8BitPCM,			RMdaDevSound::EMdaSoundEncoding8BitPCM,
    1.38 +	KStrEMdaSoundEncoding16BitPCM,			RMdaDevSound::EMdaSoundEncoding16BitPCM,
    1.39 +	KStrEMdaSoundEncoding8BitALaw,			RMdaDevSound::EMdaSoundEncoding8BitALaw,
    1.40 +	KStrEMdaSoundEncoding8BitMuLaw,			RMdaDevSound::EMdaSoundEncoding8BitMuLaw,
    1.41 +	KStrEMdaSoundEncoding40BitPCM,			0x00000040,
    1.42 +	KStrNull,								-1
    1.43 +	};
    1.44 +
    1.45 +/**
    1.46 + * Loading of generinc sound driver required for RMDaDevSound interface
    1.47 + * 
    1.48 + * @param aLll 				LDD driver name
    1.49 + * @param aPdd				PDD driver name
    1.50 + *
    1.51 + * @return					System wide error
    1.52 + *
    1.53 + * @leave					no
    1.54 + */
    1.55 +TInt	TSoundUtil::LoadSoundDrivers(const TDesC& aLdd, const TDesC& aPdd)
    1.56 +	{
    1.57 +	TInt rerr = KErrNone;
    1.58 +	
    1.59 +	rerr = User::LoadPhysicalDevice(aPdd);
    1.60 +	if(rerr != KErrNone && rerr != KErrAlreadyExists)
    1.61 +		{
    1.62 +		return rerr;
    1.63 +		}
    1.64 +	rerr = User::LoadLogicalDevice(aLdd);	
    1.65 +	if(rerr != KErrNone && rerr != KErrAlreadyExists)
    1.66 +		{
    1.67 +		return rerr;
    1.68 +		}
    1.69 +	return KErrNone;	
    1.70 +	}
    1.71 +
    1.72 +/**
    1.73 + * Un-loading of generinc sound driver required for RMDaDevSound interface
    1.74 + * 
    1.75 + * @param aLll 				LDD driver name
    1.76 + * @param aPdd				PDD driver name
    1.77 + *
    1.78 + * @return					System wide error
    1.79 + *
    1.80 + * @leave					no
    1.81 + */
    1.82 +TInt	TSoundUtil::FreeSoundDrivers(const TDesC& aLdd, const TDesC& aPdd)
    1.83 +	{
    1.84 +	TInt rerr = KErrNone;
    1.85 +	
    1.86 +	rerr = User::FreePhysicalDevice(aPdd);
    1.87 +	if(rerr != KErrNone && rerr != KErrAlreadyExists)
    1.88 +		{
    1.89 +		return rerr;
    1.90 +		}
    1.91 +	rerr = User::FreeLogicalDevice(aLdd);	
    1.92 +	if(rerr != KErrNone && rerr != KErrAlreadyExists)
    1.93 +		{
    1.94 +		return rerr;
    1.95 +		}
    1.96 +	return KErrNone;	
    1.97 +	}
    1.98 +
    1.99 +/**
   1.100 + * Store current RBuf8 content into the binary file
   1.101 + * 
   1.102 + * @param aFile 			file name to save audio data
   1.103 + *
   1.104 + * @return					System wide error
   1.105 + *
   1.106 + * @leave					System wide error
   1.107 + */
   1.108 +TInt	TSoundUtil::RAudioBuffer::SaveAudioDataL(const TDesC& aFile)
   1.109 +	{	
   1.110 +	RFs fsSession;
   1.111 +	::CleanupClosePushL(fsSession);
   1.112 +	User::LeaveIfError(fsSession.Connect()); 	
   1.113 +	TInt err = KErrNone;
   1.114 +	RFile file;
   1.115 +	err = file.Create(fsSession, aFile, EFileStream | EFileWrite);
   1.116 +	if (!err)
   1.117 +		{
   1.118 +		err = file.Write(*this);
   1.119 +
   1.120 +		file.Close();
   1.121 +		}	
   1.122 +	fsSession.Close();
   1.123 +	CleanupStack::PopAndDestroy();		
   1.124 +	return err;
   1.125 +	}
   1.126 +
   1.127 +/**
   1.128 + * Load binary file content into RBuf8
   1.129 + * 
   1.130 + * @param aFile 			file name where to load audio data
   1.131 + *
   1.132 + * @return					System wide error
   1.133 + *
   1.134 + * @leave					System wide error
   1.135 + */
   1.136 +TInt	TSoundUtil::RAudioBuffer::LoadAudioDataL(const TDesC& aFile)
   1.137 +	{
   1.138 +	RFs fsSession;
   1.139 +	::CleanupClosePushL(fsSession);
   1.140 +	User::LeaveIfError(fsSession.Connect());	
   1.141 +	TFindFile	findFile(fsSession);
   1.142 +	TInt err = findFile.FindByDir(aFile, KStrNull);
   1.143 +	if ( err == KErrNone )
   1.144 +		{
   1.145 +		const TDesC&	fileName=findFile.File();
   1.146 +		RFile file;
   1.147 +		err = file.Open(fsSession, fileName, EFileStream | EFileRead);
   1.148 +		if (!err)
   1.149 +			{
   1.150 +			err = file.Read(*this);
   1.151 +			file.Close();
   1.152 +			}
   1.153 +		}
   1.154 +	fsSession.Close();
   1.155 +	CleanupStack::PopAndDestroy();		
   1.156 +	return err;	
   1.157 +	}
   1.158 +
   1.159 +/**
   1.160 + * Delete file
   1.161 + * 
   1.162 + * @param aFile 			file name to delete
   1.163 + *
   1.164 + * @return					System wide error
   1.165 + *
   1.166 + * @leave					System wide error
   1.167 + */
   1.168 +TInt	TSoundUtil::DeleteFileL(const TDesC& aFile)
   1.169 +	{
   1.170 +	RFs fsSession;
   1.171 +	CleanupClosePushL(fsSession);
   1.172 +	User::LeaveIfError(fsSession.Connect());
   1.173 +	TInt err;
   1.174 +	err = fsSession.Delete(aFile);	
   1.175 +	fsSession.Close();
   1.176 +	CleanupStack::PopAndDestroy();
   1.177 +	return err;
   1.178 +	}