Пример #1
0
// Convert an 8 bit unsigned voice to the current rate.
// Maintains unsignedness.
void ConvertVoice8( Voice* InVoice )
{
	// How fast is this sample?
	INT VoiceRate = InVoice->pSample->SamplesPerSec;
	if ((VoiceRate != 11025) && (VoiceRate != 22050) && (VoiceRate != 44100))
		appErrorf( TEXT("Unsupported playback rate: %i"), VoiceRate );
	if (VoiceRate > AudioRate)
	{
		// This voice is slower than our current rate.
		INT RateFactor = VoiceRate / AudioRate;
		INT NewSize;
		if (InVoice->pSample->Length % 2 == 1)
			NewSize = (InVoice->pSample->Length+1) / RateFactor;
		else
			NewSize = InVoice->pSample->Length / RateFactor;
		BYTE* Source = (BYTE*) InVoice->pSample->Data;
		BYTE* NewData = (BYTE*) appMalloc(NewSize, TEXT("Sample Data"));
		check(NewData);
		BYTE* Dest = NewData;

		appMemset( Dest, 0x80, NewSize );
		for (INT i=0; i<InVoice->pSample->Length; i += RateFactor)
		{
			*Dest = Source[i];
			Dest++;
		}

		InVoice->PlayPosition = 0;
		InVoice->pSample->SamplesPerSec = AudioRate;
		InVoice->pSample->Length = NewSize;
		void* OldData = InVoice->pSample->Data;
		InVoice->pSample->Data = NewData;
		appFree( OldData );
	} else {
		// This voice is faster than our current rate.
		INT RateFactor = AudioRate / VoiceRate;
		INT NewSize = InVoice->pSample->Length * RateFactor;

		BYTE* Source = (BYTE*) InVoice->pSample->Data;
		BYTE* NewData = (BYTE*) appMalloc(NewSize, TEXT("Sample Data"));
		check(NewData);
		BYTE* Dest = NewData;

		appMemset( Dest, 0x80, NewSize );
		for (INT i=0; i<NewSize; i++)
		{
			Dest[i] = *Source;
			if (i%RateFactor == 1)
				Source++;
		}

		InVoice->PlayPosition = 0;
		InVoice->pSample->SamplesPerSec = AudioRate;
		InVoice->pSample->Length = NewSize;
		void* OldData = InVoice->pSample->Data;
		InVoice->pSample->Data = (void*) NewData;
		appFree( OldData );
	}
}
Пример #2
0
void crAppFinalize()
{
	meshFree(meshBg);
	materialFree(mtlText);
	Label_free(label);
	appFree(app);
}
Пример #3
0
void S_Shutdown(void)
{
	if (!sound_started)
		return;

	SNDDMA_Shutdown();

	sound_started = false;

	UnregisterCommand("play");
	UnregisterCommand("stopsound");
	UnregisterCommand("soundlist");
	UnregisterCommand("soundinfo");

	// free all sounds
	int		i;
	sfx_t	*sfx;
	for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++)
	{
		if (!sfx->Name[0])
			continue;
		if (sfx->cache)
			appFree(sfx->cache);
		memset(sfx, 0, sizeof(*sfx));
	}

	num_sfx = 0;
}
Пример #4
0
void S_EndRegistration(void)
{
	int		i;
	sfx_t	*sfx;

	// free any sounds not from this registration sequence
	for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++)
	{
		if (!sfx->Name[0])
			continue;
		if (sfx->registration_sequence != s_registration_sequence)
		{
			// don't need this sound
			if (sfx->cache)	// it is possible to have a leftover
				appFree(sfx->cache);	// from a server that didn't finish loading
			memset(sfx, 0, sizeof(*sfx));
		}
	}

	// load everything in
	for (i = 0, sfx = known_sfx; i < num_sfx; i++, sfx++)
	{
		if (!sfx->Name[0])
			continue;
		S_LoadSound(sfx);
	}

	s_registering = false;
}
Пример #5
0
/**
 * Sends a command to the database proxy.
 *
 * @param	Cmd		The command to be sent.
 */
