diff options
author | Chris Apers | 2004-05-25 14:23:17 +0000 |
---|---|---|
committer | Chris Apers | 2004-05-25 14:23:17 +0000 |
commit | 819bfde9cf90afee539b9b33b09c68c2e049cecb (patch) | |
tree | 903d79d9172594a0adc7faa8ee190d28e3f97932 /backends/PalmOS | |
parent | 530fd01fa365f5f9fa35d193ccbe33d7d4a51ce9 (diff) | |
download | scummvm-rg350-819bfde9cf90afee539b9b33b09c68c2e049cecb.tar.gz scummvm-rg350-819bfde9cf90afee539b9b33b09c68c2e049cecb.tar.bz2 scummvm-rg350-819bfde9cf90afee539b9b33b09c68c2e049cecb.zip |
Sound FX support
svn-id: r13882
Diffstat (limited to 'backends/PalmOS')
-rw-r--r-- | backends/PalmOS/Src/snd_pa1.cpp | 112 | ||||
-rw-r--r-- | backends/PalmOS/Src/snd_stream.cpp | 50 |
2 files changed, 162 insertions, 0 deletions
diff --git a/backends/PalmOS/Src/snd_pa1.cpp b/backends/PalmOS/Src/snd_pa1.cpp new file mode 100644 index 0000000000..4a430a827b --- /dev/null +++ b/backends/PalmOS/Src/snd_pa1.cpp @@ -0,0 +1,112 @@ +#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); + +} diff --git a/backends/PalmOS/Src/snd_stream.cpp b/backends/PalmOS/Src/snd_stream.cpp new file mode 100644 index 0000000000..ae4d3f8020 --- /dev/null +++ b/backends/PalmOS/Src/snd_stream.cpp @@ -0,0 +1,50 @@ +#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; +}
\ No newline at end of file |