diff --git a/code/aliens.cpp b/code/aliens.cpp index 31bf982..ef9df88 100644 --- a/code/aliens.cpp +++ b/code/aliens.cpp @@ -832,7 +832,7 @@ static void moveAndSeparate(object *theEnemy) theEnemy->hit = 3; theEnemy->dx *= -1; theEnemy->dy *= -1; - playSound(SFX_HIT); + playSound(SFX_HIT, theEnemy->x); } if (anEnemy->owner == anEnemy) @@ -855,10 +855,10 @@ static void moveAndSeparate(object *theEnemy) if (!engine.cheatShield) player.shield -= theEnemy->shield; theEnemy->shield = 0; - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, theEnemy->x); setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED); player.hit = 5; - playSound(SFX_HIT); + playSound(SFX_HIT, player.x); } if (theEnemy->classDef == CD_ASTEROID2) @@ -866,10 +866,10 @@ static void moveAndSeparate(object *theEnemy) if (!engine.cheatShield) player.shield -= theEnemy->shield; theEnemy->shield = 0; - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, theEnemy->x); setInfoLine("Warning: Asteroid Collision Damage!!", FONT_RED); player.hit = 5; - playSound(SFX_HIT); + playSound(SFX_HIT, player.x); } if (theEnemy->classDef == CD_BARRIER) @@ -877,7 +877,7 @@ static void moveAndSeparate(object *theEnemy) if (!engine.cheatShield) player.shield--; player.hit = 5; - playSound(SFX_HIT); + playSound(SFX_HIT, player.x); } } } @@ -1084,7 +1084,7 @@ void doAliens() theEnemy->flags -= FL_ISCLOAKED; else theEnemy->flags += FL_ISCLOAKED; - playSound(SFX_CLOAK); + playSound(SFX_CLOAK, theEnemy->x); } // ------------ Barriers ------------------ @@ -1143,7 +1143,7 @@ void doAliens() else if ((theEnemy->weaponType[1] == W_ENERGYRAY) && (theEnemy->ammo[0] == 250)) { theEnemy->flags += FL_FIRERAY; - playSound(SFX_ENERGYRAY); + playSound(SFX_ENERGYRAY, theEnemy->x); } } } diff --git a/code/audio.cpp b/code/audio.cpp index a6c5b7d..101b575 100644 --- a/code/audio.cpp +++ b/code/audio.cpp @@ -22,11 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Mix_Chunk *sound[MAX_SOUNDS]; -void playSound(int sid) +void playSound(int sid, float x) { if ((!engine.useSound) || (!engine.useAudio)) return; + int channel; + static int freechannel = 4; + switch(sid) { case SFX_DEATH: @@ -37,25 +40,45 @@ void playSound(int sid) case SFX_CLOAK: case SFX_PLASMA2: case SFX_PLASMA3: - Mix_PlayChannel(-1, sound[sid], 0); + channel = -1; break; case SFX_PLASMA: case SFX_LASER: - Mix_PlayChannel(0, sound[sid], 0); + channel = 0; break; case SFX_ENERGYRAY: case SFX_MISSILE: - Mix_PlayChannel(1, sound[sid], 0); + channel = 1; break; case SFX_HIT: - Mix_PlayChannel(4, sound[sid], 0); + channel = 2; break; case SFX_EXPLOSION: case SFX_DEBRIS: case SFX_DEBRIS2: - Mix_PlayChannel(3, sound[sid], 0); + channel = 3; break; } + + if(channel == -1) { + channel = freechannel++; + if(freechannel >= 8) + freechannel = 4; + } + + fprintf(stderr, "%d\n", channel); + + int angle = atanf((x - 400) / 400) * 180 / M_PI; + int attenuation = fabsf(x - 400) / 40; + + if(angle < 0) + angle += 360; + + if(attenuation > 255) + attenuation = 255; + + Mix_SetPosition(channel, angle, attenuation); + Mix_PlayChannel(channel, sound[sid], 0); } Mix_Chunk *loadSound(const char *filename) diff --git a/code/audio.h b/code/audio.h index df53d2a..309e205 100644 --- a/code/audio.h +++ b/code/audio.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern Mix_Chunk *sound[MAX_SOUNDS]; -extern void playSound(int sid); +extern void playSound(int sid, float x = 400); extern Mix_Chunk *loadSound(const char *filename); extern void loadMusic(const char *filename); extern void playRandomTrack(); diff --git a/code/bullets.cpp b/code/bullets.cpp index f2ea64f..c56ab03 100644 --- a/code/bullets.cpp +++ b/code/bullets.cpp @@ -157,16 +157,16 @@ void fireBullet(object *attacker, int weaponType) case WT_PLASMA: case WT_SPREAD: case WT_DIRECTIONAL: - playSound(SFX_PLASMA); + playSound(SFX_PLASMA, attacker->x); break; case WT_ROCKET: - playSound(SFX_MISSILE); + playSound(SFX_MISSILE, attacker->x); break; case WT_LASER: - playSound(SFX_LASER); + playSound(SFX_LASER, attacker->x); break; case WT_CHARGER: - playSound(SFX_PLASMA3); + playSound(SFX_PLASMA3, attacker->x); break; } @@ -272,7 +272,7 @@ Fill in later... */ static void destroyAlien(object *bullet, object *theEnemy) { - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, theEnemy->x); // Chain reaction destruction if needed if (theEnemy->flags & FL_DAMAGEOWNER) @@ -436,11 +436,11 @@ void fireRay(object *attacker) player.shield--; addExplosion(player.x, player.y, E_SMALL_EXPLOSION); - playSound(SFX_HIT); + playSound(SFX_HIT, player.x); if (player.shield < 1) { - playSound(SFX_DEATH); - playSound(SFX_EXPLOSION); + playSound(SFX_DEATH, player.x); + playSound(SFX_EXPLOSION, player.x); } } } @@ -459,7 +459,7 @@ void fireRay(object *attacker) { anEnemy->shield--; addExplosion(anEnemy->x, anEnemy->y, E_SMALL_EXPLOSION); - playSound(SFX_HIT); + playSound(SFX_HIT, anEnemy->x); if (anEnemy->shield < 1) { destroyAlien(attacker, anEnemy); @@ -645,7 +645,7 @@ void doBullets() bullet->active = false; } - playSound(SFX_HIT); + playSound(SFX_HIT, theEnemy->x); if (theEnemy->AIType == AI_EVASIVE) theEnemy->thinktime = 0; @@ -707,7 +707,7 @@ void doBullets() bullet->active = false; } - playSound(SFX_HIT); + playSound(SFX_HIT, player.x); if (bullet->id == WT_ROCKET) addExplosion(bullet->x, bullet->y, E_BIG_EXPLOSION); @@ -728,11 +728,11 @@ void doBullets() { bullet->active = false; addExplosion(bullet->x, bullet->y, E_SMALL_EXPLOSION); - playSound(SFX_HIT); + playSound(SFX_HIT, theCargo->x); if (theCargo->collectType != P_PHOEBE) { theCargo->active = false; - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, theCargo->x); for (int i = 0 ; i < 10 ; i++) addExplosion(theCargo->x + rrand(-15, 15), theCargo->y + rrand(-15, 15), E_BIG_EXPLOSION); updateMissionRequirements(M_PROTECT_PICKUP, P_CARGO, 1); @@ -751,7 +751,7 @@ void doBullets() { if ((bullet->flags & WF_TIMEDEXPLOSION) || (bullet->id == WT_CHARGER)) { - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, bullet->x); for (int i = 0 ; i < 10 ; i++) addExplosion(bullet->x + rrand(-35, 35), bullet->y + rrand(-35, 35), E_BIG_EXPLOSION); diff --git a/code/collectable.cpp b/code/collectable.cpp index 8e07f12..4f8742c 100644 --- a/code/collectable.cpp +++ b/code/collectable.cpp @@ -164,7 +164,7 @@ void addCollectable(float x, float y, int type, int value, int life) static void explodeMine(collectables *collectable) { if ((collectable->x >= 0) && (collectable->x <= 800) && (collectable->y >= 0) && (collectable->y <= 600)) - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, collectable->x); for (int i = 0 ; i < 10 ; i++) addExplosion(collectable->x + rand() % 25 - rand() % 25, collectable->y + rand() % 25 - rand() % 25, E_BIG_EXPLOSION); @@ -380,9 +380,9 @@ void doCollectables() { setInfoLine(temp, FONT_WHITE); if (collectable->type == P_SHIELD) - playSound(SFX_SHIELDUP); + playSound(SFX_SHIELDUP, player.x); else - playSound(SFX_PICKUP); + playSound(SFX_PICKUP, player.x); } } diff --git a/code/debris.cpp b/code/debris.cpp index 395daa3..06362a2 100644 --- a/code/debris.cpp +++ b/code/debris.cpp @@ -23,9 +23,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void addDebris(int x, int y, int amount) { if ((rand() % 2) == 0) - playSound(SFX_DEBRIS); + playSound(SFX_DEBRIS, x); else - playSound(SFX_DEBRIS2); + playSound(SFX_DEBRIS2, x); object *debris; diff --git a/code/game.cpp b/code/game.cpp index d7a24d6..e05332c 100644 --- a/code/game.cpp +++ b/code/game.cpp @@ -265,14 +265,14 @@ int mainGameLoop() // specific to Boss 1 if ((currentGame.area == 5) && (enemy[WC_BOSS].flags & FL_ESCAPED)) { - playSound(SFX_DEATH); + playSound(SFX_DEATH, enemy[WC_BOSS].x); clearScreen(white); updateScreen(); for (int i = 0 ; i < 300 ; i++) { SDL_Delay(10); if ((rand() % 25) == 0) - playSound(SFX_EXPLOSION); + playSound(SFX_EXPLOSION, enemy[WC_BOSS].x); } SDL_Delay(1000); break; diff --git a/code/init.cpp b/code/init.cpp index a57e26c..6f4f88e 100644 --- a/code/init.cpp +++ b/code/init.cpp @@ -200,9 +200,9 @@ void initSystem() if (engine.useAudio) { - if (Mix_OpenAudio(22050, AUDIO_S16, engine.useAudio, 1024) < 0) + if (Mix_OpenAudio(48000, AUDIO_S16, engine.useAudio * 2, 1024) < 0) { - printf("Warning: Couldn't set 22050 Hz 16-bit audio - Reason: %s\n", Mix_GetError()); + printf("Warning: Couldn't set 48000 Hz 16-bit stereo audio - Reason: %s\n", Mix_GetError()); printf("Sound and Music will be disabled\n"); engine.useAudio = false; } diff --git a/code/player.cpp b/code/player.cpp index 6a740a4..7ef3c8f 100644 --- a/code/player.cpp +++ b/code/player.cpp @@ -251,8 +251,8 @@ void doPlayer() enemy[i].flags |= FL_LEAVESECTOR; } - playSound(SFX_DEATH); - playSound(SFX_EXPLOSION); + playSound(SFX_DEATH, player.x); + playSound(SFX_EXPLOSION, player.x); } engine.keyState[SDLK_UP] = engine.keyState[SDLK_DOWN] = engine.keyState[SDLK_LEFT] = engine.keyState[SDLK_RIGHT] = 0;