UBOOL ExecuteDBProxyCommand(FSocket *Socket, const TCHAR* Cmd)
{
	check(Socket);
	check(Cmd);

	INT CmdStrLength = appStrlen(Cmd);
	INT BytesSent = 0;

	// add 1 so we also send NULL
	++CmdStrLength;

	TCHAR *SendBuf = (TCHAR*)appMalloc(CmdStrLength * sizeof(TCHAR));

	// convert to network byte ordering. This is important for running on the ps3 and xenon
	for(INT BufIndex = 0; BufIndex < CmdStrLength; ++BufIndex)
	{
		SendBuf[BufIndex] = htons(Cmd[BufIndex]);
	}

	UBOOL bRet = Socket->Send((BYTE*)SendBuf, CmdStrLength * sizeof(TCHAR), BytesSent);

	appFree(SendBuf);

	return bRet;
}
Пример #6
0
UBOOL DestroyAudioThread(AudioThread* OldThread)
{
	ALock;
	OldThread->Valid = 0;
	AUnlock;
	pthread_t* Thread = (pthread_t*) OldThread->Thread;
	pthread_join(*Thread, NULL);
	appFree(OldThread->Thread);
	return 1;
}
Пример #7
0
/**
 * Captures the current stack and updates stack tracking information.
 * optionally stores a user data pointer that the tracker will take ownership of and delete upon reset
 * you must allocate the memory with appMalloc()
 */
void FStackTracker::CaptureStackTrace(INT EntriesToIgnore /*=2*/, void* UserData /*=NULL*/)
{
	// Avoid re-rentrancy as the code uses TArray/TMap.
	if( !bAvoidCapturing && bIsEnabled )
	{
		// Scoped TRUE/ FALSE.
		bAvoidCapturing = TRUE;

		// Capture callstack and create CRC.
		QWORD* FullBackTrace = NULL;
		FullBackTrace = static_cast<QWORD*>(appAlloca((MAX_BACKTRACE_DEPTH + EntriesToIgnore) * sizeof(QWORD)));

		appCaptureStackBackTrace( FullBackTrace, MAX_BACKTRACE_DEPTH + EntriesToIgnore );
		// Skip first NUM_ENTRIES_TO_SKIP entries as they are inside this code
		QWORD* BackTrace = &FullBackTrace[EntriesToIgnore];
		DWORD CRC = appMemCrc( BackTrace, MAX_BACKTRACE_DEPTH * sizeof(QWORD), 0 );
        
		// Use index if found
		INT* IndexPtr = CRCToCallStackIndexMap.Find( CRC );
        
		if( IndexPtr )
		{
			// Increase stack count for existing callstack.
			CallStacks(*IndexPtr).StackCount++;
			if (UpdateFn)
			{
				UpdateFn(CallStacks(*IndexPtr), UserData);
			}

			//We can delete this since the user gives ownership at the beginning of this call
			//and had a chance to update their data inside the above callback
			if (UserData)
			{
				appFree(UserData);
			}
		}
		// Encountered new call stack, add to array and set index mapping.
		else
		{
			// Add to array and set mapping for future use.
			INT Index = CallStacks.Add();
			CRCToCallStackIndexMap.Set( CRC, Index );

			// Fill in callstack and count.
			FCallStack& CallStack = CallStacks(Index);
			appMemcpy( CallStack.Addresses, BackTrace, sizeof(QWORD) * MAX_BACKTRACE_DEPTH );
			CallStack.StackCount = 1;
			CallStack.UserData = UserData;
		}

		// We're done capturing.
		bAvoidCapturing = FALSE;
	}
}
Пример #8
0
FArray::~FArray()
{
	if (!IsStatic())
	{
		if (DataPtr)
			appFree(DataPtr);
	}
	DataCount = 0;
	DataPtr   = NULL;
	MaxCount  = 0;
}
void xprAppFinalize()
{
	remoteConfigFree(config);
	Cloth_free(cloth);
	meshFree(ballMesh);
	meshFree(floorMesh);
	meshFree(bgMesh);
	materialFree(shadowMapMtl);
	materialFree(sceneMtl);
	materialFree(bgMtl);
	xprTextureFree(texture);
	appFree(app);
}
Пример #10
0
void Physics::ExitCollision( void )
{
	DLogWriteSystem(" ---- Exit Collision ----" );
	For( int i = AllocatedMemory.Num()-1; i >= 0; --i )
		appFree(AllocatedMemory[i]);
	AllocatedMemory.Empty();
	For( int i = 0; i < HASH_TABLE_NUM; ++i )
		Hash[i] = NULL;

	DTerrainActor::TerrainList.Empty();

	DLogWriteSystem(" ---- exit collision end" );
}
Пример #11
0
void CloseAudio()
{
	ALock;
	if (AudioBuffer != NULL)
	{
		appFree(AudioBuffer);
		AudioBuffer = NULL;
	}
	if (AudioDevice > -1)
	{
		close(AudioDevice);
		AudioDevice = -1;
	}
	AUnlock;
}
Пример #12
0
/*
 * Decrypt.
 * plainText->Data is allocated by the CSP and must be freed (via
 * free()) by caller.
 */
