aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/wii/osystem_sfx.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2008-06-04 20:28:20 +0000
committerEugene Sandulenko2008-06-04 20:28:20 +0000
commit5e666ef774d11d030ea9957ecc64a197de2abcd8 (patch)
tree0d7e9e8c78dd31c25127f7498c2e2955641ceefa /backends/platform/wii/osystem_sfx.cpp
parent1869141f0448621b19ab25d3ca338a134500a049 (diff)
downloadscummvm-rg350-5e666ef774d11d030ea9957ecc64a197de2abcd8.tar.gz
scummvm-rg350-5e666ef774d11d030ea9957ecc64a197de2abcd8.tar.bz2
scummvm-rg350-5e666ef774d11d030ea9957ecc64a197de2abcd8.zip
Patch #1971285: "Nintendo Wii port"
svn-id: r32547
Diffstat (limited to 'backends/platform/wii/osystem_sfx.cpp')
-rw-r--r--backends/platform/wii/osystem_sfx.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/backends/platform/wii/osystem_sfx.cpp b/backends/platform/wii/osystem_sfx.cpp
new file mode 100644
index 0000000000..16b2f3b055
--- /dev/null
+++ b/backends/platform/wii/osystem_sfx.cpp
@@ -0,0 +1,133 @@
+/* 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.
+ */
+
+#include <malloc.h>
+
+#include "osystem.h"
+
+#define SFX_THREAD_STACKSIZE (1024 * 128)
+#define SFX_THREAD_PRIO 80
+#define SFX_THREAD_FRAG_SIZE 4096
+
+static lwpq_t sfx_queue;
+static lwp_t sfx_thread;
+static u8 *sfx_stack;
+static bool sfx_thread_running = false;
+static bool sfx_thread_quit = false;
+
+static u8 sb = 0;
+static u8 *sound_buffer[2];
+
+static OSystem_Wii::SoundProc sound_proc = NULL;
+static void *proc_param = NULL;
+
+static void audio_switch_buffers() {
+ AUDIO_StopDMA();
+ AUDIO_InitDMA((u32) sound_buffer[sb], SFX_THREAD_FRAG_SIZE);
+ AUDIO_StartDMA();
+
+ LWP_ThreadSignal(sfx_queue);
+}
+
+static void * sfx_thread_func(void *arg) {
+ u8 next_sb;
+
+ while (true) {
+ LWP_ThreadSleep(sfx_queue);
+
+ if (sfx_thread_quit)
+ break;
+
+ next_sb = sb ^ 1;
+ sound_proc(proc_param, sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE);
+ DCFlushRange(sound_buffer[next_sb], SFX_THREAD_FRAG_SIZE);
+
+ sb = next_sb;
+ }
+
+ return NULL;
+}
+
+void OSystem_Wii::initSfx() {
+ sfx_thread_running = false;
+ sfx_thread_quit = false;
+
+ sfx_stack = (u8 *) memalign(32, SFX_THREAD_STACKSIZE);
+ memset(sfx_stack, 0, SFX_THREAD_STACKSIZE);
+
+ LWP_InitQueue(&sfx_queue);
+
+ s32 res = LWP_CreateThread(&sfx_thread, sfx_thread_func, NULL, sfx_stack,
+ SFX_THREAD_STACKSIZE, SFX_THREAD_PRIO);
+
+ if (res) {
+ printf("ERROR creating sfx thread: %d\n", res);
+ LWP_CloseQueue(sfx_queue);
+ return;
+ }
+
+ sfx_thread_running = true;
+
+ sound_buffer[0] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE);
+ sound_buffer[1] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE);
+
+ memset(sound_buffer[0], 0, SFX_THREAD_FRAG_SIZE);
+ memset(sound_buffer[1], 0, SFX_THREAD_FRAG_SIZE);
+
+ DCFlushRange(sound_buffer[0], SFX_THREAD_FRAG_SIZE);
+ DCFlushRange(sound_buffer[1], SFX_THREAD_FRAG_SIZE);
+
+ sound_proc = Audio::Mixer::mixCallback;
+ proc_param = _mixer;
+
+ _mixer->setReady(true);
+
+ AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
+ AUDIO_RegisterDMACallback(audio_switch_buffers);
+
+ audio_switch_buffers();
+}
+
+void OSystem_Wii::deinitSfx() {
+ if (_mixer)
+ _mixer->setReady(false);
+
+ AUDIO_StopDMA();
+ AUDIO_RegisterDMACallback(NULL);
+
+ if (sfx_thread_running) {
+ sfx_thread_quit = true;
+ LWP_ThreadBroadcast(sfx_queue);
+
+ LWP_JoinThread(sfx_thread, NULL);
+ LWP_CloseQueue(sfx_queue);
+
+ sfx_thread_running = false;
+
+ free(sound_buffer[0]);
+ free(sound_buffer[1]);
+ }
+}
+
+int OSystem_Wii::getOutputSampleRate() const {
+ return 48000;
+}
+