Permalink
Browse files

Added missing snd_system

  • Loading branch information...
1 parent 5c0838f commit b4044e18db9366724c747a8c658061ae6ac73643 @TheDushan committed Aug 28, 2012
View
188 src/engine/snd_system/libmumblelink.cpp
@@ -0,0 +1,188 @@
+/* libmumblelink.c -- mumble link interface
+
+ Copyright (C) 2008 Ludwig Nussel <ludwig.nussel@suse.de>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+*/
+
+#ifdef WIN32
+#include <windows.h>
+#define uint32_t UINT32
+#else
+#include <unistd.h>
+#ifdef __sun
+#define _POSIX_C_SOURCE 199309L
+#endif
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#endif
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "libmumblelink.h"
+
+#ifndef MIN
+#define MIN(a, b) ((a)<(b)?(a):(b))
+#endif
+
+typedef struct
+{
+ uint32_t uiVersion;
+ uint32_t uiTick;
+ float fAvatarPosition[3];
+ float fAvatarFront[3];
+ float fAvatarTop[3];
+ wchar_t name[256];
+ /* new in mumble 1.2 */
+ float fCameraPosition[3];
+ float fCameraFront[3];
+ float fCameraTop[3];
+ wchar_t identity[256];
+ uint32_t context_len;
+ unsigned char context[256];
+ wchar_t description[2048];
+} LinkedMem;
+
+static LinkedMem *lm = NULL;
+
+#ifdef WIN32
+static HANDLE hMapObject = NULL;
+#else
+static int32_t GetTickCount(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+
+ return tv.tv_usec / 1000 + tv.tv_sec * 1000;
+}
+#endif
+
+int mumble_link(const char* name)
+{
+#ifdef WIN32
+ if(lm)
+ return 0;
+
+ hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
+ if (hMapObject == NULL)
+ return -1;
+
+ lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkedMem));
+ if (lm == NULL) {
+ CloseHandle(hMapObject);
+ hMapObject = NULL;
+ return -1;
+ }
+#else
+ char file[256];
+ int shmfd;
+ if(lm)
+ return 0;
+
+ snprintf(file, sizeof (file), "/MumbleLink.%d", getuid());
+ shmfd = shm_open(file, O_RDWR, S_IRUSR | S_IWUSR);
+ if(shmfd < 0) {
+ return -1;
+ }
+
+ lm = (LinkedMem *) (mmap(NULL, sizeof(LinkedMem), PROT_READ | PROT_WRITE, MAP_SHARED, shmfd,0));
+ if (lm == (void *) (-1)) {
+ lm = NULL;
+ close(shmfd);
+ return -1;
+ }
+ close(shmfd);
+#endif
+ memset(lm, 0, sizeof(LinkedMem));
+ mbstowcs(lm->name, name, sizeof(lm->name) / sizeof(wchar_t));
+
+ return 0;
+}
+
+void mumble_update_coordinates(float fPosition[3], float fFront[3], float fTop[3])
+{
+ mumble_update_coordinates2(fPosition, fFront, fTop, fPosition, fFront, fTop);
+}
+
+void mumble_update_coordinates2(float fAvatarPosition[3], float fAvatarFront[3], float fAvatarTop[3],
+ float fCameraPosition[3], float fCameraFront[3], float fCameraTop[3])
+{
+ if (!lm)
+ return;
+
+ memcpy(lm->fAvatarPosition, fAvatarPosition, sizeof(lm->fAvatarPosition));
+ memcpy(lm->fAvatarFront, fAvatarFront, sizeof(lm->fAvatarFront));
+ memcpy(lm->fAvatarTop, fAvatarTop, sizeof(lm->fAvatarTop));
+ memcpy(lm->fCameraPosition, fCameraPosition, sizeof(lm->fCameraPosition));
+ memcpy(lm->fCameraFront, fCameraFront, sizeof(lm->fCameraFront));
+ memcpy(lm->fCameraTop, fCameraTop, sizeof(lm->fCameraTop));
+ lm->uiVersion = 2;
+ lm->uiTick = GetTickCount();
+}
+
+void mumble_set_identity(const char* identity)
+{
+ size_t len;
+ if (!lm)
+ return;
+ len = MIN(sizeof(lm->identity), strlen(identity)+1);
+ mbstowcs(lm->identity, identity, len);
+}
+
+void mumble_set_context(const unsigned char* context, UINT32 len)
+{
+ if (!lm)
+ return;
+ len = MIN(sizeof(lm->context), len);
+ lm->context_len = len;
+ memcpy(lm->context, context, len);
+}
+
+void mumble_set_description(const char* description)
+{
+ size_t len;
+ if (!lm)
+ return;
+ len = MIN(sizeof(lm->description), strlen(description)+1);
+ mbstowcs(lm->description, description, len);
+}
+
+void mumble_unlink()
+{
+ if(!lm)
+ return;
+#ifdef WIN32
+ UnmapViewOfFile(lm);
+ CloseHandle(hMapObject);
+ hMapObject = NULL;
+#else
+ munmap(lm, sizeof(LinkedMem));
+#endif
+ lm = NULL;
+}
+
+int mumble_islinked(void)
+{
+ return lm != NULL;
+}
View
35 src/engine/snd_system/libmumblelink.h
@@ -0,0 +1,35 @@
+/* libmumblelink.h -- mumble link interface
+
+ Copyright (C) 2008 Ludwig Nussel <ludwig.nussel@suse.de>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+*/
+
+int mumble_link(const char* name);
+int mumble_islinked(void);
+void mumble_update_coordinates(float fPosition[3], float fFront[3], float fTop[3]);
+
+/* new for mumble 1.2: also set camera position */
+void mumble_update_coordinates2(float fAvatarPosition[3], float fAvatarFront[3], float fAvatarTop[3],
+ float fCameraPosition[3], float fCameraFront[3], float fCameraTop[3]);
+
+void mumble_set_description(const char* description);
+void mumble_set_context(const unsigned char* context, size_t len);
+void mumble_set_identity(const char* identity);
+
+void mumble_unlink(void);
View
336 src/engine/snd_system/qal.cpp
@@ -0,0 +1,336 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+// Dynamically loads OpenAL
+
+#ifdef USE_OPENAL
+
+#include "qal.h"
+
+#ifdef USE_OPENAL_DLOPEN
+
+#include "../sys/sys_loadlib.h"
+
+LPALENABLE qalEnable;
+LPALDISABLE qalDisable;
+LPALISENABLED qalIsEnabled;
+LPALGETSTRING qalGetString;
+LPALGETBOOLEANV qalGetBooleanv;
+LPALGETINTEGERV qalGetIntegerv;
+LPALGETFLOATV qalGetFloatv;
+LPALGETDOUBLEV qalGetDoublev;
+LPALGETBOOLEAN qalGetBoolean;
+LPALGETINTEGER qalGetInteger;
+LPALGETFLOAT qalGetFloat;
+LPALGETDOUBLE qalGetDouble;
+LPALGETERROR qalGetError;
+LPALISEXTENSIONPRESENT qalIsExtensionPresent;
+LPALGETPROCADDRESS qalGetProcAddress;
+LPALGETENUMVALUE qalGetEnumValue;
+LPALLISTENERF qalListenerf;
+LPALLISTENER3F qalListener3f;
+LPALLISTENERFV qalListenerfv;
+LPALLISTENERI qalListeneri;
+LPALGETLISTENERF qalGetListenerf;
+LPALGETLISTENER3F qalGetListener3f;
+LPALGETLISTENERFV qalGetListenerfv;
+LPALGETLISTENERI qalGetListeneri;
+LPALGENSOURCES qalGenSources;
+LPALDELETESOURCES qalDeleteSources;
+LPALISSOURCE qalIsSource;
+LPALSOURCEF qalSourcef;
+LPALSOURCE3F qalSource3f;
+LPALSOURCEFV qalSourcefv;
+LPALSOURCEI qalSourcei;
+LPALGETSOURCEF qalGetSourcef;
+LPALGETSOURCE3F qalGetSource3f;
+LPALGETSOURCEFV qalGetSourcefv;
+LPALGETSOURCEI qalGetSourcei;
+LPALSOURCEPLAYV qalSourcePlayv;
+LPALSOURCESTOPV qalSourceStopv;
+LPALSOURCEREWINDV qalSourceRewindv;
+LPALSOURCEPAUSEV qalSourcePausev;
+LPALSOURCEPLAY qalSourcePlay;
+LPALSOURCESTOP qalSourceStop;
+LPALSOURCEREWIND qalSourceRewind;
+LPALSOURCEPAUSE qalSourcePause;
+LPALSOURCEQUEUEBUFFERS qalSourceQueueBuffers;
+LPALSOURCEUNQUEUEBUFFERS qalSourceUnqueueBuffers;
+LPALGENBUFFERS qalGenBuffers;
+LPALDELETEBUFFERS qalDeleteBuffers;
+LPALISBUFFER qalIsBuffer;
+LPALBUFFERDATA qalBufferData;
+LPALGETBUFFERF qalGetBufferf;
+LPALGETBUFFERI qalGetBufferi;
+LPALDOPPLERFACTOR qalDopplerFactor;
+LPALDOPPLERVELOCITY qalDopplerVelocity;
+LPALDISTANCEMODEL qalDistanceModel;
+
+LPALCCREATECONTEXT qalcCreateContext;
+LPALCMAKECONTEXTCURRENT qalcMakeContextCurrent;
+LPALCPROCESSCONTEXT qalcProcessContext;
+LPALCSUSPENDCONTEXT qalcSuspendContext;
+LPALCDESTROYCONTEXT qalcDestroyContext;
+LPALCGETCURRENTCONTEXT qalcGetCurrentContext;
+LPALCGETCONTEXTSDEVICE qalcGetContextsDevice;
+LPALCOPENDEVICE qalcOpenDevice;
+LPALCCLOSEDEVICE qalcCloseDevice;
+LPALCGETERROR qalcGetError;
+LPALCISEXTENSIONPRESENT qalcIsExtensionPresent;
+LPALCGETPROCADDRESS qalcGetProcAddress;
+LPALCGETENUMVALUE qalcGetEnumValue;
+LPALCGETSTRING qalcGetString;
+LPALCGETINTEGERV qalcGetIntegerv;
+LPALCCAPTUREOPENDEVICE qalcCaptureOpenDevice;
+LPALCCAPTURECLOSEDEVICE qalcCaptureCloseDevice;
+LPALCCAPTURESTART qalcCaptureStart;
+LPALCCAPTURESTOP qalcCaptureStop;
+LPALCCAPTURESAMPLES qalcCaptureSamples;
+
+static void *OpenALLib = NULL;
+
+static qboolean alinit_fail = qfalse;
+
+/*
+=================
+GPA
+=================
+*/
+static void *GPA(char *str)
+{
+ void *rv;
+
+ rv = Sys_LoadFunction(OpenALLib, str);
+ if(!rv)
+ {
+ Com_Printf( " Can't load symbol %s\n", str);
+ alinit_fail = qtrue;
+ return NULL;
+ }
+ else
+ {
+ Com_DPrintf( " Loaded symbol %s (%p)\n", str, rv);
+ return rv;
+ }
+}
+
+/*
+=================
+QAL_Init
+=================
+*/
+qboolean QAL_Init(const char *libname)
+{
+ if(OpenALLib)
+ return qtrue;
+
+ if(!(OpenALLib = Sys_LoadDll(libname, qtrue)))
+ return qfalse;
+
+ alinit_fail = qfalse;
+
+ qalEnable = GPA("alEnable");
+ qalDisable = GPA("alDisable");
+ qalIsEnabled = GPA("alIsEnabled");
+ qalGetString = GPA("alGetString");
+ qalGetBooleanv = GPA("alGetBooleanv");
+ qalGetIntegerv = GPA("alGetIntegerv");
+ qalGetFloatv = GPA("alGetFloatv");
+ qalGetDoublev = GPA("alGetDoublev");
+ qalGetBoolean = GPA("alGetBoolean");
+ qalGetInteger = GPA("alGetInteger");
+ qalGetFloat = GPA("alGetFloat");
+ qalGetDouble = GPA("alGetDouble");
+ qalGetError = GPA("alGetError");
+ qalIsExtensionPresent = GPA("alIsExtensionPresent");
+ qalGetProcAddress = GPA("alGetProcAddress");
+ qalGetEnumValue = GPA("alGetEnumValue");
+ qalListenerf = GPA("alListenerf");
+ qalListener3f = GPA("alListener3f");
+ qalListenerfv = GPA("alListenerfv");
+ qalListeneri = GPA("alListeneri");
+ qalGetListenerf = GPA("alGetListenerf");
+ qalGetListener3f = GPA("alGetListener3f");
+ qalGetListenerfv = GPA("alGetListenerfv");
+ qalGetListeneri = GPA("alGetListeneri");
+ qalGenSources = GPA("alGenSources");
+ qalDeleteSources = GPA("alDeleteSources");
+ qalIsSource = GPA("alIsSource");
+ qalSourcef = GPA("alSourcef");
+ qalSource3f = GPA("alSource3f");
+ qalSourcefv = GPA("alSourcefv");
+ qalSourcei = GPA("alSourcei");
+ qalGetSourcef = GPA("alGetSourcef");
+ qalGetSource3f = GPA("alGetSource3f");
+ qalGetSourcefv = GPA("alGetSourcefv");
+ qalGetSourcei = GPA("alGetSourcei");
+ qalSourcePlayv = GPA("alSourcePlayv");
+ qalSourceStopv = GPA("alSourceStopv");
+ qalSourceRewindv = GPA("alSourceRewindv");
+ qalSourcePausev = GPA("alSourcePausev");
+ qalSourcePlay = GPA("alSourcePlay");
+ qalSourceStop = GPA("alSourceStop");
+ qalSourceRewind = GPA("alSourceRewind");
+ qalSourcePause = GPA("alSourcePause");
+ qalSourceQueueBuffers = GPA("alSourceQueueBuffers");
+ qalSourceUnqueueBuffers = GPA("alSourceUnqueueBuffers");
+ qalGenBuffers = GPA("alGenBuffers");
+ qalDeleteBuffers = GPA("alDeleteBuffers");
+ qalIsBuffer = GPA("alIsBuffer");
+ qalBufferData = GPA("alBufferData");
+ qalGetBufferf = GPA("alGetBufferf");
+ qalGetBufferi = GPA("alGetBufferi");
+ qalDopplerFactor = GPA("alDopplerFactor");
+ qalDopplerVelocity = GPA("alDopplerVelocity");
+ qalDistanceModel = GPA("alDistanceModel");
+
+ qalcCreateContext = GPA("alcCreateContext");
+ qalcMakeContextCurrent = GPA("alcMakeContextCurrent");
+ qalcProcessContext = GPA("alcProcessContext");
+ qalcSuspendContext = GPA("alcSuspendContext");
+ qalcDestroyContext = GPA("alcDestroyContext");
+ qalcGetCurrentContext = GPA("alcGetCurrentContext");
+ qalcGetContextsDevice = GPA("alcGetContextsDevice");
+ qalcOpenDevice = GPA("alcOpenDevice");
+ qalcCloseDevice = GPA("alcCloseDevice");
+ qalcGetError = GPA("alcGetError");
+ qalcIsExtensionPresent = GPA("alcIsExtensionPresent");
+ qalcGetProcAddress = GPA("alcGetProcAddress");
+ qalcGetEnumValue = GPA("alcGetEnumValue");
+ qalcGetString = GPA("alcGetString");
+ qalcGetIntegerv = GPA("alcGetIntegerv");
+ qalcCaptureOpenDevice = GPA("alcCaptureOpenDevice");
+ qalcCaptureCloseDevice = GPA("alcCaptureCloseDevice");
+ qalcCaptureStart = GPA("alcCaptureStart");
+ qalcCaptureStop = GPA("alcCaptureStop");
+ qalcCaptureSamples = GPA("alcCaptureSamples");
+
+ if(alinit_fail)
+ {
+ QAL_Shutdown();
+ Com_Printf( " One or more symbols not found\n");
+ return qfalse;
+ }
+
+ return qtrue;
+}
+
+/*
+=================
+QAL_Shutdown
+=================
+*/
+void QAL_Shutdown( void )
+{
+ if(OpenALLib)
+ {
+ Sys_UnloadLibrary(OpenALLib);
+ OpenALLib = NULL;
+ }
+
+ qalEnable = NULL;
+ qalDisable = NULL;
+ qalIsEnabled = NULL;
+ qalGetString = NULL;
+ qalGetBooleanv = NULL;
+ qalGetIntegerv = NULL;
+ qalGetFloatv = NULL;
+ qalGetDoublev = NULL;
+ qalGetBoolean = NULL;
+ qalGetInteger = NULL;
+ qalGetFloat = NULL;
+ qalGetDouble = NULL;
+ qalGetError = NULL;
+ qalIsExtensionPresent = NULL;
+ qalGetProcAddress = NULL;
+ qalGetEnumValue = NULL;
+ qalListenerf = NULL;
+ qalListener3f = NULL;
+ qalListenerfv = NULL;
+ qalListeneri = NULL;
+ qalGetListenerf = NULL;
+ qalGetListener3f = NULL;
+ qalGetListenerfv = NULL;
+ qalGetListeneri = NULL;
+ qalGenSources = NULL;
+ qalDeleteSources = NULL;
+ qalIsSource = NULL;
+ qalSourcef = NULL;
+ qalSource3f = NULL;
+ qalSourcefv = NULL;
+ qalSourcei = NULL;
+ qalGetSourcef = NULL;
+ qalGetSource3f = NULL;
+ qalGetSourcefv = NULL;
+ qalGetSourcei = NULL;
+ qalSourcePlayv = NULL;
+ qalSourceStopv = NULL;
+ qalSourceRewindv = NULL;
+ qalSourcePausev = NULL;
+ qalSourcePlay = NULL;
+ qalSourceStop = NULL;
+ qalSourceRewind = NULL;
+ qalSourcePause = NULL;
+ qalSourceQueueBuffers = NULL;
+ qalSourceUnqueueBuffers = NULL;
+ qalGenBuffers = NULL;
+ qalDeleteBuffers = NULL;
+ qalIsBuffer = NULL;
+ qalBufferData = NULL;
+ qalGetBufferf = NULL;
+ qalGetBufferi = NULL;
+ qalDopplerFactor = NULL;
+ qalDopplerVelocity = NULL;
+ qalDistanceModel = NULL;
+
+ qalcCreateContext = NULL;
+ qalcMakeContextCurrent = NULL;
+ qalcProcessContext = NULL;
+ qalcSuspendContext = NULL;
+ qalcDestroyContext = NULL;
+ qalcGetCurrentContext = NULL;
+ qalcGetContextsDevice = NULL;
+ qalcOpenDevice = NULL;
+ qalcCloseDevice = NULL;
+ qalcGetError = NULL;
+ qalcIsExtensionPresent = NULL;
+ qalcGetProcAddress = NULL;
+ qalcGetEnumValue = NULL;
+ qalcGetString = NULL;
+ qalcGetIntegerv = NULL;
+ qalcCaptureOpenDevice = NULL;
+ qalcCaptureCloseDevice = NULL;
+ qalcCaptureStart = NULL;
+ qalcCaptureStop = NULL;
+ qalcCaptureSamples = NULL;
+}
+#else
+qboolean QAL_Init(const char *libname)
+{
+ return qtrue;
+}
+void QAL_Shutdown( void )
+{
+}
+#endif
+#endif
View
252 src/engine/snd_system/qal.h
@@ -0,0 +1,252 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+
+#ifndef __QAL_H__
+#define __QAL_H__
+
+#include "../qcommon/q_shared.h"
+#include "../qcommon/qcommon.h"
+
+#ifdef USE_OPENAL_DLOPEN
+#define AL_NO_PROTOTYPES
+#define ALC_NO_PROTOTYPES
+#endif
+
+#ifdef USE_LOCAL_HEADERS
+#include "../AL/al.h"
+#include "../AL/alc.h"
+#else
+#ifdef _MSC_VER
+ // MSVC users must install the OpenAL SDK which doesn't use the AL/*.h scheme.
+ #include <al.h>
+ #include <alc.h>
+#else
+ #include <AL/al.h>
+ #include <AL/alc.h>
+#endif
+#endif
+
+/* Hack to enable compiling both on OpenAL SDK and OpenAL-soft. */
+#ifndef ALC_ENUMERATE_ALL_EXT
+# define ALC_ENUMERATE_ALL_EXT 1
+# define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
+# define ALC_ALL_DEVICES_SPECIFIER 0x1013
+#endif
+
+#ifdef USE_OPENAL_DLOPEN
+extern LPALENABLE qalEnable;
+extern LPALDISABLE qalDisable;
+extern LPALISENABLED qalIsEnabled;
+extern LPALGETSTRING qalGetString;
+extern LPALGETBOOLEANV qalGetBooleanv;
+extern LPALGETINTEGERV qalGetIntegerv;
+extern LPALGETFLOATV qalGetFloatv;
+extern LPALGETDOUBLEV qalGetDoublev;
+extern LPALGETBOOLEAN qalGetBoolean;
+extern LPALGETINTEGER qalGetInteger;
+extern LPALGETFLOAT qalGetFloat;
+extern LPALGETDOUBLE qalGetDouble;
+extern LPALGETERROR qalGetError;
+extern LPALISEXTENSIONPRESENT qalIsExtensionPresent;
+extern LPALGETPROCADDRESS qalGetProcAddress;
+extern LPALGETENUMVALUE qalGetEnumValue;
+extern LPALLISTENERF qalListenerf;
+extern LPALLISTENER3F qalListener3f;
+extern LPALLISTENERFV qalListenerfv;
+extern LPALLISTENERI qalListeneri;
+extern LPALLISTENER3I qalListener3i;
+extern LPALLISTENERIV qalListeneriv;
+extern LPALGETLISTENERF qalGetListenerf;
+extern LPALGETLISTENER3F qalGetListener3f;
+extern LPALGETLISTENERFV qalGetListenerfv;
+extern LPALGETLISTENERI qalGetListeneri;
+extern LPALGETLISTENER3I qalGetListener3i;
+extern LPALGETLISTENERIV qalGetListeneriv;
+extern LPALGENSOURCES qalGenSources;
+extern LPALDELETESOURCES qalDeleteSources;
+extern LPALISSOURCE qalIsSource;
+extern LPALSOURCEF qalSourcef;
+extern LPALSOURCE3F qalSource3f;
+extern LPALSOURCEFV qalSourcefv;
+extern LPALSOURCEI qalSourcei;
+extern LPALSOURCE3I qalSource3i;
+extern LPALSOURCEIV qalSourceiv;
+extern LPALGETSOURCEF qalGetSourcef;
+extern LPALGETSOURCE3F qalGetSource3f;
+extern LPALGETSOURCEFV qalGetSourcefv;
+extern LPALGETSOURCEI qalGetSourcei;
+extern LPALGETSOURCE3I qalGetSource3i;
+extern LPALGETSOURCEIV qalGetSourceiv;
+extern LPALSOURCEPLAYV qalSourcePlayv;
+extern LPALSOURCESTOPV qalSourceStopv;
+extern LPALSOURCEREWINDV qalSourceRewindv;
+extern LPALSOURCEPAUSEV qalSourcePausev;
+extern LPALSOURCEPLAY qalSourcePlay;
+extern LPALSOURCESTOP qalSourceStop;
+extern LPALSOURCEREWIND qalSourceRewind;
+extern LPALSOURCEPAUSE qalSourcePause;
+extern LPALSOURCEQUEUEBUFFERS qalSourceQueueBuffers;
+extern LPALSOURCEUNQUEUEBUFFERS qalSourceUnqueueBuffers;
+extern LPALGENBUFFERS qalGenBuffers;
+extern LPALDELETEBUFFERS qalDeleteBuffers;
+extern LPALISBUFFER qalIsBuffer;
+extern LPALBUFFERDATA qalBufferData;
+extern LPALBUFFERF qalBufferf;
+extern LPALBUFFER3F qalBuffer3f;
+extern LPALBUFFERFV qalBufferfv;
+extern LPALBUFFERF qalBufferi;
+extern LPALBUFFER3F qalBuffer3i;
+extern LPALBUFFERFV qalBufferiv;
+extern LPALGETBUFFERF qalGetBufferf;
+extern LPALGETBUFFER3F qalGetBuffer3f;
+extern LPALGETBUFFERFV qalGetBufferfv;
+extern LPALGETBUFFERI qalGetBufferi;
+extern LPALGETBUFFER3I qalGetBuffer3i;
+extern LPALGETBUFFERIV qalGetBufferiv;
+extern LPALDOPPLERFACTOR qalDopplerFactor;
+extern LPALDOPPLERVELOCITY qalDopplerVelocity;
+extern LPALSPEEDOFSOUND qalSpeedOfSound;
+extern LPALDISTANCEMODEL qalDistanceModel;
+
+extern LPALCCREATECONTEXT qalcCreateContext;
+extern LPALCMAKECONTEXTCURRENT qalcMakeContextCurrent;
+extern LPALCPROCESSCONTEXT qalcProcessContext;
+extern LPALCSUSPENDCONTEXT qalcSuspendContext;
+extern LPALCDESTROYCONTEXT qalcDestroyContext;
+extern LPALCGETCURRENTCONTEXT qalcGetCurrentContext;
+extern LPALCGETCONTEXTSDEVICE qalcGetContextsDevice;
+extern LPALCOPENDEVICE qalcOpenDevice;
+extern LPALCCLOSEDEVICE qalcCloseDevice;
+extern LPALCGETERROR qalcGetError;
+extern LPALCISEXTENSIONPRESENT qalcIsExtensionPresent;
+extern LPALCGETPROCADDRESS qalcGetProcAddress;
+extern LPALCGETENUMVALUE qalcGetEnumValue;
+extern LPALCGETSTRING qalcGetString;
+extern LPALCGETINTEGERV qalcGetIntegerv;
+extern LPALCCAPTUREOPENDEVICE qalcCaptureOpenDevice;
+extern LPALCCAPTURECLOSEDEVICE qalcCaptureCloseDevice;
+extern LPALCCAPTURESTART qalcCaptureStart;
+extern LPALCCAPTURESTOP qalcCaptureStop;
+extern LPALCCAPTURESAMPLES qalcCaptureSamples;
+#else
+#define qalEnable alEnable
+#define qalDisable alDisable
+#define qalIsEnabled alIsEnabled
+#define qalGetString alGetString
+#define qalGetBooleanv alGetBooleanv
+#define qalGetIntegerv alGetIntegerv
+#define qalGetFloatv alGetFloatv
+#define qalGetDoublev alGetDoublev
+#define qalGetBoolean alGetBoolean
+#define qalGetInteger alGetInteger
+#define qalGetFloat alGetFloat
+#define qalGetDouble alGetDouble
+#define qalGetError alGetError
+#define qalIsExtensionPresent alIsExtensionPresent
+#define qalGetProcAddress alGetProcAddress
+#define qalGetEnumValue alGetEnumValue
+#define qalListenerf alListenerf
+#define qalListener3f alListener3f
+#define qalListenerfv alListenerfv
+#define qalListeneri alListeneri
+#define qalListener3i alListener3i
+#define qalListeneriv alListeneriv
+#define qalGetListenerf alGetListenerf
+#define qalGetListener3f alGetListener3f
+#define qalGetListenerfv alGetListenerfv
+#define qalGetListeneri alGetListeneri
+#define qalGetListener3i alGetListener3i
+#define qalGetListeneriv alGetListeneriv
+#define qalGenSources alGenSources
+#define qalDeleteSources alDeleteSources
+#define qalIsSource alIsSource
+#define qalSourcef alSourcef
+#define qalSource3f alSource3f
+#define qalSourcefv alSourcefv
+#define qalSourcei alSourcei
+#define qalSource3i alSource3i
+#define qalSourceiv alSourceiv
+#define qalGetSourcef alGetSourcef
+#define qalGetSource3f alGetSource3f
+#define qalGetSourcefv alGetSourcefv
+#define qalGetSourcei alGetSourcei
+#define qalGetSource3i alGetSource3i
+#define qalGetSourceiv alGetSourceiv
+#define qalSourcePlayv alSourcePlayv
+#define qalSourceStopv alSourceStopv
+#define qalSourceRewindv alSourceRewindv
+#define qalSourcePausev alSourcePausev
+#define qalSourcePlay alSourcePlay
+#define qalSourceStop alSourceStop
+#define qalSourceRewind alSourceRewind
+#define qalSourcePause alSourcePause
+#define qalSourceQueueBuffers alSourceQueueBuffers
+#define qalSourceUnqueueBuffers alSourceUnqueueBuffers
+#define qalGenBuffers alGenBuffers
+#define qalDeleteBuffers alDeleteBuffers
+#define qalIsBuffer alIsBuffer
+#define qalBufferData alBufferData
+#define qalBufferf alBufferf
+#define qalBuffer3f alBuffer3f
+#define qalBufferfv alBufferfv
+#define qalBufferi alBufferi
+#define qalBuffer3i alBuffer3i
+#define qalBufferiv alBufferiv
+#define qalGetBufferf alGetBufferf
+#define qalGetBuffer3f alGetBuffer3f
+#define qalGetBufferfv alGetBufferfv
+#define qalGetBufferi alGetBufferi
+#define qalGetBuffer3i alGetBuffer3i
+#define qalGetBufferiv alGetBufferiv
+#define qalDopplerFactor alDopplerFactor
+#define qalDopplerVelocity alDopplerVelocity
+#define qalSpeedOfSound alSpeedOfSound
+#define qalDistanceModel alDistanceModel
+
+#define qalcCreateContext alcCreateContext
+#define qalcMakeContextCurrent alcMakeContextCurrent
+#define qalcProcessContext alcProcessContext
+#define qalcSuspendContext alcSuspendContext
+#define qalcDestroyContext alcDestroyContext
+#define qalcGetCurrentContext alcGetCurrentContext
+#define qalcGetContextsDevice alcGetContextsDevice
+#define qalcOpenDevice alcOpenDevice
+#define qalcCloseDevice alcCloseDevice
+#define qalcGetError alcGetError
+#define qalcIsExtensionPresent alcIsExtensionPresent
+#define qalcGetProcAddress alcGetProcAddress
+#define qalcGetEnumValue alcGetEnumValue
+#define qalcGetString alcGetString
+#define qalcGetIntegerv alcGetIntegerv
+#define qalcCaptureOpenDevice alcCaptureOpenDevice
+#define qalcCaptureCloseDevice alcCaptureCloseDevice
+#define qalcCaptureStart alcCaptureStart
+#define qalcCaptureStop alcCaptureStop
+#define qalcCaptureSamples alcCaptureSamples
+#endif
+
+qboolean QAL_Init(const char *libname);
+void QAL_Shutdown( void );
+
+#endif // __QAL_H__
View
330 src/engine/snd_system/snd_adpcm.cpp
@@ -0,0 +1,330 @@
+/***********************************************************
+Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The
+Netherlands.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+/*
+** Intel/DVI ADPCM coder/decoder.
+**
+** The algorithm for this coder was taken from the IMA Compatability Project
+** proceedings, Vol 2, Number 2; May 1992.
+**
+** Version 1.2, 18-Dec-92.
+*/
+
+#include "snd_local.h"
+
+
+/* Intel ADPCM step variation table */
+static int indexTable[16] = {
+ -1, -1, -1, -1, 2, 4, 6, 8,
+ -1, -1, -1, -1, 2, 4, 6, 8,
+};
+
+static int stepsizeTable[89] = {
+ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
+ 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
+ 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
+ 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
+ 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
+ 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
+ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
+ 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
+ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
+};
+
+
+void S_AdpcmEncode( short indata[], char outdata[], int len, struct adpcm_state *state ) {
+ short *inp; /* Input buffer pointer */
+ signed char *outp; /* output buffer pointer */
+ int val; /* Current input sample value */
+ int sign; /* Current adpcm sign bit */
+ int delta; /* Current adpcm output value */
+ int diff; /* Difference between val and sample */
+ int step; /* Stepsize */
+ int valpred; /* Predicted output value */
+ int vpdiff; /* Current change to valpred */
+ int index; /* Current step change index */
+ int outputbuffer; /* place to keep previous 4-bit value */
+ int bufferstep; /* toggle between outputbuffer/output */
+
+ outp = (signed char *)outdata;
+ inp = indata;
+
+ valpred = state->sample;
+ index = state->index;
+ step = stepsizeTable[index];
+
+ outputbuffer = 0; // quiet a compiler warning
+ bufferstep = 1;
+
+ for ( ; len > 0 ; len-- ) {
+ val = *inp++;
+
+ /* Step 1 - compute difference with previous value */
+ diff = val - valpred;
+ sign = (diff < 0) ? 8 : 0;
+ if ( sign ) diff = (-diff);
+
+ /* Step 2 - Divide and clamp */
+ /* Note:
+ ** This code *approximately* computes:
+ ** delta = diff*4/step;
+ ** vpdiff = (delta+0.5)*step/4;
+ ** but in shift step bits are dropped. The net result of this is
+ ** that even if you have fast mul/div hardware you cannot put it to
+ ** good use since the fixup would be too expensive.
+ */
+ delta = 0;
+ vpdiff = (step >> 3);
+
+ if ( diff >= step ) {
+ delta = 4;
+ diff -= step;
+ vpdiff += step;
+ }
+ step >>= 1;
+ if ( diff >= step ) {
+ delta |= 2;
+ diff -= step;
+ vpdiff += step;
+ }
+ step >>= 1;
+ if ( diff >= step ) {
+ delta |= 1;
+ vpdiff += step;
+ }
+
+ /* Step 3 - Update previous value */
+ if ( sign )
+ valpred -= vpdiff;
+ else
+ valpred += vpdiff;
+
+ /* Step 4 - Clamp previous value to 16 bits */
+ if ( valpred > 32767 )
+ valpred = 32767;
+ else if ( valpred < -32768 )
+ valpred = -32768;
+
+ /* Step 5 - Assemble value, update index and step values */
+ delta |= sign;
+
+ index += indexTable[delta];
+ if ( index < 0 ) index = 0;
+ if ( index > 88 ) index = 88;
+ step = stepsizeTable[index];
+
+ /* Step 6 - Output value */
+ if ( bufferstep ) {
+ outputbuffer = (delta << 4) & 0xf0;
+ } else {
+ *outp++ = (delta & 0x0f) | outputbuffer;
+ }
+ bufferstep = !bufferstep;
+ }
+
+ /* Output last step, if needed */
+ if ( !bufferstep )
+ *outp++ = outputbuffer;
+
+ state->sample = valpred;
+ state->index = index;
+}
+
+
+/* static */ void S_AdpcmDecode( const char indata[], short *outdata, int len, struct adpcm_state *state ) {
+ signed char *inp; /* Input buffer pointer */
+ int outp; /* output buffer pointer */
+ int sign; /* Current adpcm sign bit */
+ int delta; /* Current adpcm output value */
+ int step; /* Stepsize */
+ int valpred; /* Predicted value */
+ int vpdiff; /* Current change to valpred */
+ int index; /* Current step change index */
+ int inputbuffer; /* place to keep next 4-bit value */
+ int bufferstep; /* toggle between inputbuffer/input */
+
+ outp = 0;
+ inp = (signed char *)indata;
+
+ valpred = state->sample;
+ index = state->index;
+ step = stepsizeTable[index];
+
+ bufferstep = 0;
+ inputbuffer = 0; // quiet a compiler warning
+ for ( ; len > 0 ; len-- ) {
+
+ /* Step 1 - get the delta value */
+ if ( bufferstep ) {
+ delta = inputbuffer & 0xf;
+ } else {
+ inputbuffer = *inp++;
+ delta = (inputbuffer >> 4) & 0xf;
+ }
+ bufferstep = !bufferstep;
+
+ /* Step 2 - Find new index value (for later) */
+ index += indexTable[delta];
+ if ( index < 0 ) index = 0;
+ if ( index > 88 ) index = 88;
+
+ /* Step 3 - Separate sign and magnitude */
+ sign = delta & 8;
+ delta = delta & 7;
+
+ /* Step 4 - Compute difference and new predicted value */
+ /*
+ ** Computes 'vpdiff = (delta+0.5)*step/4', but see comment
+ ** in adpcm_coder.
+ */
+ vpdiff = step >> 3;
+ if ( delta & 4 ) vpdiff += step;
+ if ( delta & 2 ) vpdiff += step>>1;
+ if ( delta & 1 ) vpdiff += step>>2;
+
+ if ( sign )
+ valpred -= vpdiff;
+ else
+ valpred += vpdiff;
+
+ /* Step 5 - clamp output value */
+ if ( valpred > 32767 )
+ valpred = 32767;
+ else if ( valpred < -32768 )
+ valpred = -32768;
+
+ /* Step 6 - Update step value */
+ step = stepsizeTable[index];
+
+ /* Step 7 - Output value */
+ outdata[outp] = valpred;
+ outp++;
+ }
+
+ state->sample = valpred;
+ state->index = index;
+}
+
+
+/*
+====================
+S_AdpcmMemoryNeeded
+
+Returns the amount of memory (in bytes) needed to store the samples in out internal adpcm format
+====================
+*/
+int S_AdpcmMemoryNeeded( const wavinfo_t *info ) {
+ float scale;
+ int scaledSampleCount;
+ int sampleMemory;
+ int blockCount;
+ int headerMemory;
+
+ // determine scale to convert from input sampling rate to desired sampling rate
+ scale = (float)info->rate / dma.speed;
+
+ // calc number of samples at playback sampling rate
+ scaledSampleCount = info->samples / scale;
+
+ // calc memory need to store those samples using ADPCM at 4 bits per sample
+ sampleMemory = scaledSampleCount / 2;
+
+ // calc number of sample blocks needed of PAINTBUFFER_SIZE
+ blockCount = scaledSampleCount / PAINTBUFFER_SIZE;
+ if( scaledSampleCount % PAINTBUFFER_SIZE ) {
+ blockCount++;
+ }
+
+ // calc memory needed to store the block headers
+ headerMemory = blockCount * sizeof(adpcm_state_t);
+
+ return sampleMemory + headerMemory;
+}
+
+
+/*
+====================
+S_AdpcmGetSamples
+====================
+*/
+void S_AdpcmGetSamples(sndBuffer *chunk, short *to) {
+ adpcm_state_t state;
+ byte *out;
+
+ // get the starting state from the block header
+ state.index = chunk->adpcm.index;
+ state.sample = chunk->adpcm.sample;
+
+ out = (byte *)chunk->sndChunk;
+ // get samples
+ S_AdpcmDecode((char *) out, to, SND_CHUNK_SIZE_BYTE*2, &state );
+}
+
+
+/*
+====================
+S_AdpcmEncodeSound
+====================
+*/
+void S_AdpcmEncodeSound( sfx_t *sfx, short *samples ) {
+ adpcm_state_t state;
+ int inOffset;
+ int count;
+ int n;
+ sndBuffer *newchunk, *chunk;
+ byte *out;
+
+ inOffset = 0;
+ count = sfx->soundLength;
+ state.index = 0;
+ state.sample = samples[0];
+
+ chunk = NULL;
+ while( count ) {
+ n = count;
+ if( n > SND_CHUNK_SIZE_BYTE*2 ) {
+ n = SND_CHUNK_SIZE_BYTE*2;
+ }
+
+ newchunk = SND_malloc();
+ if (sfx->soundData == NULL) {
+ sfx->soundData = newchunk;
+ } else {
+ chunk->next = newchunk;
+ }
+ chunk = newchunk;
+
+ // output the header
+ chunk->adpcm.index = state.index;
+ chunk->adpcm.sample = state.sample;
+
+ out = (byte *)chunk->sndChunk;
+
+ // encode the samples
+ S_AdpcmEncode( samples + inOffset, (char *) out, n, &state );
+
+ inOffset += n;
+ count -= n;
+ }
+}
View
259 src/engine/snd_system/snd_codec.cpp
@@ -0,0 +1,259 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+#include "../client/client.h"
+#include "snd_codec.h"
+
+static snd_codec_t *codecs;
+
+/*
+=================
+S_FileExtension
+=================
+*/
+char *S_FileExtension(const char *fni)
+{
+ // we should search from the ending to the last '/'
+
+ char *fn = (char *)fni + strlen(fni) - 1;
+ char *eptr = NULL;
+
+ while(*fn != '/' && fn != fni)
+ {
+ if(*fn == '.')
+ {
+ eptr = fn;
+ break;
+ }
+ fn--;
+ }
+
+ return eptr;
+}
+
+
+/*
+=================
+S_CodecGetSound
+
+Opens/loads a sound, tries codec based on the sound's file extension
+then tries all supported codecs.
+=================
+*/
+static void *S_CodecGetSound(const char *filename, snd_info_t *info)
+{
+ snd_codec_t *codec;
+ snd_codec_t *orgCodec = NULL;
+ qboolean orgNameFailed = qfalse;
+ char localName[ MAX_QPATH ];
+ const char *ext;
+ char altName[ MAX_QPATH ];
+ void *rtn = NULL;
+
+ Q_strncpyz(localName, filename, MAX_QPATH);
+
+ ext = COM_GetExtension(localName);
+
+ if( *ext )
+ {
+ // Look for the correct loader and use it
+ for( codec = codecs; codec; codec = codec->next )
+ {
+ if( !Q_stricmp( ext, codec->ext ) )
+ {
+ // Load
+ if( info )
+ rtn = codec->load(localName, info);
+ else
+ rtn = codec->open(localName);
+ break;
+ }
+ }
+
+ // A loader was found
+ if( codec )
+ {
+ if( !rtn )
+ {
+ // Loader failed, most likely because the file isn't there;
+ // try again without the extension
+ orgNameFailed = qtrue;
+ orgCodec = codec;
+ COM_StripExtension2( filename, localName, MAX_QPATH );
+ }
+ else
+ {
+ // Something loaded
+ return rtn;
+ }
+ }
+ }
+
+ // Try and find a suitable match using all
+ // the sound codecs supported
+ for( codec = codecs; codec; codec = codec->next )
+ {
+ if( codec == orgCodec )
+ continue;
+
+ Com_sprintf( altName, sizeof (altName), "%s.%s", localName, codec->ext );
+
+ // Load
+ if( info )
+ rtn = codec->load(altName, info);
+ else
+ rtn = codec->open(altName);
+
+ if( rtn )
+ {
+ if( orgNameFailed )
+ {
+ Com_DPrintf(S_COLOR_YELLOW "WARNING: %s not present, using %s instead\n",
+ filename, altName );
+ }
+
+ return rtn;
+ }
+ }
+
+ Com_Printf(S_COLOR_YELLOW "WARNING: Failed to %s sound %s!\n", info ? "load" : "open", filename);
+
+ return NULL;
+}
+
+/*
+=================
+S_CodecInit
+=================
+*/
+void S_CodecInit()
+{
+ codecs = NULL;
+
+#ifdef USE_CODEC_VORBIS
+ S_CodecRegister(&ogg_codec);
+#endif
+
+// Register wav codec last so that it is always tried first when a file extension was not found
+ S_CodecRegister(&wav_codec);
+}
+
+/*
+=================
+S_CodecShutdown
+=================
+*/
+void S_CodecShutdown()
+{
+ codecs = NULL;
+}
+
+/*
+=================
+S_CodecRegister
+=================
+*/
+void S_CodecRegister(snd_codec_t *codec)
+{
+ codec->next = codecs;
+ codecs = codec;
+}
+
+/*
+=================
+S_CodecLoad
+=================
+*/
+void *S_CodecLoad(const char *filename, snd_info_t *info)
+{
+ return S_CodecGetSound(filename, info);
+}
+
+/*
+=================
+S_CodecOpenStream
+=================
+*/
+snd_stream_t *S_CodecOpenStream(const char *filename)
+{
+ return (snd_stream_t*)S_CodecGetSound(filename, NULL);
+}
+
+void S_CodecCloseStream(snd_stream_t *stream)
+{
+ stream->codec->close(stream);
+}
+
+int S_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
+{
+ return stream->codec->read(stream, bytes, buffer);
+}
+
+//=======================================================================
+// Util functions (used by codecs)
+
+/*
+=================
+S_CodecUtilOpen
+=================
+*/
+snd_stream_t *S_CodecUtilOpen(const char *filename, snd_codec_t *codec)
+{
+ snd_stream_t *stream;
+ fileHandle_t hnd;
+ int length;
+
+ // Try to open the file
+ length = FS_FOpenFileRead(filename, &hnd, qtrue);
+ if(!hnd)
+ {
+ Com_DPrintf("Can't read sound file %s\n", filename);
+ return NULL;
+ }
+
+ // Allocate a stream
+ stream = (snd_stream_t*)Z_Malloc(sizeof(snd_stream_t));
+ if(!stream)
+ {
+ FS_FCloseFile(hnd);
+ return NULL;
+ }
+
+ // Copy over, return
+ stream->codec = codec;
+ stream->file = hnd;
+ stream->length = length;
+ return stream;
+}
+
+/*
+=================
+S_CodecUtilClose
+=================
+*/
+void S_CodecUtilClose(snd_stream_t **stream)
+{
+ FS_FCloseFile((*stream)->file);
+ Z_Free(*stream);
+ *stream = NULL;
+}
View
98 src/engine/snd_system/snd_codec.h
@@ -0,0 +1,98 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+#ifndef _SND_CODEC_H_
+#define _SND_CODEC_H_
+
+#include "../qcommon/q_shared.h"
+#include "../qcommon/qcommon.h"
+
+typedef struct snd_info_s
+{
+ int rate;
+ int width;
+ int channels;
+ int samples;
+ int size;
+ int dataofs;
+} snd_info_t;
+
+typedef struct snd_codec_s snd_codec_t;
+
+typedef struct snd_stream_s
+{
+ snd_codec_t *codec;
+ fileHandle_t file;
+ snd_info_t info;
+ int length;
+ int pos;
+ void *ptr;
+} snd_stream_t;
+
+// Codec functions
+typedef void *(*CODEC_LOAD)(const char *filename, snd_info_t *info);
+typedef snd_stream_t *(*CODEC_OPEN)(const char *filename);
+typedef int (*CODEC_READ)(snd_stream_t *stream, int bytes, void *buffer);
+typedef void (*CODEC_CLOSE)(snd_stream_t *stream);
+
+// Codec data structure
+struct snd_codec_s
+{
+ char *ext;
+ CODEC_LOAD load;
+ CODEC_OPEN open;
+ CODEC_READ read;
+ CODEC_CLOSE close;
+ snd_codec_t *next;
+};
+
+// Codec management
+void S_CodecInit( void );
+void S_CodecShutdown( void );
+void S_CodecRegister(snd_codec_t *codec);
+void *S_CodecLoad(const char *filename, snd_info_t *info);
+snd_stream_t *S_CodecOpenStream(const char *filename);
+void S_CodecCloseStream(snd_stream_t *stream);
+int S_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer);
+
+// Util functions (used by codecs)
+snd_stream_t *S_CodecUtilOpen(const char *filename, snd_codec_t *codec);
+void S_CodecUtilClose(snd_stream_t **stream);
+
+// WAV Codec
+extern snd_codec_t wav_codec;
+void *S_WAV_CodecLoad(const char *filename, snd_info_t *info);
+snd_stream_t *S_WAV_CodecOpenStream(const char *filename);
+void S_WAV_CodecCloseStream(snd_stream_t *stream);
+int S_WAV_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer);
+
+// Ogg Vorbis codec
+#ifdef USE_CODEC_VORBIS
+extern snd_codec_t ogg_codec;
+void *S_OGG_CodecLoad(const char *filename, snd_info_t *info);
+snd_stream_t *S_OGG_CodecOpenStream(const char *filename);
+void S_OGG_CodecCloseStream(snd_stream_t *stream);
+int S_OGG_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer);
+#endif // USE_CODEC_VORBIS
+
+#endif // !_SND_CODEC_H_
View
478 src/engine/snd_system/snd_codec_ogg.cpp
@@ -0,0 +1,478 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
+Copyright (C) 2005-2006 Joerg Dietrich <dietrich_joerg@gmx.de>
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+// OGG support is enabled by this define
+#ifdef USE_CODEC_VORBIS
+
+// includes for the Q3 sound system
+#include "../client/client.h"
+#include "snd_codec.h"
+
+// includes for the OGG codec
+#include <errno.h>
+#define OV_EXCLUDE_STATIC_CALLBACKS
+#include <vorbis/vorbisfile.h>
+
+// The OGG codec can return the samples in a number of different formats,
+// we use the standard signed short format.
+#define OGG_SAMPLEWIDTH 2
+
+// Q3 OGG codec
+snd_codec_t ogg_codec =
+{
+ "ogg",
+ S_OGG_CodecLoad,
+ S_OGG_CodecOpenStream,
+ S_OGG_CodecReadStream,
+ S_OGG_CodecCloseStream,
+ NULL
+};
+
+// callbacks for vobisfile
+
+// fread() replacement
+size_t S_OGG_Callback_read(void *ptr, size_t size, size_t nmemb, void *datasource)
+{
+ snd_stream_t *stream;
+ int byteSize = 0;
+ int bytesRead = 0;
+ size_t nMembRead = 0;
+
+ // check if input is valid
+ if(!ptr)
+ {
+ errno = EFAULT;
+ return 0;
+ }
+
+ if(!(size && nmemb))
+ {
+ // It's not an error, caller just wants zero bytes!
+ errno = 0;
+ return 0;
+ }
+
+ if(!datasource)
+ {
+ errno = EBADF;
+ return 0;
+ }
+
+ // we use a snd_stream_t in the generic pointer to pass around
+ stream = (snd_stream_t *) datasource;
+
+ // FS_Read does not support multi-byte elements
+ byteSize = nmemb * size;
+
+ // read it with the Q3 function FS_Read()
+ bytesRead = FS_Read(ptr, byteSize, stream->file);
+
+ // update the file position
+ stream->pos += bytesRead;
+
+ // this function returns the number of elements read not the number of bytes
+ nMembRead = bytesRead / size;
+
+ // even if the last member is only read partially
+ // it is counted as a whole in the return value
+ if(bytesRead % size)
+ {
+ nMembRead++;
+ }
+
+ return nMembRead;
+}
+
+// fseek() replacement
+int S_OGG_Callback_seek(void *datasource, ogg_int64_t offset, int whence)
+{
+ snd_stream_t *stream;
+ int retVal = 0;
+
+ // check if input is valid
+ if(!datasource)
+ {
+ errno = EBADF;
+ return -1;
+ }
+
+ // snd_stream_t in the generic pointer
+ stream = (snd_stream_t *) datasource;
+
+ // we must map the whence to its Q3 counterpart
+ switch(whence)
+ {
+ case SEEK_SET :
+ {
+ // set the file position in the actual file with the Q3 function
+ retVal = FS_Seek(stream->file, (long) offset, FS_SEEK_SET);
+
+ // something has gone wrong, so we return here
+ if(retVal < 0)
+ {
+ return retVal;
+ }
+
+ // keep track of file position
+ stream->pos = (int) offset;
+ break;
+ }
+
+ case SEEK_CUR :
+ {
+ // set the file position in the actual file with the Q3 function
+ retVal = FS_Seek(stream->file, (long) offset, FS_SEEK_CUR);
+
+ // something has gone wrong, so we return here
+ if(retVal < 0)
+ {
+ return retVal;
+ }
+
+ // keep track of file position
+ stream->pos += (int) offset;
+ break;
+ }
+
+ case SEEK_END :
+ {
+ // Quake 3 seems to have trouble with FS_SEEK_END
+ // so we use the file length and FS_SEEK_SET
+
+ // set the file position in the actual file with the Q3 function
+ retVal = FS_Seek(stream->file, (long) stream->length + (long) offset, FS_SEEK_SET);
+
+ // something has gone wrong, so we return here
+ if(retVal < 0)
+ {
+ return retVal;
+ }
+
+ // keep track of file position
+ stream->pos = stream->length + (int) offset;
+ break;
+ }
+
+ default :
+ {
+ // unknown whence, so we return an error
+ errno = EINVAL;
+ return -1;
+ }
+ }
+
+ // stream->pos shouldn't be smaller than zero or bigger than the filesize
+ stream->pos = (stream->pos < 0) ? 0 : stream->pos;
+ stream->pos = (stream->pos > stream->length) ? stream->length : stream->pos;
+
+ return 0;
+}
+
+// fclose() replacement
+int S_OGG_Callback_close(void *datasource)
+{
+ // we do nothing here and close all things manually in S_OGG_CodecCloseStream()
+ return 0;
+}
+
+// ftell() replacement
+long S_OGG_Callback_tell(void *datasource)
+{
+ snd_stream_t *stream;
+
+ // check if input is valid
+ if(!datasource)
+ {
+ errno = EBADF;
+ return -1;
+ }
+
+ // snd_stream_t in the generic pointer
+ stream = (snd_stream_t *) datasource;
+
+ return (long) FS_FTell(stream->file);
+}
+
+// the callback structure
+const ov_callbacks S_OGG_Callbacks =
+{
+ &S_OGG_Callback_read,
+ &S_OGG_Callback_seek,
+ &S_OGG_Callback_close,
+ &S_OGG_Callback_tell
+};
+
+/*
+=================
+S_OGG_CodecOpenStream
+=================
+*/
+snd_stream_t *S_OGG_CodecOpenStream(const char *filename)
+{
+ snd_stream_t *stream;
+
+ // OGG codec control structure
+ OggVorbis_File *vf;
+
+ // some variables used to get informations about the OGG
+ vorbis_info *OGGInfo;
+ ogg_int64_t numSamples;
+
+ // check if input is valid
+ if(!filename)
+ {
+ return NULL;
+ }
+
+ // Open the stream
+ stream = S_CodecUtilOpen(filename, &ogg_codec);
+ if(!stream)
+ {
+ return NULL;
+ }
+
+ // alloctate the OggVorbis_File
+ vf = (OggVorbis_File*)Z_Malloc(sizeof(OggVorbis_File));
+ if(!vf)
+ {
+ S_CodecUtilClose(&stream);
+
+ return NULL;
+ }
+
+ // open the codec with our callbacks and stream as the generic pointer
+ if(ov_open_callbacks(stream, vf, NULL, 0, S_OGG_Callbacks) != 0)
+ {
+ Z_Free(vf);
+
+ S_CodecUtilClose(&stream);
+
+ return NULL;
+ }
+
+ // the stream must be seekable
+ if(!ov_seekable(vf))
+ {
+ ov_clear(vf);
+
+ Z_Free(vf);
+
+ S_CodecUtilClose(&stream);
+
+ return NULL;
+ }
+
+ // we only support OGGs with one substream
+ if(ov_streams(vf) != 1)
+ {
+ ov_clear(vf);
+
+ Z_Free(vf);
+
+ S_CodecUtilClose(&stream);
+
+ return NULL;
+ }
+
+ // get the info about channels and rate
+ OGGInfo = ov_info(vf, 0);
+ if(!OGGInfo)
+ {
+ ov_clear(vf);
+
+ Z_Free(vf);
+
+ S_CodecUtilClose(&stream);
+
+ return NULL;
+ }
+
+ // get the number of sample-frames in the OGG
+ numSamples = ov_pcm_total(vf, 0);
+
+ // fill in the info-structure in the stream
+ stream->info.rate = OGGInfo->rate;
+ stream->info.width = OGG_SAMPLEWIDTH;
+ stream->info.channels = OGGInfo->channels;
+ stream->info.samples = numSamples;
+ stream->info.size = stream->info.samples * stream->info.channels * stream->info.width;
+ stream->info.dataofs = 0;
+
+ // We use stream->pos for the file pointer in the compressed ogg file
+ stream->pos = 0;
+
+ // We use the generic pointer in stream for the OGG codec control structure
+ stream->ptr = vf;
+
+ return stream;
+}
+
+/*
+=================
+S_OGG_CodecCloseStream
+=================
+*/
+void S_OGG_CodecCloseStream(snd_stream_t *stream)
+{
+ // check if input is valid
+ if(!stream)
+ {
+ return;
+ }
+
+ // let the OGG codec cleanup its stuff
+ ov_clear((OggVorbis_File *) stream->ptr);
+
+ // free the OGG codec control struct
+ Z_Free(stream->ptr);
+
+ // close the stream
+ S_CodecUtilClose(&stream);
+}
+
+/*
+=================
+S_OGG_CodecReadStream
+=================
+*/
+int S_OGG_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
+{
+ // buffer handling
+ int bytesRead, bytesLeft, c;
+ char *bufPtr;
+
+ // Bitstream for the decoder
+ int BS = 0;
+
+ // big endian machines want their samples in big endian order
+ int IsBigEndian = 0;
+
+# ifdef Q3_BIG_ENDIAN
+ IsBigEndian = 1;
+# endif // Q3_BIG_ENDIAN
+
+ // check if input is valid
+ if(!(stream && buffer))
+ {
+ return 0;
+ }
+
+ if(bytes <= 0)
+ {
+ return 0;
+ }
+
+ bytesRead = 0;
+ bytesLeft = bytes;
+ bufPtr = (char*)buffer;
+
+ // cycle until we have the requested or all available bytes read
+ while(-1)
+ {
+ // read some bytes from the OGG codec
+ c = ov_read((OggVorbis_File *) stream->ptr, bufPtr, bytesLeft, IsBigEndian, OGG_SAMPLEWIDTH, 1, &BS);
+
+ // no more bytes are left
+ if(c <= 0)
+ {
+ break;
+ }
+
+ bytesRead += c;
+ bytesLeft -= c;
+ bufPtr += c;
+
+ // we have enough bytes
+ if(bytesLeft <= 0)
+ {
+ break;
+ }
+ }
+
+ return bytesRead;
+}
+
+/*
+=====================================================================
+S_OGG_CodecLoad
+
+We handle S_OGG_CodecLoad as a special case of the streaming functions
+where we read the whole stream at once.
+======================================================================
+*/
+void *S_OGG_CodecLoad(const char *filename, snd_info_t *info)
+{
+ snd_stream_t *stream;
+ byte *buffer;
+ int bytesRead;
+
+ // check if input is valid
+ if(!(filename && info))
+ {
+ return NULL;
+ }
+
+ // open the file as a stream
+ stream = S_OGG_CodecOpenStream(filename);
+ if(!stream)
+ {
+ return NULL;
+ }
+
+ // copy over the info
+ info->rate = stream->info.rate;
+ info->width = stream->info.width;
+ info->channels = stream->info.channels;
+ info->samples = stream->info.samples;
+ info->size = stream->info.size;
+ info->dataofs = stream->info.dataofs;
+
+ // allocate a buffer
+ // this buffer must be free-ed by the caller of this function
+ buffer = (byte*)Hunk_AllocateTempMemory(info->size);
+ if(!buffer)
+ {
+ S_OGG_CodecCloseStream(stream);
+
+ return NULL;
+ }
+
+ // fill the buffer
+ bytesRead = S_OGG_CodecReadStream(stream, info->size, buffer);
+
+ // we don't even have read a single byte
+ if(bytesRead <= 0)
+ {
+ Hunk_FreeTempMemory(buffer);
+ S_OGG_CodecCloseStream(stream);
+
+ return NULL;
+ }
+
+ S_OGG_CodecCloseStream(stream);
+
+ return buffer;
+}
+
+#endif // USE_CODEC_VORBIS
View
291 src/engine/snd_system/snd_codec_wav.cpp
@@ -0,0 +1,291 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+Copyright (C) 2005 Stuart Dalton (badcdev@gmail.com)
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+#include "../client/client.h"
+#include "snd_codec.h"
+
+/*
+=================
+FGetLittleLong
+=================
+*/
+static int FGetLittleLong( fileHandle_t f ) {
+ int v;
+
+ FS_Read( &v, sizeof(v), f );
+
+ return LittleLong( v);
+}
+
+/*
+=================
+FGetLittleShort
+=================
+*/
+static short FGetLittleShort( fileHandle_t f ) {
+ short v;
+
+ FS_Read( &v, sizeof(v), f );
+
+ return LittleShort( v);
+}
+
+/*
+=================
+S_ReadChunkInfo
+=================
+*/
+static int S_ReadChunkInfo(fileHandle_t f, char *name)
+{
+ int len, r;
+
+ name[4] = 0;
+
+ r = FS_Read(name, 4, f);
+ if(r != 4)
+ return -1;
+
+ len = FGetLittleLong(f);
+ if( len < 0 ) {
+ Com_Printf( S_COLOR_YELLOW "WARNING: Negative chunk length\n" );
+ return -1;
+ }
+
+ return len;
+}
+
+/*
+=================
+S_FindRIFFChunk
+
+Returns the length of the data in the chunk, or -1 if not found
+=================
+*/
+static int S_FindRIFFChunk( fileHandle_t f, char *chunk ) {
+ char name[5];
+ int len;
+
+ while( ( len = S_ReadChunkInfo(f, name) ) >= 0 )
+ {
+ // If this is the right chunk, return
+ if( !Q_strncmp( name, chunk, 4 ) )
+ return len;
+
+ len = PAD( len, 2 );
+
+ // Not the right chunk - skip it
+ FS_Seek( f, len, FS_SEEK_CUR );
+ }
+
+ return -1;
+}
+
+/*
+=================
+S_ByteSwapRawSamples
+=================
+*/
+static void S_ByteSwapRawSamples( int samples, int width, int s_channels, const byte *data ) {
+ int i;
+
+ if ( width != 2 ) {
+ return;
+ }
+ if ( LittleShort( 256 ) == 256 ) {
+ return;
+ }
+
+ if ( s_channels == 2 ) {
+ samples <<= 1;
+ }
+ for ( i = 0 ; i < samples ; i++ ) {
+ ((short *)data)[i] = LittleShort( ((short *)data)[i] );
+ }
+}
+
+/*
+=================
+S_ReadRIFFHeader
+=================
+*/
+static qboolean S_ReadRIFFHeader(fileHandle_t file, snd_info_t *info)
+{
+ char dump[16];
+ int bits;
+ int fmtlen = 0;
+
+ // skip the riff wav header
+ FS_Read(dump, 12, file);
+
+ // Scan for the format chunk
+ if((fmtlen = S_FindRIFFChunk(file, "fmt ")) < 0)
+ {
+ Com_Printf( S_COLOR_RED "ERROR: Couldn't find \"fmt\" chunk\n");
+ return qfalse;
+ }
+
+ // Save the parameters
+ FGetLittleShort(file); // wav_format
+ info->channels = FGetLittleShort(file);
+ info->rate = FGetLittleLong(file);
+ FGetLittleLong(file);
+ FGetLittleShort(file);
+ bits = FGetLittleShort(file);
+
+ if( bits < 8 )
+ {
+ Com_Printf( S_COLOR_RED "ERROR: Less than 8 bit sound is not supported\n");
+ return qfalse;
+ }
+
+ info->width = bits / 8;
+ info->dataofs = 0;
+
+ // Skip the rest of the format chunk if required
+ if(fmtlen > 16)
+ {
+ fmtlen -= 16;
+ FS_Seek( file, fmtlen, FS_SEEK_CUR );
+ }
+
+ // Scan for the data chunk
+ if( (info->size = S_FindRIFFChunk(file, "data")) < 0)
+ {
+ Com_Printf( S_COLOR_RED "ERROR: Couldn't find \"data\" chunk\n");
+ return qfalse;
+ }
+ info->samples = (info->size / info->width) / info->channels;
+
+ return qtrue;
+}
+
+// WAV codec
+snd_codec_t wav_codec =
+{
+ "wav",
+ S_WAV_CodecLoad,
+ S_WAV_CodecOpenStream,
+ S_WAV_CodecReadStream,
+ S_WAV_CodecCloseStream,
+ NULL
+};
+
+/*
+=================
+S_WAV_CodecLoad
+=================
+*/
+void *S_WAV_CodecLoad(const char *filename, snd_info_t *info)
+{
+ fileHandle_t file;
+ void *buffer;
+
+ // Try to open the file
+ FS_FOpenFileRead(filename, &file, qtrue);
+ if(!file)
+ {
+ return NULL;
+ }
+
+ // Read the RIFF header
+ if(!S_ReadRIFFHeader(file, info))
+ {
+ FS_FCloseFile(file);
+ Com_Printf( S_COLOR_RED "ERROR: Incorrect/unsupported format in \"%s\"\n",
+ filename);
+ return NULL;
+ }
+
+ // Allocate some memory
+ buffer = Hunk_AllocateTempMemory(info->size);
+ if(!buffer)
+ {
+ FS_FCloseFile(file);
+ Com_Printf( S_COLOR_RED "ERROR: Out of memory reading \"%s\"\n",
+ filename);
+ return NULL;
+ }
+
+ // Read, byteswap
+ FS_Read(buffer, info->size, file);
+ S_ByteSwapRawSamples(info->samples, info->width, info->channels, (byte *)buffer);
+
+ // Close and return
+ FS_FCloseFile(file);
+ return buffer;
+}
+
+/*
+=================
+S_WAV_CodecOpenStream
+=================
+*/
+snd_stream_t *S_WAV_CodecOpenStream(const char *filename)
+{
+ snd_stream_t *rv;
+
+ // Open
+ rv = S_CodecUtilOpen(filename, &wav_codec);
+ if(!rv)
+ return NULL;
+
+ // Read the RIFF header
+ if(!S_ReadRIFFHeader(rv->file, &rv->info))
+ {
+ S_CodecUtilClose(&rv);
+ return NULL;
+ }
+
+ return rv;
+}
+
+/*
+=================
+S_WAV_CodecCloseStream
+=================
+*/
+void S_WAV_CodecCloseStream(snd_stream_t *stream)
+{
+ S_CodecUtilClose(&stream);
+}
+
+/*
+=================
+S_WAV_CodecReadStream
+=================
+*/
+int S_WAV_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
+{
+ int remaining = stream->info.size - stream->pos;
+ int samples;
+
+ if(remaining <= 0)
+ return 0;
+ if(bytes > remaining)
+ bytes = remaining;
+ stream->pos += bytes;
+ samples = (bytes / stream->info.width) / stream->info.channels;
+ FS_Read(buffer, bytes, stream->file);
+ S_ByteSwapRawSamples(samples, stream->info.width, stream->info.channels, (byte*)buffer);
+ return bytes;
+}
View
1,746 src/engine/snd_system/snd_dma.cpp
@@ -0,0 +1,1746 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+
+This file is part of OpenWolf source code.
+
+OpenWolf source code 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.
+
+OpenWolf source code 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 OpenWolf source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+===========================================================================
+*/
+
+/*****************************************************************************
+ * name: snd_dma.c
+ *
+ * desc: main control for any streaming sound output device
+ *
+ * $Archive: /MissionPack/code/client/snd_dma.c $
+ *
+ *****************************************************************************/
+
+#include "snd_local.h"
+#include "snd_codec.h"
+#include "../client/client.h"
+
+void S_Update_( void );
+void S_Base_StopAllSounds(void);
+void S_Base_StopBackgroundTrack( void );
+
+snd_stream_t *s_backgroundStream = NULL;
+static char s_backgroundLoop[MAX_QPATH];
+//static char s_backgroundMusic[MAX_QPATH]; //TTimo: unused
+streamingSound_t streamingSounds[MAX_STREAMING_SOUNDS];
+
+
+// =======================================================================
+// Internal sound data & structures
+// =======================================================================
+
+// only begin attenuating sound volumes when outside the FULLVOLUME range
+#define SOUND_FULLVOLUME 80
+
+#define SOUND_ATTENUATE 0.0008f
+
+channel_t s_channels[MAX_CHANNELS];
+channel_t loop_channels[MAX_CHANNELS];
+int numLoopChannels;
+
+static int s_soundStarted;
+static qboolean s_soundMuted;
+
+dma_t dma;
+
+static int listener_number;
+static vec3_t listener_origin;
+static vec3_t listener_axis[3];
+
+int s_soundtime; // sample PAIRS
+int s_paintedtime; // sample PAIRS
+
+// MAX_SFX may be larger than MAX_SOUNDS because
+// of custom player sounds
+#define MAX_SFX 4096
+sfx_t s_knownSfx[MAX_SFX];
+int s_numSfx = 0;
+
+#define LOOP_HASH 128
+static sfx_t *sfxHash[LOOP_HASH];
+
+cvar_t *s_testsound;
+cvar_t *s_show;
+cvar_t *s_mixahead;
+cvar_t *s_mixPreStep;
+
+static loopSound_t loopSounds[MAX_GENTITIES];
+static channel_t *freelist = NULL;
+
+int s_rawend[MAX_RAW_STREAMS];
+
+portable_samplepair_t s_rawsamples[MAX_RAW_STREAMS][MAX_RAW_SAMPLES];
+
+
+// ====================================================================
+// User-setable variables
+// ====================================================================
+
+
+void S_Base_SoundInfo(void) {
+ Com_Printf("----- Sound Info -----\n" );
+ if (!s_soundStarted) {
+ Com_Printf ("sound system not started\n");
+ } else {
+ Com_Printf("%5d stereo\n", dma.channels - 1);
+ Com_Printf("%5d samples\n", dma.samples);
+ Com_Printf("%5d samplebits\n", dma.samplebits);
+ Com_Printf("%5d submission_chunk\n", dma.submission_chunk);
+ Com_Printf("%5d speed\n", dma.speed);
+ Com_Printf("%p dma buffer\n", dma.buffer);
+ if ( s_backgroundStream ) {
+ Com_Printf("Background file: %s\n", s_backgroundLoop );
+ } else {
+ Com_Printf("No background file.\n" );
+ }
+
+ }
+ Com_Printf("----------------------\n" );
+}
+
+
+#ifdef USE_VOIP
+static
+void S_Base_StartCapture( void )
+{
+ // !!! FIXME: write me.
+}
+
+static
+int S_Base_AvailableCaptureSamples( void )
+{
+ // !!! FIXME: write me.
+ return 0;
+}
+
+static
+void S_Base_Capture( int samples, byte *data )
+{
+ // !!! FIXME: write me.
+}
+
+static
+void S_Base_StopCapture( void )
+{
+ // !!! FIXME: write me.
+}
+
+static
+void S_Base_MasterGain( float val )
+{
+ // !!! FIXME: write me.
+}
+#endif
+
+
+
+/*
+=================
+S_Base_SoundList
+=================
+*/
+void S_Base_SoundList( void ) {
+ int i;
+ sfx_t *sfx;
+ int size, total;
+ char type[4][16];
+ char mem[2][16];
+
+ strcpy(type[0], "16bit");
+ strcpy(type[1], "adpcm");
+ strcpy(type[2], "daub4");
+ strcpy(type[3], "mulaw");
+ strcpy(mem[0], "paged out");
+ strcpy(mem[1], "resident ");
+ total = 0;
+ for (sfx=s_knownSfx, i=0 ; i<s_numSfx ; i++, sfx++) {
+ size = sfx->soundLength;
+ total += size;
+ Com_Printf("%6i[%s] : %s[%s]\n", size, type[sfx->soundCompressionMethod],
+ sfx->soundName, mem[sfx->inMemory] );
+ }
+ Com_Printf ("Total resident: %i\n", total);
+ S_DisplayFreeMemory();
+}
+
+
+
+void S_ChannelFree(channel_t *v) {
+ v->thesfx = NULL;
+ *(channel_t **)v = freelist;
+ freelist = (channel_t*)v;
+}
+
+channel_t* S_ChannelMalloc( void ) {
+ channel_t *v;
+ if (freelist == NULL) {
+ return NULL;
+ }
+ v = freelist;
+ freelist = *(channel_t **)freelist;
+ v->allocTime = Com_Milliseconds();
+ return v;
+}
+
+void S_ChannelSetup( void ) {
+ channel_t *p, *q;
+
+ // clear all the sounds so they don't
+ Com_Memset( s_channels, 0, sizeof( s_channels ) );
+
+ p = s_channels;;
+ q = p + MAX_CHANNELS;
+ while (--q > p) {
+ *(channel_t **)q = q-1;
+ }
+
+ *(channel_t **)q = NULL;
+ freelist = p + MAX_CHANNELS - 1;
+ Com_DPrintf("Channel memory manager started\n");
+}
+
+
+
+// =======================================================================
+// Load a sound
+// =======================================================================
+
+/*
+================
+return a hash value for the sfx name
+================
+*/
+static long S_HashSFXName(const char *name) {
+ int i;
+ long hash;
+ char letter;
+
+ hash = 0;
+ i = 0;
+ while (name[i] != '\0') {
+ letter = tolower(name[i]);
+ if (letter =='.') break; // don't include extension
+ if (letter =='\\') letter = '/'; // damn path names
+ hash+=(long)(letter)*(i+119);
+ i++;
+ }
+ hash &= (LOOP_HASH-1);
+ return hash;
+}
+
+/*
+==================
+S_FindName
+
+Will allocate a new sfx if it isn't found
+==================
+*/
+static sfx_t *S_FindName( const char *name ) {
+ int i;
+ int hash;
+
+ sfx_t *sfx;
+
+ if (!name) {
+ Com_Error (ERR_FATAL, "S_FindName: NULL");
+ }
+ if (!name[0]) {
+ Com_Error (ERR_FATAL, "S_FindName: empty name");
+ }
+
+ if (strlen(name) >= MAX_QPATH) {
+ Com_Error (ERR_FATAL, "Sound name too long: %s", name);
+ }
+
+ hash = S_HashSFXName(name);
+
+ sfx = sfxHash[hash];
+ // see if already loaded
+ while (sfx) {
+ if (!Q_stricmp(sfx->soundName, name) ) {
+ return sfx;
+ }
+ sfx = sfx->next;
+ }
+
+ // find a free sfx
+ for (i=0 ; i < s_numSfx ; i++) {
+ if (!s_knownSfx[i].soundName[0]) {
+ break;
+ }
+ }
+
+ if (i == s_numSfx) {
+ if (s_numSfx == MAX_SFX) {
+ Com_Error (ERR_FATAL, "S_FindName: out of sfx_t");
+ }
+ s_numSfx++;
+ }
+
+ sfx = &s_knownSfx[i];
+ Com_Memset (sfx, 0, sizeof(*sfx));
+ strcpy (sfx->soundName, name);
+
+ sfx->next = sfxHash[hash];
+ sfxHash[hash] = sfx;
+
+ return sfx;