CSSM_RETURN cdsaDecrypt(
	CSSM_CSP_HANDLE		cspHandle,
	const CSSM_KEY		*key,
	const CSSM_DATA		*cipherText,
	CSSM_DATA_PTR		plainText)
{
	CSSM_RETURN 	crtn;
	CSSM_CC_HANDLE	ccHandle;
	CSSM_DATA		remData = {0, NULL};
	uint32			bytesDecrypted;
	
	crtn = genCryptHandle(cspHandle, key, &ivCommon, &ccHandle);
	if(crtn) {
		return crtn;
	}
	plainText->Length = 0;
	plainText->Data = NULL;
	crtn = CSSM_DecryptData(ccHandle,
		cipherText,
		1,
		plainText,
		1,
		&bytesDecrypted,
		&remData);
	CSSM_DeleteContext(ccHandle);
	if(crtn) {
		return crtn;
	}
	
	plainText->Length = bytesDecrypted;
	if(remData.Length != 0) {
		/* append remaining data to plainText */
		uint32 newLen = plainText->Length + remData.Length;
		plainText->Data = (uint8 *)appRealloc(plainText->Data,
			newLen,
			NULL);
		memmove(plainText->Data + plainText->Length, 
			remData.Data, remData.Length);
		plainText->Length = newLen;
		appFree(remData.Data, NULL);
	}
	return CSSM_OK;
}
Пример #13
0
/** Resets stack tracking. Deletes all user pointers passed in via CaptureStackTrace() */
void FStackTracker::ResetTracking()
{
	check(!bAvoidCapturing);
	CRCToCallStackIndexMap.Empty();

	//Clean up any user data 
	for(INT i=0; i<CallStacks.Num(); i++)
	{
		if (CallStacks(i).UserData)
		{
			appFree(CallStacks(i).UserData);
		}
	}

	CallStacks.Empty();

    //Reset the markers
	StartFrameCounter = GFrameCounter;
	StopFrameCounter = GFrameCounter;
}
Пример #14
0
void FArray::Empty(int count, int elementSize)
{
	guard(FArray::Empty);

	DataCount = 0;

	if (IsStatic())
	{
		if (count <= MaxCount)
			return;
		// "static" array becomes non-static, invalidate data pointer
		DataPtr = NULL;
	}

	//!! TODO: perhaps round up 'Max' to 16 bytes, allow comparison below to be 'softer'
	//!! (i.e. when array is 16 items, and calling Empty(15) - don't reallicate it, unless
	//!! item size is large
	if (DataPtr)
	{
		// check if we need to release old array
		if (count == MaxCount)
		{
			// the size was not changed
			return;
		}
		// delete old memory block
		appFree(DataPtr);
		DataPtr = NULL;
	}

	MaxCount = count;

	if (count)
	{
		DataPtr = appMalloc(count * elementSize);
	}

	unguardf("%d x %d", count, elementSize);
}
Пример #15
0
UBOOL DestroyAudioMutex(AudioMutex* Mutex)
{
	pthread_mutex_destroy((pthread_mutex_t*) Mutex->Mutex);
	appFree(Mutex->Mutex);
	return 1;
}
Пример #16
0
void xprAppFinalize()
{
	materialFree(mtlText);
	Label_free(label);
	appFree(app);
}
/*
 * CDSA private key decrypt with blinding option.
 */
