summaryrefslogtreecommitdiff
path: root/pcsound/pcsound_win32.c
diff options
context:
space:
mode:
authorSimon Howard2007-03-09 22:50:48 +0000
committerSimon Howard2007-03-09 22:50:48 +0000
commitd4056662a4c70bf2817d470694a3506bb35f0b7f (patch)
tree1c7d971df1f0d28bf6a57d8cb4ff77c2b405f2b5 /pcsound/pcsound_win32.c
parent7ebeb39398f0e7fbdda6393ef2a251b0f2a42f54 (diff)
downloadchocolate-doom-d4056662a4c70bf2817d470694a3506bb35f0b7f.tar.gz
chocolate-doom-d4056662a4c70bf2817d470694a3506bb35f0b7f.tar.bz2
chocolate-doom-d4056662a4c70bf2817d470694a3506bb35f0b7f.zip
Move the pcsound library to the top level, alongside textscreen.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 849
Diffstat (limited to 'pcsound/pcsound_win32.c')
-rw-r--r--pcsound/pcsound_win32.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/pcsound/pcsound_win32.c b/pcsound/pcsound_win32.c
new file mode 100644
index 00000000..090c0bbd
--- /dev/null
+++ b/pcsound/pcsound_win32.c
@@ -0,0 +1,115 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 2007 Simon Howard
+//
+// 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.
+//
+// DESCRIPTION:
+// PC speaker interface.
+//
+//-----------------------------------------------------------------------------
+
+#ifdef _WIN32
+
+#include <SDL.h>
+#include <windows.h>
+
+#include "pcsound.h"
+
+static SDL_Thread *sound_thread_handle;
+static int sound_thread_running;
+static pcsound_callback_func callback;
+
+static int SoundThread(void *unused)
+{
+ int frequency;
+ int duration;
+
+ while (sound_thread_running)
+ {
+ callback(&duration, &frequency);
+
+ if (frequency != 0)
+ {
+ Beep(frequency, duration);
+ }
+ else
+ {
+ Sleep(duration);
+ }
+ }
+
+ return 0;
+}
+
+static int PCSound_Win32_Init(pcsound_callback_func callback_func)
+{
+ OSVERSIONINFO osvi;
+ BOOL result;
+
+ // Temporarily disabled - the Windows scheduler is strange and
+ // stupid.
+
+ return 0;
+
+ // Find the OS version
+
+ osvi.dwOSVersionInfoSize = sizeof(osvi);
+
+ result = GetVersionEx(&osvi);
+
+ if (!result)
+ {
+ return 0;
+ }
+
+ // Beep() ignores its arguments on win9x, so this driver will
+ // not work there.
+
+ if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
+ {
+ // TODO: Use _out() to write directly to the PC speaker on
+ // win9x: See PC/winsound.c in the Python standard library.
+
+ return 0;
+ }
+
+ // Start a thread to play sound.
+
+ callback = callback_func;
+ sound_thread_running = 1;
+
+ sound_thread_handle = SDL_CreateThread(SoundThread, NULL);
+
+ return 1;
+}
+
+static void PCSound_Win32_Shutdown(void)
+{
+ sound_thread_running = 0;
+ SDL_WaitThread(sound_thread_handle, NULL);
+}
+
+pcsound_driver_t pcsound_win32_driver =
+{
+ "Windows",
+ PCSound_Win32_Init,
+ PCSound_Win32_Shutdown,
+};
+
+#endif /* #ifdef _WIN32 */
+