aboutsummaryrefslogtreecommitdiffstats
path: root/src/jake2/sound
diff options
context:
space:
mode:
Diffstat (limited to 'src/jake2/sound')
-rw-r--r--src/jake2/sound/DummyDriver.java111
-rw-r--r--src/jake2/sound/S.java187
-rw-r--r--src/jake2/sound/Sound.java105
-rw-r--r--src/jake2/sound/sfx_t.java49
-rw-r--r--src/jake2/sound/sfxcache_t.java37
-rw-r--r--src/jake2/sound/soundinfo_t.java19
-rw-r--r--src/jake2/sound/wavinfo_t.java19
7 files changed, 527 insertions, 0 deletions
diff --git a/src/jake2/sound/DummyDriver.java b/src/jake2/sound/DummyDriver.java
new file mode 100644
index 0000000..e663d09
--- /dev/null
+++ b/src/jake2/sound/DummyDriver.java
@@ -0,0 +1,111 @@
+/*
+ * Created on Apr 25, 2004
+ *
+ * Copyright (C) 2003
+ *
+ * $Id: DummyDriver.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+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.
+
+*/
+package jake2.sound;
+
+/**
+ * DummyDriver
+ *
+ * @author cwei
+ */
+public final class DummyDriver implements Sound {
+
+ static {
+ S.register(new DummyDriver());
+ };
+
+ private DummyDriver() {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#Init()
+ */
+ public boolean Init() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#Shutdown()
+ */
+ public void Shutdown() {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#BeginRegistration()
+ */
+ public void BeginRegistration() {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#RegisterSound(java.lang.String)
+ */
+ public sfx_t RegisterSound(String sample) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#EndRegistration()
+ */
+ public void EndRegistration() {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#StartLocalSound(java.lang.String)
+ */
+ public void StartLocalSound(String sound) {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#StartSound(float[], int, int, jake2.sound.sfx_t, float, float, float)
+ */
+ public void StartSound(float[] origin, int entnum, int entchannel, sfx_t sfx, float fvol, float attenuation, float timeofs) {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#Update(float[], float[], float[], float[])
+ */
+ public void Update(float[] origin, float[] forward, float[] right, float[] up) {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#RawSamples(int, int, int, int, byte[])
+ */
+ public void RawSamples(int samples, int rate, int width, int channels, byte[] data) {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#StopAllSounds()
+ */
+ public void StopAllSounds() {
+ }
+
+ /* (non-Javadoc)
+ * @see jake2.sound.Sound#getName()
+ */
+ public String getName() {
+ return "dummy";
+ }
+}
diff --git a/src/jake2/sound/S.java b/src/jake2/sound/S.java
new file mode 100644
index 0000000..c696501
--- /dev/null
+++ b/src/jake2/sound/S.java
@@ -0,0 +1,187 @@
+/*
+ * S.java
+ * Copyright (C) 2003
+ *
+ * $Id: S.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+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.
+
+*/
+package jake2.sound;
+
+import jake2.Defines;
+import jake2.game.cvar_t;
+import jake2.qcommon.Com;
+import jake2.qcommon.Cvar;
+
+import java.util.Vector;
+
+/**
+ * S
+ */
+public class S {
+
+ static Sound impl;
+ static cvar_t s_impl;
+
+ static Vector drivers = new Vector(3);
+
+ static {
+ try {
+ Class.forName("jake2.sound.DummyDriver");
+ Class.forName("jake2.sound.joal.JOALSoundImpl");
+ Class.forName("jake2.sound.jsound.JSoundImpl");
+ }
+ catch (ClassNotFoundException e) {
+ }
+ };
+
+ public static void register(Sound driver) {
+ if (driver == null) {
+ throw new IllegalArgumentException("Sound implementation can't be null");
+ }
+ if (!drivers.contains(driver)) {
+ drivers.add(driver);
+ }
+ }
+
+ public static void useDriver(String driverName) {
+ Sound driver = null;
+ int count = drivers.size();
+ for (int i = 0; i < count; i++) {
+ driver = (Sound) drivers.get(i);
+ if (driver.getName().equals(driverName)) {
+ impl = driver;
+ return;
+ }
+ }
+ // if driver not found use dummy
+ impl = (Sound)drivers.get(0);
+ }
+
+ public static void Init() {
+
+ Com.Printf("\n------- sound initialization -------\n");
+
+ cvar_t cv = Cvar.Get("s_initsound", "1", 0);
+ if (cv.value == 0.0f) {
+ Com.Printf("not initializing.\n");
+ useDriver("dummy");
+ return;
+ }
+
+ s_impl = Cvar.Get("s_impl", "joal", Defines.CVAR_ARCHIVE);
+ useDriver(s_impl.string);
+
+ if (impl.Init()) {
+ // driver ok
+ Cvar.Set("s_impl", impl.getName());
+ } else {
+ // fallback
+ useDriver("dummy");
+ }
+
+ Com.Printf("\n------- use sound driver \"" + impl.getName() + "\" -------\n");
+ StopAllSounds();
+ }
+
+ public static void Shutdown() {
+ impl.Shutdown();
+ }
+
+ /*
+ =====================
+ S_BeginRegistration
+ =====================
+ */
+ public static void BeginRegistration() {
+ impl.BeginRegistration();
+ }
+
+ /*
+ =====================
+ S_RegisterSound
+ =====================
+ */
+ public static sfx_t RegisterSound(String sample) {
+ return impl.RegisterSound(sample);
+ }
+
+ /*
+ =====================
+ S_EndRegistration
+ =====================
+ */
+ public static void EndRegistration() {
+ impl.EndRegistration();
+ }
+
+ /*
+ ==================
+ S_StartLocalSound
+ ==================
+ */
+ public static void StartLocalSound(String sound) {
+ impl.StartLocalSound(sound);
+ }
+
+ /*
+ ====================
+ S_StartSound
+
+ Validates the parms and ques the sound up
+ if pos is NULL, the sound will be dynamically sourced from the entity
+ Entchannel 0 will never override a playing sound
+ ====================
+ */
+ public static void StartSound(float[] origin, int entnum, int entchannel, sfx_t sfx, float fvol, float attenuation, float timeofs) {
+ impl.StartSound(origin, entnum, entchannel, sfx, fvol, attenuation, timeofs);
+ }
+
+ /*
+ ============
+ S_Update
+
+ Called once each time through the main loop
+ ============
+ */
+ public static void Update(float[] origin, float[] forward, float[] right, float[] up) {
+ impl.Update(origin, forward, right, up);
+ }
+
+ /*
+ ============
+ S_RawSamples
+
+ Cinematic streaming and voice over network
+ ============
+ */
+ public static void RawSamples(int samples, int rate, int width, int channels, byte[] data) {
+ impl.RawSamples(samples, rate, width, channels, data);
+ }
+
+ /*
+ ==================
+ S_StopAllSounds
+ ==================
+ */
+ public static void StopAllSounds() {
+ impl.StopAllSounds();
+ }
+}
diff --git a/src/jake2/sound/Sound.java b/src/jake2/sound/Sound.java
new file mode 100644
index 0000000..30bd8c6
--- /dev/null
+++ b/src/jake2/sound/Sound.java
@@ -0,0 +1,105 @@
+/*
+ * Created on Apr 25, 2004
+ *
+ * Copyright (C) 2003
+ *
+ * $Id: Sound.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+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.
+
+*/
+package jake2.sound;
+
+/**
+ * Sound
+ *
+ * @author cwei
+ */
+public interface Sound {
+
+
+ String getName();
+
+ boolean Init();
+ void Shutdown();
+
+ /*
+ =====================
+ S_BeginRegistration
+ =====================
+ */
+ void BeginRegistration();
+
+ /*
+ =====================
+ S_RegisterSound
+ =====================
+ */
+ sfx_t RegisterSound(String sample);
+
+ /*
+ =====================
+ S_EndRegistration
+ =====================
+ */
+ void EndRegistration();
+
+ /*
+ ==================
+ S_StartLocalSound
+ ==================
+ */
+ void StartLocalSound(String sound);
+
+ /*
+ ====================
+ S_StartSound
+
+ Validates the parms and ques the sound up
+ if pos is NULL, the sound will be dynamically sourced from the entity
+ Entchannel 0 will never override a playing sound
+ ====================
+ */
+ void StartSound(float[] origin, int entnum, int entchannel, sfx_t sfx, float fvol, float attenuation, float timeofs);
+
+ /*
+ ============
+ S_Update
+
+ Called once each time through the main loop
+ ============
+ */
+ void Update(float[] origin, float[] forward, float[] right, float[] up);
+ /*
+ ============
+ S_RawSamples
+
+ Cinematic streaming and voice over network
+ ============
+ */
+ void RawSamples(int samples, int rate, int width, int channels, byte[] data);
+
+ /*
+ ==================
+ S_StopAllSounds
+ ==================
+ */
+ void StopAllSounds();
+
+}
diff --git a/src/jake2/sound/sfx_t.java b/src/jake2/sound/sfx_t.java
new file mode 100644
index 0000000..992c0e7
--- /dev/null
+++ b/src/jake2/sound/sfx_t.java
@@ -0,0 +1,49 @@
+/*
+ * sfx_t.java
+ * Copyright (C) 2004
+ *
+ * $Id: sfx_t.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+ */
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+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.
+
+*/
+
+// Created on 28.11.2003 by RST.
+
+package jake2.sound;
+
+
+public class sfx_t {
+ public String name; //mem
+ public int registration_sequence;
+ public sfxcache_t cache; //ptr
+ public String truename; //ptr
+
+ // cwei
+ public int id = -1;
+
+ public void clear() {
+ name = truename = null;
+ cache = null;
+ registration_sequence = 0;
+
+ // cwei
+ id = -1;
+ }
+}
diff --git a/src/jake2/sound/sfxcache_t.java b/src/jake2/sound/sfxcache_t.java
new file mode 100644
index 0000000..7f4428a
--- /dev/null
+++ b/src/jake2/sound/sfxcache_t.java
@@ -0,0 +1,37 @@
+/*
+Copyright (C) 1997-2001 Id Software, Inc.
+
+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.
+
+*/
+
+// Created on 28.11.2003 by RST.
+// $Id: sfxcache_t.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+
+package jake2.sound;
+
+public class sfxcache_t {
+ public int length;
+ public int loopstart;
+ public int speed; // not needed, because converted on load?
+ public int width;
+ public int stereo;
+ public byte data[]; // variable sized
+
+ public sfxcache_t(int size) {
+ data = new byte[size];
+ }
+}
diff --git a/src/jake2/sound/soundinfo_t.java b/src/jake2/sound/soundinfo_t.java
new file mode 100644
index 0000000..2c9e6c6
--- /dev/null
+++ b/src/jake2/sound/soundinfo_t.java
@@ -0,0 +1,19 @@
+/*
+ * soundinfo_t.java
+ * Copyright (C) 2004
+ *
+ * $Id: soundinfo_t.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+ */
+package jake2.sound;
+
+/**
+ * soundinfo_t
+ */
+public class soundinfo_t {
+ int channels;
+ int samples; // mono samples in buffer
+ int submission_chunk; // don't mix less than this #
+ int samplepos; // in mono samples
+ int samplebits;
+ int speed;
+}
diff --git a/src/jake2/sound/wavinfo_t.java b/src/jake2/sound/wavinfo_t.java
new file mode 100644
index 0000000..76a28fc
--- /dev/null
+++ b/src/jake2/sound/wavinfo_t.java
@@ -0,0 +1,19 @@
+/*
+ * wavinfo_t.java
+ * Copyright (C) 2004
+ *
+ * $Id: wavinfo_t.java,v 1.1 2004-07-08 20:56:49 hzi Exp $
+ */
+package jake2.sound;
+
+/**
+ * wavinfo_t
+ */
+public class wavinfo_t {
+ public int rate;
+ public int width;
+ public int channels;
+ public int loopstart;
+ public int samples;
+ public int dataofs; // chunk starts this many bytes from file start
+}