static CSSM_RETURN _cspDecrypt(CSSM_CSP_HANDLE cspHand,
		uint32 algorithm,					// CSSM_ALGID_FEED, etc.
		uint32 mode,						// CSSM_ALGMODE_CBC, etc. - only for symmetric algs
		CSSM_PADDING padding,				// CSSM_PADDING_PKCS1, etc. 
		CSSM_BOOL blinding,
		const CSSM_KEY *key,				// public or session key
		const CSSM_DATA *ctext,
		CSSM_DATA_PTR ptext)				// RETURNED
{
	CSSM_CC_HANDLE 	cryptHand;
	CSSM_RETURN		crtn;
	CSSM_RETURN		ocrtn = CSSM_OK;
	CSSM_SIZE		bytesDecrypted;
	CSSM_DATA		remData = {0, NULL};

	cryptHand = genCryptHandle(cspHand, 
		algorithm, 
		mode, 
		padding,
		key, 
		NULL,		// pubKey, 
		NULL,		// iv,
		0,			// effectiveKeySizeInBits,
		0);			// rounds
	if(cryptHand == 0) {
		return CSSMERR_CSP_INTERNAL_ERROR;
	}
	if(blinding) {
		CSSM_CONTEXT_ATTRIBUTE	newAttr;	
		newAttr.AttributeType     = CSSM_ATTRIBUTE_RSA_BLINDING;
		newAttr.AttributeLength   = sizeof(uint32);
		newAttr.Attribute.Uint32  = 1;
		crtn = CSSM_UpdateContextAttributes(cryptHand, 1, &newAttr);
		if(crtn) {
			printError("CSSM_UpdateContextAttributes", crtn);
			return crtn;
		}
	}

	crtn = CSSM_DecryptData(cryptHand,
		ctext,
		1,
		ptext,
		1,
		&bytesDecrypted,
		&remData);
	if(crtn == CSSM_OK) {
		// NOTE: We return the proper length in ptext....
		ptext->Length = bytesDecrypted;
		
		// FIXME - sometimes get mallocd RemData here, but never any valid data
		// there...side effect of CSPFullPluginSession's buffer handling logic;
		// but will we ever actually see valid data in RemData? So far we never
		// have....
		if(remData.Data != NULL) {
			appFree(remData.Data, NULL);
		}
	}
	else {
		printError("CSSM_DecryptData", crtn);
		ocrtn = crtn;
	}
	crtn = CSSM_DeleteContext(cryptHand);
	if(crtn) {
		printError("CSSM_DeleteContext", crtn);
		ocrtn = crtn;
	}
	return ocrtn;
}
Пример #18
0
void* DoSound(void* Arguments)
{
	// Allocate the mixing buffer.
	ALock;
	MixBuffer = appMalloc(BufferSize, TEXT("Mixing Buffer"));
	AUnlock;

	INT Task = SOUND_MIXING, i;
	while (MixingThread.Valid)
	{
		switch (Task)
		{
			case SOUND_MIXING:
				ALock;
				// Empty the mixing buffer.
				appMemset(MixBuffer, 0, BufferSize);
				for (i=0; i<AUDIO_TOTALVOICES; i++)
				{
					// Get an enabled and active voice.
					if ((Voices[i].State&VOICE_ENABLED) && (Voices[i].State&VOICE_ACTIVE) && !AudioPaused)
					{
						// Mix a buffer's worth of sound.
						INT Format = Voices[i].pSample->Type & SAMPLE_16BIT 
							? SAMPLE_16BIT : SAMPLE_8BIT;
						switch (Format)
						{
							case SAMPLE_8BIT:
								if (AudioFormat & AUDIO_16BIT)
									MixVoice8to16( i );
								break;
							case SAMPLE_16BIT:
								if (AudioFormat & AUDIO_16BIT)
									MixVoice16to16( i );
								break;
						}
					}
				}
				AUnlock;
				Task = SOUND_PLAYING;
				break;
			case SOUND_PLAYING:
				// Block until the audio device is writable.
				if (!AudioPaused)
				{
					if (AudioWait() == 0)
						break;
				} else break;

				ALock;
				// Silence the audio buffer.
				appMemset(AudioBuffer, 0, BufferSize);

				// Ready the most recently mixed audio.
				appMemcpy(AudioBuffer, MixBuffer, BufferSize);

				// Play it.
				if (!AudioPaused)
				{
					PlayAudio();
				}
				AUnlock;

				Task = SOUND_MIXING;
				break;
		}
	}

	// Free the mixing buffer.
	ALock;
	if (MixBuffer != NULL)
		appFree(MixBuffer);
	AUnlock;
	
	ExitAudioThread(&MixingThread);
}
Пример #19
0
extern "C" void zcfree(int opaque, void *ptr)
{
	appFree(ptr);
}
Пример #20
0
static void mspack_free(void *ptr)
{
	appFree(ptr);
}
Пример #21
0
	~BufferData()
	{
		if (Data) appFree(Data);
	}