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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* $URL$
* $Id$
*
*/
#include "be_os5.h"
#include "common/config-manager.h"
#include "sound/mixer_intern.h"
#ifdef PALMOS_ARM
# ifdef COMPILE_ZODIAC
# define SAMPLES_PER_SEC 44100
# else
# define SAMPLES_PER_SEC 22050
# endif
#else
# define SAMPLES_PER_SEC 8000
#endif
SoundExType _soundEx;
static Err sndCallback(void* UserDataP, SndStreamRef stream, void* bufferP, UInt32 *bufferSizeP) {
SoundExType *_soundEx = (SoundExType *)UserDataP;
SoundType *_sound = _soundEx->sound;
if (_soundEx->set && _soundEx->size) {
MemMove(bufferP, _soundEx->dataP, _soundEx->size);
*bufferSizeP = _soundEx->size;
_soundEx->set = false;
} else {
_soundEx->size = *bufferSizeP;
MemSet(bufferP, 128, 0);
*bufferSizeP = 128;
}
return errNone;
}
void OSystem_PalmOS5::sound_handler() {
if (_sound.active) {
if (_soundEx.size && !_soundEx.set) {
if (!_soundEx.dataP)
_soundEx.dataP = MemPtrNew(_soundEx.size);
_mixerMgr->mixCallback((byte *)_soundEx.dataP, _soundEx.size);
_soundEx.set = true;
}
}// TODO : no Sound API case
}
SndStreamVariableBufferCallback OSystem_PalmOS5::sound_callback() {
return sndCallback;
}
bool OSystem_PalmOS5::setupMixer() {
Err e;
Boolean success = false;
uint32 samplesPerSec;
if (ConfMan.hasKey("output_rate"))
samplesPerSec = ConfMan.getInt("output_rate");
else
samplesPerSec = SAMPLES_PER_SEC;
_mixerMgr = new Audio::MixerImpl(this, samplesPerSec);
if (!_sound.active) {
if (gVars->fmQuality != FM_QUALITY_INI) {
ConfMan.setBool("FM_medium_quality", (gVars->fmQuality == FM_QUALITY_MED));
ConfMan.setBool("FM_high_quality", (gVars->fmQuality == FM_QUALITY_HI));
}
#if defined (COMPILE_OS5)
CALLBACK_INIT(_soundEx);
#endif
_sound.proc = 0;
_sound.param = _mixerMgr;
_sound.active = true; // always true when we call this function, false when sound is off
_soundEx.handle = 0;
_soundEx.size = 0; // set by the callback
_soundEx.set = false;
_soundEx.dataP = NULL; // set by the handler
// try to create sound stream
if (OPTIONS_TST(kOptPalmSoundAPI)) {
e = SndStreamCreateExtended(
&_soundEx.handle,
sndOutput,
sndFormatPCM,
samplesPerSec,
sndInt16Little,
sndStereo,
sound_callback(),
&_soundEx,
8192
#ifdef COMPILE_OS5
,true
#endif
);
e = e ? e : SndStreamStart(_soundEx.handle);
e = e ? e : SndStreamSetVolume(_soundEx.handle, 1024L * gVars->palmVolume / 100);
success = (e == errNone);
// no Sound API
} else {
_soundEx.size = 512;
_soundEx.dataP = MemPtrNew(_soundEx.size);
}
}
// if not true some scenes (indy3 256,...) may freeze (ESC to skip)
_mixerMgr->setReady(true);
return true;
}
void OSystem_PalmOS5::clearSoundCallback() {
if (_sound.active) {
if (OPTIONS_TST(kOptPalmSoundAPI)) {
SndStreamStop(_soundEx.handle);
SndStreamDelete(_soundEx.handle);
}
if (_soundEx.dataP)
MemPtrFree(_soundEx.dataP);
}
_sound.active = false;
_soundEx.handle = NULL;
_soundEx.dataP = NULL;
}
|