]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Allow playing sounds with stereo effects.
authorGuus Sliepen <guus@debian.org>
Sun, 9 Aug 2015 13:54:21 +0000 (15:54 +0200)
committerGuus Sliepen <guus@debian.org>
Sun, 9 Aug 2015 13:54:21 +0000 (15:54 +0200)
This is basically a copy of the playSound routine from Project: Starfighter.

src/CAudio.cpp
src/CAudio.h

index 98d1a86babce839a9c57e859081d8c7d0061497d..e20aece8f6b935ac9cad541e5cf2df9429bd7601 100644 (file)
@@ -178,7 +178,7 @@ bool Audio::loadMusic(const char *filename)
        return true;
 }
 
-void Audio::playSound(int snd, int channel)
+void Audio::playSoundRelative(int snd, int channel, float x)
 {
        if ((!engine->useAudio) || (soundVolume == 0))
                return;
@@ -188,9 +188,29 @@ void Audio::playSound(int snd, int channel)
                return;
        }
 
-       Mix_Volume(channel, soundVolume);
+       int angle = atanf(x / 320) * 180 / M_PI;
+       int attenuation = fabsf(x) / 40;
+
+       if (angle < 0)
+               angle += 360;
 
+       if (attenuation > 255)
+               attenuation = 255;
+
+       Mix_Volume(channel, soundVolume);
        Mix_PlayChannel(channel, sound[snd], 0);
+       Mix_SetPosition(channel, angle, attenuation);
+}
+
+void Audio::playSound(int snd, int channel, float x)
+{
+       x -= (engine->playerPosX + 320);
+       playSoundRelative(snd, channel, x);
+}
+
+void Audio::playSound(int snd, int channel)
+{
+       playSoundRelative(snd, channel, 0);
 }
 
 void Audio::playMusic()
index 500455a4d0d3eb67073950ecd069614a4b6beb52..d9faa5cb72efb0c7cb28bdfb6051f93179372abb 100644 (file)
@@ -50,6 +50,8 @@ class Audio {
        void registerEngine(Engine *engine);
        bool loadSound(int i, const char *filename);
        bool loadMusic(const char *filename);
+       void playSoundRelative(int snd, int channel, float x);
+       void playSound(int snd, int channel, float x);
        void playSound(int snd, int channel);
        void playMusic();
        void playMusicOnce();