aboutsummaryrefslogtreecommitdiff
path: root/backends/PalmOS/Src/snd_stream.cpp
blob: ae4d3f80205290db57cd85a6840fcd70b5a987a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
}