[Scummvm-cvs-logs] CVS: scummvm/backends/PalmOS/Src snd_pa1.cpp,NONE,1.1 snd_stream.cpp,NONE,1.1

Chris Apers chrilith at users.sourceforge.net
Tue May 25 07:24:10 CEST 2004


Update of /cvsroot/scummvm/scummvm/backends/PalmOS/Src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11445

Added Files:
	snd_pa1.cpp snd_stream.cpp 
Log Message:
Sound FX support

--- NEW FILE: snd_pa1.cpp ---
#include "ARMNative.h"
#include "stdlib.h"
#include "globals.h"

#ifdef COMPILE_PA1SND
#	include <endianutils.h>
#endif


static Int32 diffLookup[16] = {
   1,3,5,7,9,11,13,15,
   -1,-3,-5,-7,-9,-11,-13,-15,
};

static Int32 indexScale[16] = {
   0x0e6, 0x0e6, 0x0e6, 0x0e6, 0x133, 0x199, 0x200, 0x266,
   0x0e6, 0x0e6, 0x0e6, 0x0e6, 0x133, 0x199, 0x200, 0x266 /* same value for speedup */
};

static int limit(int val,int min,int max) {
   if (val<min) return min;
   else if (val>max) return max;
   else return val;
}

void pcm2adpcm(Int16 *src, UInt8 *dst, UInt32 length) {
#ifndef COMPILE_PA1SND

	if (OPTIONS_TST(kOptDeviceARM)) {
		PnoDescriptor pno;
		ARMPa1SndType userData = {src, dst, length};
		
		MemPtr armP =	_PnoInit(ARM_PA1SND, &pno);
						_PnoCall(&pno, &userData);
						_PnoFree(&pno, armP);
		
		return;
	}

	int data,val,diff;
	int signal,step;
#else
	long chan1, chan2;
	long data,val,diff;
	long signal,step;
#endif

	signal = 0;
	step = 0x7F;
	length >>= 3;	// 16bit stereo -> 4bit mono
	
	do {

		// high nibble
#ifdef COMPILE_PA1SND
		chan1 = ByteSwap16(*src);
		src++;
		chan2 = ByteSwap16(*src);
		src++;
		
		diff = ((chan1 + chan2) >> 1) - signal;
#else
		diff = ((*src++ + *src++) >> 1) - signal;
#endif
		diff <<= 3;
		diff /= step;
		
		val = abs(diff) >> 1;

		if (val  > 7)	val = 7;
		if (diff < 0)	val+= 8;

		signal+= (step * diffLookup[val]) >> 3;
		signal = limit(signal, -32768, 32767);

		step = (step * indexScale[val]) >> 8;
		step = limit(step, 0x7F, 0x6000);

		data = val;

		// low nibble
#ifdef COMPILE_PA1SND
		chan1 = ByteSwap16(*src);
		src++;
		chan2 = ByteSwap16(*src);
		src++;
		
		diff = ((chan1 + chan2) >> 1) - signal;
#else
		diff = ((*src++ + *src++) >> 1) - signal;
#endif
		diff <<= 3;
		diff /= step;

		val = abs(diff) >> 1;

		if (val  > 7)	val = 7;
		if (diff < 0)	val+= 8;

		signal+= (step * diffLookup[val]) >> 3;
		signal = limit(signal, -32768, 32767);

		step = (step * indexScale[val]) >> 8;
		step = limit(step, 0x7F, 0x6000);

		data |= val << 4;

		*dst++ = (UInt8)data;

	} while(--length);

}

--- NEW FILE: snd_stream.cpp ---
#ifndef COMPILE_STREAMSND
#	include "stdafx.h"
#	include "palm.h"
#else
#	include "ARMNative.h"
#	include <endianutils.h>
#endif

#ifndef ByteSwap32
#define ByteSwap32(x)	x
#else
#define READ_LE_UINT32(x) *x
#endif

Err sndCallback(void* UserDataP, SndStreamRef stream, void* bufferP, UInt32 *bufferSizeP) {
	SoundDataType *snd = (SoundDataType *)UserDataP;
	UInt32 size = *bufferSizeP;

#ifdef COMPILE_STREAMSND
	// endian
	snd->set	= ByteSwap32(snd->set);
	snd->size	= ByteSwap32(snd->size);
#endif

	if (snd->set && snd->size) {
		UInt32 *dst = (UInt32 *)bufferP;
		UInt32 *src = (UInt32 *)ByteSwap32(snd->dataP);

		size = (snd->size / 16);
		while (size--) {
			*dst++ = READ_LE_UINT32(src++);
			*dst++ = READ_LE_UINT32(src++);
			*dst++ = READ_LE_UINT32(src++);
			*dst++ = READ_LE_UINT32(src++);
		}
		snd->set = false;	

	} else {
		snd->size = size;
		MemSet(bufferP, size, 0);
	}

#ifdef COMPILE_STREAMSND
	// endian
	snd->set	= ByteSwap32(snd->set);
	snd->size	= ByteSwap32(snd->size);
#endif

	return errNone;
}




More information about the Scummvm-git-logs mailing list