aboutsummaryrefslogtreecommitdiff
path: root/backends/PalmOS/Src/os5_sound.cpp
blob: ab81a0827db51c23908d0d86d01628287d431ebf (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2001  Ludvig Strigeus
 * Copyright (C) 2001-2005 The ScummVM project
 * Copyright (C) 2002-2005 Chris Apers - PalmOS Backend
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#include "be_os5.h"
#include "common/config-manager.h"

#ifdef PALMOS_68K
static void initRegs(void *addr) {
	asm (
		move.l	addr, a0
		move.l	a4, 0(a0)
		move.l	a5, 4(a0)
	);
}

static Err sndCallback(void* UserDataP, SndStreamRef stream, void* bufferP, UInt32 *bufferSizeP) {
	asm (
//		movem.l a4-a5, -(sp)
		move.l UserDataP, a0
		move.l 0(a0), a4
		move.l 4(a0), a5
	);

	SoundDataType *_sound = (SoundDataType *)UserDataP;
	((OSystem::SoundProc)_sound->proc)(_sound->param, (byte *)bufferP, *bufferSizeP);

//	asm ( movem.l (sp)+, a4-a5 );
	return errNone;
}

#else

static SYSTEM_CALLBACK Err sndCallback(void* UserDataP, SndStreamRef stream, void* bufferP, UInt32 *bufferSizeP) {
	SoundDataType *_sound = (SoundDataType *)UserDataP;
	((OSystem::SoundProc)_sound->proc)(_sound->param, (byte *)bufferP, *bufferSizeP);
	return errNone;
}
#endif


bool OSystem_PalmOS5::setSoundCallback(SoundProc proc, void *param) {
	Err e;
	Boolean success = false;

	if (!_sound.active) {
		_sound.proc = proc;
		_sound.param = param;
		_sound.active = true;		// always true when we call this function, false when sound is off
		_sound.handle = NULL;


		if (ConfMan.hasKey("output_rate"))
			_samplesPerSec = ConfMan.getInt("output_rate");
		else
#ifdef PALMOS_ARM
			_samplesPerSec = 22050;	// default value
#else
			_samplesPerSec = 8000;	// default value
#endif

		// try to create sound stream
		if (1 || OPTIONS_TST(kOptPalmSoundAPI)) {
#ifdef PALMOS_68K
			initRegs(&_sound);
#endif
			e = SndStreamCreateExtended(
						&_sound.handle,
						sndOutput,
						sndFormatPCM,
						_samplesPerSec,
#ifdef PALMOS_ARM
						sndInt16Little,
#else
						sndInt16Big,
#endif
						sndStereo,
						(SndStreamVariableBufferCallback)sndCallback,
						&_sound,
						8192
#ifdef PALMOS_68K
						,false
#endif
						);

			e = e ? e : SndStreamStart(_sound.handle);
			e = e ? e :	SndStreamSetVolume(_sound.handle, (32767L / 16) * gVars->palmVolume / 100);
			success = (e == errNone);
		}
	}
	// if not true some scenes (indy3 256,...) may freeze (ESC to skip)
	return true;
}

void OSystem_PalmOS5::clearSoundCallback() {
	if (_sound.active) {
		if (1 || OPTIONS_TST(kOptPalmSoundAPI)) {
			SndStreamStop(_sound.handle);
			SndStreamDelete(_sound.handle);
		}
	}
	
	_sound.active = false;
	_sound.handle = NULL;
}