baseport/syborg/soundsc/shared_txsound.cpp
changeset 15 5fca9e46c6fa
equal deleted inserted replaced
14:e6ebb7730c4b 15:5fca9e46c6fa
       
     1 /*
       
     2 * Copyright (c) 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 the License "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 #include "shared_sound.h"
       
    19 #include "variant_sound.h"
       
    20 
       
    21 void TimerCallback(TAny* aData)
       
    22 	{
       
    23 	DDriverSyborgSoundScPdd * soundscpdd = (DDriverSyborgSoundScPdd*) aData;
       
    24 		
       
    25 	soundscpdd->Callback(soundscpdd->iTransferArray[0].iTransferID, KErrNone, soundscpdd->iTransferArray[0].iNumBytes);
       
    26 	
       
    27 	}
       
    28 
       
    29 
       
    30 DDriverSyborgSoundScPdd::DDriverSyborgSoundScPdd() : iTimer(TimerCallback,this)
       
    31 	{
       
    32 
       
    33 	}
       
    34 
       
    35 DDriverSyborgSoundScPdd::~DDriverSyborgSoundScPdd()
       
    36 	{
       
    37 	iTimer.Cancel();
       
    38 	}
       
    39 
       
    40 
       
    41 TInt DDriverSyborgSoundScPdd::DoCreate()
       
    42 	{
       
    43 
       
    44 	SetCaps();
       
    45 
       
    46 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::DoCreate TxPdd");
       
    47 	
       
    48 	return KErrNone;
       
    49 	}
       
    50 
       
    51 void DDriverSyborgSoundScPdd::GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo)
       
    52 	{
       
    53 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::GetChunkCreateInfo TxPdd");
       
    54 	
       
    55 	aChunkCreateInfo.iType = TChunkCreateInfo::ESharedKernelMultiple;
       
    56 	aChunkCreateInfo.iMapAttr = EMapAttrFullyBlocking; 	// No caching
       
    57 	aChunkCreateInfo.iOwnsMemory = ETrue; 				// Using RAM pages
       
    58 	aChunkCreateInfo.iDestroyedDfc = NULL; 				// No chunk destroy DFC
       
    59 	}
       
    60 
       
    61 void DDriverSyborgSoundScPdd::Caps(TDes8& aCapsBuf) const
       
    62 	{
       
    63 
       
    64 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::Caps TxPdd");
       
    65 	
       
    66 	// Fill the structure with zeros in case it is a newer version than we know about
       
    67 	aCapsBuf.FillZ(aCapsBuf.MaxLength());
       
    68 
       
    69 	// And copy the capabilities into the packaged structure
       
    70 	TPtrC8 ptr((const TUint8*) &iCaps, sizeof(iCaps));
       
    71 	aCapsBuf = ptr.Left(Min(ptr.Length(), aCapsBuf.MaxLength()));
       
    72 	}
       
    73 
       
    74 TInt DDriverSyborgSoundScPdd::SetConfig(const TDesC8& aConfigBuf)
       
    75 	{
       
    76 
       
    77 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::SetConfig TxPdd");
       
    78 	
       
    79 	// Read the new configuration from the LDD
       
    80 	TCurrentSoundFormatV02 config;
       
    81 	TPtr8 ptr((TUint8*) &config, sizeof(config));
       
    82 	Kern::InfoCopy(ptr, aConfigBuf);
       
    83 
       
    84 	iConfig = config;
       
    85 	
       
    86 	return KErrNone;
       
    87 	}
       
    88 
       
    89 
       
    90 TInt DDriverSyborgSoundScPdd::SetVolume(TInt aVolume)
       
    91 	{
       
    92 	
       
    93 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::Setvolume TxPdd");
       
    94 	
       
    95 	return KErrNone;
       
    96 	}
       
    97 
       
    98 
       
    99 TInt DDriverSyborgSoundScPdd::StartTransfer()
       
   100 	{
       
   101 	
       
   102 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::starttransfer TxPdd");
       
   103 	
       
   104 	//Prepare for transfer
       
   105 	return KErrNone;
       
   106 	
       
   107 	}
       
   108 
       
   109 TInt DDriverSyborgSoundScPdd::CalculateBufferTime(TInt aNumBytes)
       
   110 	{
       
   111 	
       
   112 	TUint samplerate=0;
       
   113 
       
   114 	// Let the compiler perform an integer division of rates
       
   115 	switch(iConfig.iRate)
       
   116 		{
       
   117 		case ESoundRate7350Hz: 	samplerate = 7350; break;
       
   118 		case ESoundRate8000Hz: 	samplerate = 8000; break;
       
   119 		case ESoundRate8820Hz: 	samplerate = 8820; break;
       
   120 		case ESoundRate9600Hz: 	samplerate = 9600; break;
       
   121 		case ESoundRate11025Hz: samplerate = 11025; break;
       
   122 		case ESoundRate12000Hz: samplerate = 12000; break;
       
   123 		case ESoundRate14700Hz:	samplerate = 14700; break;
       
   124 		case ESoundRate16000Hz: samplerate = 16000; break;
       
   125 		case ESoundRate22050Hz: samplerate = 22050; break;
       
   126 		case ESoundRate24000Hz: samplerate = 24000; break;
       
   127 		case ESoundRate29400Hz: samplerate = 29400; break;
       
   128 		case ESoundRate32000Hz: samplerate = 32000; break;
       
   129 		case ESoundRate44100Hz: samplerate = 44100; break;
       
   130 		case ESoundRate48000Hz: samplerate = 48000; break;
       
   131 		}
       
   132 
       
   133 
       
   134 	// integer division by number of channels
       
   135 	aNumBytes /= iConfig.iChannels;
       
   136 
       
   137 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::iChannels =%d", iConfig.iChannels);
       
   138 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::iEncoding =%d", iConfig.iEncoding);
       
   139 	
       
   140 	// integer division by bytes per sample
       
   141 	switch(iConfig.iEncoding)
       
   142 		{
       
   143 		case ESoundEncoding8BitPCM: break;
       
   144 		case ESoundEncoding16BitPCM: aNumBytes /= 2; break;
       
   145 		case ESoundEncoding24BitPCM: aNumBytes /= 3; break;
       
   146 		}
       
   147 
       
   148 	return (aNumBytes * 1000) / samplerate; //return time in milliseconds
       
   149 	
       
   150 
       
   151 	}
       
   152 
       
   153 TInt DDriverSyborgSoundScPdd::TransferData(TUint aTransferID, TLinAddr aLinAddr, TPhysAddr /*aPhysAddr*/, TInt aNumBytes)
       
   154 	{
       
   155 
       
   156 	//function wil get called multiple times while transfer is in progress therefore keep fifo queue of requests
       
   157 	TTransferArrayInfo transfer;	
       
   158 		
       
   159 	transfer.iTransferID = aTransferID;
       
   160 	transfer.iLinAddr = aLinAddr;
       
   161 	transfer.iNumBytes = aNumBytes;
       
   162 	
       
   163 	//calculate the amount of time required to play/record buffer
       
   164 	TInt buffer_play_time = CalculateBufferTime(aNumBytes);
       
   165 	TInt timerticks = NKern::TimerTicks(buffer_play_time);
       
   166 	transfer.iPlayTime = timerticks;
       
   167 	
       
   168 	iTransferArray.Append(transfer);
       
   169 	
       
   170 	//Timer will callback when correct time has elapsed, will return KErrInUse if transfer
       
   171 	//already active, this is ok becuase will be started again in callback
       
   172 	TInt err = iTimer.OneShot(timerticks, ETrue);
       
   173 	
       
   174 	
       
   175 	return KErrNone;
       
   176 	}
       
   177 
       
   178 void DDriverSyborgSoundScPdd::StopTransfer()
       
   179 	{
       
   180 	// Stop transfer
       
   181 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::stoptransfer TxPdd");
       
   182 	
       
   183 	//If timer is currently active then cancel it and call back buffer
       
   184 	if(iTimer.Cancel())
       
   185 		{
       
   186 		Callback(iTransferArray[0].iTransferID, KErrNone, iTransferArray[0].iNumBytes);
       
   187 		}
       
   188 		
       
   189 
       
   190 	}
       
   191 
       
   192 
       
   193 TInt DDriverSyborgSoundScPdd::PauseTransfer()
       
   194 	{
       
   195 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::pausetransfer TxPdd");
       
   196 	//Pause Transfer
       
   197 	
       
   198 	return KErrNone;
       
   199 	}
       
   200 
       
   201 
       
   202 TInt DDriverSyborgSoundScPdd::ResumeTransfer()
       
   203 	{
       
   204 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::resumetransfer TxPdd");
       
   205 	//Resume Transfer
       
   206 	
       
   207 	return KErrNone;
       
   208 	}
       
   209 
       
   210 TInt DDriverSyborgSoundScPdd::PowerUp()
       
   211 	{
       
   212 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::PowerUp TxPdd");
       
   213 	return KErrNone;
       
   214 	}
       
   215 
       
   216 void DDriverSyborgSoundScPdd::PowerDown()
       
   217 	{
       
   218 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::Powerdown TxPdd");
       
   219 	}
       
   220 
       
   221 TInt DDriverSyborgSoundScPdd::CustomConfig(TInt /*aFunction*/,TAny* /*aParam*/)
       
   222 	{
       
   223 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::customconfig TxPdd");
       
   224 	return KErrNotSupported;
       
   225 	}
       
   226 
       
   227 
       
   228 void DDriverSyborgSoundScPdd::Callback(TUint aTransferID, TInt aTransferResult, TInt aBytesTransferred)
       
   229 	{
       
   230 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::playcallback TxPdd");
       
   231 	//Callback when Transfer completes or is stopped
       
   232 	
       
   233 	iTransferArray.Remove(0);
       
   234 	
       
   235 	if(iUnitType == KSoundScTxUnit0)
       
   236 		{
       
   237 		Ldd()->PlayCallback(aTransferID, aTransferResult, aBytesTransferred);
       
   238 		}
       
   239 	else if(iUnitType == KSoundScRxUnit0)
       
   240 		{
       
   241 		Ldd()->RecordCallback(aTransferID, aTransferResult, aBytesTransferred);
       
   242 		}
       
   243 	
       
   244 	if(	iTransferArray.Count()>0)
       
   245 		{
       
   246 		iTimer.OneShot(iTransferArray[0].iPlayTime, ETrue);
       
   247 		}
       
   248 	
       
   249 	}
       
   250 
       
   251 TDfcQue*DDriverSyborgSoundScPdd::DfcQ()
       
   252 	{
       
   253 	return iPhysicalDevice->iDfcQ;
       
   254 	}
       
   255 
       
   256 
       
   257 TInt DDriverSyborgSoundScPdd::MaxTransferLen() const
       
   258 	{
       
   259 	
       
   260 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::MaxTransferLen TxPdd");
       
   261 	
       
   262 	TInt maxlength = 200*1024;
       
   263 	return maxlength;
       
   264 	}
       
   265 
       
   266 
       
   267 void DDriverSyborgSoundScPdd::SetCaps()
       
   268 	{
       
   269 	SYBORG_SOUND_DEBUG("DDriverSyborgSoundScPdd::SetCaps TxPdd");
       
   270 	
       
   271 	if(iUnitType == KSoundScTxUnit0)
       
   272 		{
       
   273 		// The data transfer direction for this unit is play
       
   274 		iCaps.iDirection = ESoundDirPlayback;
       
   275 		}
       
   276 	else if(iUnitType == KSoundScTxUnit0)
       
   277 		{
       
   278 		// The data transfer direction for this unit is play
       
   279 		iCaps.iDirection = ESoundDirRecord;
       
   280 		}
       
   281 	
       
   282 	// This unit supports both mono and stereo
       
   283 	iCaps.iChannels = (KSoundMonoChannel | KSoundStereoChannel);
       
   284 
       
   285 	// This unit supports only some of the sample rates offered by Symbian OS
       
   286 	iCaps.iRates = (KSoundRate8000Hz | KSoundRate11025Hz | KSoundRate12000Hz | KSoundRate16000Hz |
       
   287 					KSoundRate22050Hz | KSoundRate24000Hz | KSoundRate32000Hz | KSoundRate44100Hz |
       
   288 					KSoundRate48000Hz);
       
   289 
       
   290 	// This unit only supports 16bit PCM encoding
       
   291 	iCaps.iEncodings = KSoundEncoding16BitPCM;
       
   292 
       
   293 	// This unit only supports interleaved data format when playing stereo;  that is, a PCM data
       
   294 	// stream where the left and right channel samples are interleaved as L-R-L-R-L-R etc.
       
   295 	iCaps.iDataFormats = KSoundDataFormatInterleaved;
       
   296 
       
   297 	// The iRequestMinSize member is named badly.  It is actually the value of which the length samples
       
   298 	// must be a multiple of.  ie.  The sample length % iRequestMinSize must == 0.  This value must always
       
   299 	// be a power of 2
       
   300 	iCaps.iRequestMinSize = 4;
       
   301 
       
   302 	// The logarithm to base 2 of the alignment required for request arguments.  DMA requests must be
       
   303 	// aligned to a 32 bit boundary
       
   304 	iCaps.iRequestAlignment = 2;
       
   305 
       
   306 	// This unit is not capable of detecting changes in hardware configuration
       
   307 	iCaps.iHwConfigNotificationSupport = EFalse;
       
   308 	}
       
   309 
       
   310 
       
   311 
       
   312