Make audio 48 kHz stereo, pan sound effects.

This commit is contained in:
Guus Sliepen 2012-03-02 23:00:35 +01:00
parent 46fd85829b
commit 8e4d5ccfd6
9 changed files with 63 additions and 40 deletions

View File

@ -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);
}
}
}

View File

@ -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)

View File

@ -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();

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;