aboutsummaryrefslogtreecommitdiff
path: root/backends/PalmOS/Src/palmsnd.cpp
diff options
context:
space:
mode:
authorChris Apers2004-05-25 14:16:33 +0000
committerChris Apers2004-05-25 14:16:33 +0000
commitb9d56f4424e2ed30c3644c0fb8cff0f0b0eccc5e (patch)
treeaf3524be5c662bb9b13c663ec20a073b93fce410 /backends/PalmOS/Src/palmsnd.cpp
parentd08f952ca63cf3e4c72dc7c8c79ddc504247def9 (diff)
downloadscummvm-rg350-b9d56f4424e2ed30c3644c0fb8cff0f0b0eccc5e.tar.gz
scummvm-rg350-b9d56f4424e2ed30c3644c0fb8cff0f0b0eccc5e.tar.bz2
scummvm-rg350-b9d56f4424e2ed30c3644c0fb8cff0f0b0eccc5e.zip
New file, sound support using Pa1Lib (bad) and Palm API
svn-id: r13880
Diffstat (limited to 'backends/PalmOS/Src/palmsnd.cpp')
-rw-r--r--backends/PalmOS/Src/palmsnd.cpp194
1 files changed, 194 insertions, 0 deletions
diff --git a/backends/PalmOS/Src/palmsnd.cpp b/backends/PalmOS/Src/palmsnd.cpp
new file mode 100644
index 0000000000..753d5b9c70
--- /dev/null
+++ b/backends/PalmOS/Src/palmsnd.cpp
@@ -0,0 +1,194 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001 Ludvig Strigeus
+ * Copyright (C) 2001-2004 The ScummVM project
+ *
+ * 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 "stdafx.h"
+#include "palm.h"
+
+#include "pa1lib.h"
+
+//#define SND_BLOCK (4096)
+#define SND_BLOCK (3072)
+
+#define ADPCM_8_KHZ 1
+#define ADPCM_MODE_NONCONTINUOUS_PB 0x01
+#define ADPCM_MODE_INTERRUPT_MODE 0x02
+
+
+int OSystem_PALMOS::getOutputSampleRate() const {
+ return 8000;
+}
+
+static void ClieSoundCallback(UInt32 UserData) {
+ SoundDataType *snd = (SoundDataType *)UserData;
+ snd->set = false;
+}
+
+bool OSystem_PALMOS::setSoundCallback(SoundProc proc, void *param) {
+ Boolean success = false;
+
+ if (!_sound.active) {
+ _sound.proc = proc;
+ _sound.param = param;
+ _sound.active = true; // always true when we call this function
+ _sound.dataP = NULL; // required by sound_handler
+ _sound.handle = NULL;
+
+ // try to create sound stream
+ if (OPTIONS_TST(kOptPalmSoundAPI)) {
+ void *sndFuncP;
+ Boolean isArm;
+
+ _sound.handle = MemPtrNew(sizeof(SndStreamRef));
+
+/* if (OPTIONS_TST(kOptDeviceARM)) {
+ _arm[PNO_SNDSTREAM].pnoPtr = _PnoInit(ARM_STREAMSND, &_arm[PNO_SNDSTREAM].pnoDesc);
+ sndFuncP = (void *)_PnoCall(&_arm[PNO_SNDSTREAM].pnoDesc, NULL);
+ isArm = true;
+
+ } else*/ {
+ sndFuncP = sndCallback;
+ isArm = false;
+ }
+
+ Err e = SndStreamCreateExtended(
+ (SndStreamRef *)_sound.handle,
+ sndOutput,
+ sndFormatPCM,
+ 8000,
+ sndInt16Little,
+ sndStereo,
+ (SndStreamVariableBufferCallback)sndFuncP,
+ &_sound,
+ 8192,
+ isArm);
+
+ e = e ? e : SndStreamStart(*((SndStreamRef *)_sound.handle));
+ e = e ? e : SndStreamSetVolume(*((SndStreamRef *)_sound.handle), 32767);
+
+ _sound.size = 0; // set by the callback
+ _sound.set = false;
+ _sound.wait = true;
+ success = (e == errNone);
+
+ } else if (OPTIONS_TST(kOptSonyPa1LibAPI)) {
+ static CallbackInfoType cbData;
+ _sound.handle = MemPtrNew(sizeof(UInt8));
+
+ cbData.funcP = &ClieSoundCallback;
+ cbData.dwUserData = (UInt32)&_sound;
+
+ _sound.size = SND_BLOCK;
+ _sound.set = false;
+ _sound.wait = true;
+ _sound.dataP = MemPtrNew(SND_BLOCK);
+ _sound.tmpP = MemPtrNew(SND_BLOCK / 8);
+
+ success = true; // don't generate samples
+
+ Pa1Lib_adpcmOpen(ADPCM_8_KHZ, (UInt8 *)_sound.tmpP, MemPtrSize(_sound.tmpP), &cbData, (UInt8 *)_sound.handle);
+ }
+ // failed or not supported
+ if (!success) {
+ _sound.size = SND_BLOCK;
+ _sound.set = false;
+ _sound.wait = false;
+ success = false; // don't generate samples
+ }
+ }
+
+ return true; // if not true some scenes (indy3 256,...) may freeze (ESC to skip)
+}
+
+void OSystem_PALMOS::clearSoundCallback() {
+ if (_sound.active) {
+
+ if (OPTIONS_TST(kOptPalmSoundAPI)) {
+ SndStreamStop(*((SndStreamRef *)_sound.handle));
+ SndStreamDelete(*((SndStreamRef *)_sound.handle));
+
+ if (_arm[PNO_SNDSTREAM].pnoPtr)
+ _PnoFree(&_arm[PNO_SNDSTREAM].pnoDesc, _arm[PNO_SNDSTREAM].pnoPtr);
+ }
+
+ free(_sound.dataP);
+ free(_sound.tmpP);
+ free(_sound.handle);
+ }
+
+
+ _sound.active = false;
+ _sound.dataP = NULL;
+ _sound.tmpP = NULL;
+ _sound.handle = NULL;
+}
+
+void OSystem_PALMOS::sound_handler() {
+ if (_sound.active) {
+ if (_sound.size && (!_sound.set || !_sound.wait)) {
+
+ if (!_sound.dataP)
+ _sound.dataP = MemPtrNew(_sound.size);
+
+ ((SoundProc)_sound.proc)(_sound.param, (byte *)_sound.dataP, _sound.size);
+
+ if (OPTIONS_TST(kOptSonyPa1LibAPI)) {
+ pcm2adpcm((Int16 *)_sound.dataP, (UInt8 *)_sound.tmpP, _sound.size);
+ _sound.set = Pa1Lib_adpcmStart(*((UInt8 *)_sound.handle), ADPCM_MODE_NONCONTINUOUS_PB|ADPCM_MODE_INTERRUPT_MODE);
+ } else {
+ _sound.set = true;
+ }
+ }
+ }
+}
+
+bool OSystem_PALMOS::openCD(int drive) {
+ // TODO : add a function to CDAudio to init the MP3 driver (?)
+ return false;
+}
+
+void OSystem_PALMOS::stop_cdrom() {
+ if (!_cdPlayer)
+ return;
+
+ _cdPlayer->stop();
+}
+
+void OSystem_PALMOS::play_cdrom(int track, int num_loops, int start_frame, int duration) {
+ if (!_cdPlayer)
+ return;
+
+ _cdPlayer->play(track, num_loops, start_frame, duration);
+}
+
+bool OSystem_PALMOS::poll_cdrom() {
+ if (!_cdPlayer)
+ return false;
+
+ return _cdPlayer->poll();
+}
+
+void OSystem_PALMOS::update_cdrom() {
+ if (!_cdPlayer)
+ return;
+
+ _cdPlayer->update();
+}