From ac2329020de30416484a59f41e1156439d143b87 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Wed, 29 Dec 2010 01:42:20 +0300 Subject: [PATCH] Prepare to cleanup sound emission --- Source/Game.cpp | 7 +------ Source/Globals.cpp | 1 - Source/Sounds.cpp | 12 ++++++++++++ Source/Sounds.h | 2 ++ Source/openal_wrapper.cpp | 11 +++++++++++ Source/openal_wrapper.h | 2 ++ 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index d68ee11..0751da0 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -218,12 +218,7 @@ typedef struct { } params_thread; void Game::fireSound(int sound) { - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - PlaySoundEx( sound, samp[sound], NULL, true); - OPENAL_3D_SetAttributes(channels[sound], gLoc, vel); - OPENAL_SetVolume(channels[sound], 256); - OPENAL_SetPaused(channels[sound], false); + emit_sound_at(sound); } void Game::inputText(char* str, int* charselected, int* nb_chars) { diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 30065b4..901ac1a 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -39,7 +39,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Animation.h" bool visibleloading = 0; -int channels[100] = {0}; float volume = 0; bool ismotionblur = 0; diff --git a/Source/Sounds.cpp b/Source/Sounds.cpp index c82f42e..9cedebc 100644 --- a/Source/Sounds.cpp +++ b/Source/Sounds.cpp @@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "Quaternions.h" #include "Sounds.h" #include "openal_wrapper.h" @@ -26,6 +27,8 @@ struct OPENAL_SAMPLE *samp[sounds_count]; int footstepsound, footstepsound2, footstepsound3, footstepsound4; +int channels[100]; + static const char *sound_data[sounds_count] = { #define DECLARE_SOUND(id, filename) filename, #include "Sounds.def" @@ -70,3 +73,12 @@ void loadAllSounds() OPENAL_Stream_SetMode(samp[i], OPENAL_LOOP_NORMAL); } +void +emit_sound_at(int soundid, const XYZ &pos, float vol) +{ + PlaySoundEx (soundid, samp[soundid], NULL, true); + OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL); + OPENAL_SetVolume (channels[soundid], vol); + OPENAL_SetPaused (channels[soundid], false); +} + diff --git a/Source/Sounds.h b/Source/Sounds.h index 8feac33..12d3660 100644 --- a/Source/Sounds.h +++ b/Source/Sounds.h @@ -33,5 +33,7 @@ extern struct OPENAL_SAMPLE *samp[sounds_count]; extern void loadAllSounds(); +extern void emit_sound_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f); + extern int footstepsound, footstepsound2, footstepsound3, footstepsound4; #endif diff --git a/Source/openal_wrapper.cpp b/Source/openal_wrapper.cpp index c3849a8..3d9021f 100644 --- a/Source/openal_wrapper.cpp +++ b/Source/openal_wrapper.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include "Quaternions.h" #include "openal_wrapper.h" #include "Sounds.h" @@ -186,6 +187,16 @@ AL_API signed char OPENAL_3D_SetAttributes(int channel, const float *pos, const return true; } +AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ &pos, const float *vel) +{ + if (!initialized) return false; + if ((channel < 0) || (channel >= num_channels)) return false; + + set_channel_position(channel, pos.x, pos.y, -pos.z); + + return true; +} + AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags) { if (initialized) return false; diff --git a/Source/openal_wrapper.h b/Source/openal_wrapper.h index 9f9c41b..5f2280b 100644 --- a/Source/openal_wrapper.h +++ b/Source/openal_wrapper.h @@ -70,6 +70,7 @@ extern "C" { AL_API void OPENAL_3D_Listener_SetAttributes(const float *pos, const float *vel, float fx, float fy, float fz, float tx, float ty, float tz); AL_API signed char OPENAL_3D_SetAttributes(int channel, const float *pos, const float *vel); +AL_API signed char OPENAL_3D_SetAttributes_(int channel, const XYZ &pos, const float *vel); AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags); AL_API void OPENAL_Close(); AL_API OPENAL_SAMPLE *OPENAL_Sample_Load(int index, const char *name_or_data, unsigned int mode, int offset, int length); @@ -83,6 +84,7 @@ AL_API void OPENAL_Stream_Close(OPENAL_STREAM *stream); AL_API signed char OPENAL_Stream_SetMode(OPENAL_STREAM *stream, unsigned int mode); AL_API void OPENAL_Update(); AL_API signed char OPENAL_SetOutput(int outputtype); +void PlaySoundEx(int chan, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); #ifdef __cplusplus } -- 2.39.2