Commit 2e66b7f9 authored by Gerhard Stein's avatar Gerhard Stein

Audio mapping. More Beatiful code

parent 0c6ec76e
......@@ -32,7 +32,6 @@ typedef struct
// Game Sounds
enum GameSound
{
// Common Blocks
SOUND_KEEN_WALK, SOUND_KEEN_WALK2,
SOUND_KEEN_JUMP, SOUND_KEEN_POGO,
......@@ -78,6 +77,7 @@ SOUND_FOOTSLAM,
SOUND_CANT_SWIM,
SOUND_GET_WETSUIT,
SOUND_KEEN_SWIM,
SOUND_KEEN_SWIM_TO_LAND,
SOUND_GET_AMMO,
SOUND_GET_DROP,
SOUND_GET_GEM,
......@@ -90,6 +90,7 @@ SOUND_FLAG_LAND,
SOUND_SQUISH_SKYPEST,
SOUND_MINE_EXPLOSION,
SOUND_SPRITE_SHOT,
SOUND_TRESURE_STEALER_TELEPORT,
SOUND_WORMOUTH_STRIKE,
SOUND_LICK_FIREBREATH,
......@@ -107,6 +108,7 @@ SOUND_COMPUTER_PADDLE,
SOUND_HIT_SIDEWALL,
SOUND_COMPUTER_POINT,
SOUND_PLAYER_POINT
};
class CAudioResources
......
......@@ -55,6 +55,75 @@ bool CAudioGalaxy::readPCSpeakerSoundintoWaveForm(CSoundSlot &soundslot, const b
return true;
}
/**
* \brief Sets up the Map assignments for the Sounds used in Keen Galaxy
*/
void CAudioGalaxy::setupAudioMap()
{
// Episode 4
sndSlotMapGalaxy[4][SOUND_KEEN_WALK] = 0;
sndSlotMapGalaxy[4][SOUND_KEEN_WALK2] = 1;
sndSlotMapGalaxy[4][SOUND_KEEN_JUMP] = 2;
sndSlotMapGalaxy[4][SOUND_KEEN_LAND] = 3;
sndSlotMapGalaxy[4][SOUND_KEEN_FIRE] = 4;
sndSlotMapGalaxy[4][SOUND_WORMOUTH_STRIKE] = 5;
//sndSlotMapGalaxy[4][?] = 6;
sndSlotMapGalaxy[4][SOUND_KEEN_POGO] = 7;
sndSlotMapGalaxy[4][SOUND_GET_BONUS] = 8;
sndSlotMapGalaxy[4][SOUND_GET_AMMO] = 9;
sndSlotMapGalaxy[4][SOUND_GET_DROP] = 10;
sndSlotMapGalaxy[4][SOUND_GET_ITEM] = 11;
sndSlotMapGalaxy[4][SOUND_ENTER_LEVEL] = 12;
sndSlotMapGalaxy[4][SOUND_LEVEL_DONE] = 13;
sndSlotMapGalaxy[4][SOUND_CANT_SWIM] = 14;
sndSlotMapGalaxy[4][SOUND_KEEN_BUMPHEAD] = 15;
sndSlotMapGalaxy[4][SOUND_BOUNCE_HIGH] = 16;
sndSlotMapGalaxy[4][SOUND_EXTRA_LIFE] = 17;
sndSlotMapGalaxy[4][SOUND_DOOR_OPEN] = 18;
sndSlotMapGalaxy[4][SOUND_GET_GEM] = 19;
sndSlotMapGalaxy[4][SOUND_KEEN_FALL] = 20;
sndSlotMapGalaxy[4][SOUND_GUN_CLICK] = 21;
sndSlotMapGalaxy[4][SOUND_SQUISH_SKYPEST] = 22;
sndSlotMapGalaxy[4][SOUND_KEEN_DIE] = 23;
//sndSlotMapGalaxy[4][?] = 24;
sndSlotMapGalaxy[4][SOUND_SHOT_HIT] = 25;
sndSlotMapGalaxy[4][SOUND_KEEN_SWIM] = 26;
sndSlotMapGalaxy[4][SOUND_KEEN_SWIM_TO_LAND] = 27;
sndSlotMapGalaxy[4][SOUND_BOUNCE_LOW] = 28;
//sndSlotMapGalaxy[4][?] = 29;
sndSlotMapGalaxy[4][SOUND_TRESURE_STEALER_TELEPORT] = 30;
sndSlotMapGalaxy[4][SOUND_RESCUE_COUNCIL_MEMBER] = 31;
sndSlotMapGalaxy[4][SOUND_LICK_FIREBREATH] = 32;
sndSlotMapGalaxy[4][SOUND_BERKELOID_WINDUP] = 33;
sndSlotMapGalaxy[4][SOUND_STATUS_SLIDE_IN] = 34;
sndSlotMapGalaxy[4][SOUND_STATUS_SLIDE_OUT] = 35;
sndSlotMapGalaxy[4][SOUND_BUBBLE] = 36;
sndSlotMapGalaxy[4][SOUND_MINE_EXPLOSION] = 37;
sndSlotMapGalaxy[4][SOUND_SPRITE_SHOT] = 38;
sndSlotMapGalaxy[4][SOUND_THUNDERCLOUD_STRIKE] = 39;
sndSlotMapGalaxy[4][SOUND_BERKELOID_FIREBALL_LANDING] = 40;
sndSlotMapGalaxy[4][SOUND_DARTGUN_SHOOT] = 41;
sndSlotMapGalaxy[4][SOUND_DOPEFISH_BURP] = 42;
sndSlotMapGalaxy[4][SOUND_FLAG_APPEAR] = 43;
sndSlotMapGalaxy[4][SOUND_FLAG_LAND] = 44;
sndSlotMapGalaxy[4][SOUND_GET_WETSUIT] = 45;
sndSlotMapGalaxy[4][SOUND_SLUG_DEFECATE] = 46;
sndSlotMapGalaxy[4][SOUND_PLAYER_PADDLE] = 47;
sndSlotMapGalaxy[4][SOUND_COMPUTER_PADDLE] = 48;
sndSlotMapGalaxy[4][SOUND_HIT_SIDEWALL] = 49;
sndSlotMapGalaxy[4][SOUND_COMPUTER_POINT] = 50;
sndSlotMapGalaxy[4][SOUND_PLAYER_POINT] = 51;
/* Keen 5 Sounds
// 60 Stands for Door which slides open!
// 56 is when elevator transports
// 57 when opens?
*/
}
/**
* \brief This function will load the sounds using other dictionaries which are embedded in the Exe File.
* Only galaxy supports that feature, and the original games will read two files from the EXE-file
......@@ -63,6 +132,8 @@ bool CAudioGalaxy::readPCSpeakerSoundintoWaveForm(CSoundSlot &soundslot, const b
*/
bool CAudioGalaxy::LoadFromAudioCK(const CExeFile& ExeFile)
{
setupAudioMap();
if(m_AudioSpec.format != 0)
{
// Open the Huffman dictionary and get AUDIODICT
......
......@@ -11,81 +11,6 @@
#include "common/CAudioResources.h"
#include "fileio/CExeFile.h"
const unsigned char SndSlotMapGalaxy[]=
{
//52,52,
0,1,
2,7,
23,20,
15,
7,
4,
21,
25,
11,
12,
13,
14,
15,
17,
17,
18,
19,
20,
21,
18,
23,
24,
25,
26,
27,
28,
8,
12,
31,
32,
33,
34,
35,
36,
37,
38,
14,
45,
26,
9,
10,
19,
31,
34,
35,
36,
43,
44,
22,
24,
30,
5,
32,
33,
39,
40,
41,
42,
46,
28,
16,
47,
48,
49,
50,
51
};
class CAudioGalaxy : public CAudioResources {
public:
......@@ -96,8 +21,12 @@ public:
bool LoadFromAudioCK(const CExeFile& ExeFile);
bool loadSoundData();
void unloadSound();
std::map< unsigned int, std::map<GameSound, int> > sndSlotMapGalaxy;
private:
void setupAudioMap();
const CExeFile &m_ExeFile;
};
......
......@@ -17,6 +17,9 @@ namespace galaxy
const Uint32 speed = 10;
const Uint32 hittime = 100;
// Test
//int slot = 52;
CBullet::CBullet(CMap *pmap, const Uint16 foeID, const Uint32 x, const Uint32 y, const int xDir, const int yDir) :
CGalaxySpriteObject(pmap, foeID, x, y)
{
......@@ -30,6 +33,11 @@ CGalaxySpriteObject(pmap, foeID, x, y)
setActionSprite();
calcBoundingBoxes();
playSound( SOUND_KEEN_FIRE );
// For testing sounds.
/*g_pSound->playStereosoundSlot(slot, PLAY_NOW, 0);
printf("Sound %d played!\n", slot-52);
slot++; */
}
void CBullet::process()
......
......@@ -169,6 +169,7 @@ const int POGO_START_INERTIA = 125; // 48 In K5 Disassemble
void CPlayerLevel::makeHimStand()
{
playSound( SOUND_KEEN_LAND );
if(pSupportedbyobject && g_pBehaviorEngine->getEpisode() == 5)
setAction(A_KEEN_ON_PLAT);
else
......
......@@ -36,7 +36,8 @@ m_animation(0),
m_animation_time(1),
m_animation_ticker(0),
m_cantswim(false),
waveTimer(0)
waveTimer(0),
swimming(false)
{
m_ActionBaseOffset = actionoffset;
......@@ -706,7 +707,9 @@ void CPlayerWM::checkforSwimming(bool &bleft, bool &bright, bool &bup, bool &bdo
m_basesprite = swimBaseFrame;
}
else if(down == 11)
{
m_basesprite = walkBaseFrame;
}
// from right
if(right == 12)
......@@ -715,7 +718,9 @@ void CPlayerWM::checkforSwimming(bool &bleft, bool &bright, bool &bup, bool &bdo
m_basesprite = swimBaseFrame;
}
else if(left == 12)
{
m_basesprite = walkBaseFrame;
}
// from bottom
if(down == 13)
......@@ -724,7 +729,9 @@ void CPlayerWM::checkforSwimming(bool &bleft, bool &bright, bool &bup, bool &bdo
m_basesprite = swimBaseFrame;
}
else if(up == 13)
{
m_basesprite = walkBaseFrame;
}
// from left
if(left == 14)
......@@ -733,10 +740,14 @@ void CPlayerWM::checkforSwimming(bool &bleft, bool &bright, bool &bup, bool &bdo
m_basesprite = swimBaseFrame;
}
else if(right == 14)
{
m_basesprite = walkBaseFrame;
}
if(m_Inventory.Item.m_special.ep4.swimsuit)
{
bleft = bright = bup = bdown = false;
}
}
/**
......@@ -769,6 +780,13 @@ void CPlayerWM::performWalkingAnimation(bool walking)
}
else
sprite += 2;
if(swimming)
{
playSound(SOUND_KEEN_SWIM_TO_LAND);
swimming = false;
}
}
/**
......@@ -792,6 +810,12 @@ void CPlayerWM::performSwimmingAnimation()
sprite = m_basesprite + 14;
else
sprite = m_basesprite;
if(!swimming)
{
playSound(SOUND_KEEN_SWIM_TO_LAND);
swimming = true;
}
m_animation_time = 5;
sprite += m_animation%2;
......
......@@ -66,6 +66,7 @@ private:
int elevator_close_timer;
int elevator_frames;
int waveTimer;
bool swimming;
void (CPlayerWM::*mProcessPtr)();
};
......
......@@ -109,7 +109,7 @@ void CDevilSprite::processShoot()
if( m_timer == SPRITE_SHOOT_DELAY/2 )
{
g_pSound->playSound(SOUND_KEEN_FIRE);
g_pSound->playSound(SOUND_SPRITE_SHOT);
int x_coord = getXMidPos();
x_coord += (xDirection == LEFT) ? -(8<<STC) : +(8<<STC);
CEnemyShot *Spark = new CEnemyShot(mp_Map, 0, x_coord, getYMidPos()-(8<<STC),
......
......@@ -177,8 +177,57 @@ bool CAudioVorticon::loadSound(Uint8 *buffer, const Uint32 buf_size, const std::
}
/**
* \brief Sets up the Map assignments for the Sounds used in Keen Vorticon
*/
void CAudioVorticon::setupAudioMap()
{
sndSlotMap[SOUND_KEEN_WALK] = 0;
sndSlotMap[SOUND_KEEN_WALK2] = 1;
sndSlotMap[SOUND_KEEN_JUMP] = 2;
sndSlotMap[SOUND_KEEN_POGO] = 3;
sndSlotMap[SOUND_KEEN_DIE] = 4;
sndSlotMap[SOUND_KEEN_FALL] = 5;
sndSlotMap[SOUND_KEEN_BUMPHEAD] = 6;
sndSlotMap[SOUND_KEENSLEFT] = 7;
sndSlotMap[SOUND_KEEN_FIRE] = 8;
sndSlotMap[SOUND_GUN_CLICK] = 9;
sndSlotMap[SOUND_SHOT_HIT] = 10;
sndSlotMap[SOUND_GET_ITEM] = 11;
sndSlotMap[SOUND_GET_PART] = 12;
sndSlotMap[SOUND_LEVEL_DONE] = 13;
sndSlotMap[SOUND_GAME_OVER] = 14;
sndSlotMap[SOUND_TELEPORT] = 15;
sndSlotMap[SOUND_EXTRA_LIFE] = 16;
sndSlotMap[SOUND_CANNONFIRE] = 17;
sndSlotMap[SOUND_CHUNKSMASH] = 18;
sndSlotMap[SOUND_GOINDOOR] = 19;
sndSlotMap[SOUND_GET_CARD] = 20;
sndSlotMap[SOUND_USE_KEY] = 21;
sndSlotMap[SOUND_DOOR_OPEN] = 22;
sndSlotMap[SOUND_YORP_BUMP] = 23;
sndSlotMap[SOUND_YORP_STUN] = 24;
sndSlotMap[SOUND_YORP_DIE] = 25;
sndSlotMap[SOUND_GARG_DIE] = 26;
sndSlotMap[SOUND_VORT_DIE] = 27;
sndSlotMap[SOUND_KEEN_LAND] = 28;
sndSlotMap[SOUND_GET_BONUS] = 29;
sndSlotMap[SOUND_ENTER_LEVEL] = 30;
sndSlotMap[SOUND_SWITCH_TOGGLE] = 31;
sndSlotMap[SOUND_EARTHPOW] = 32;
sndSlotMap[SOUND_TANK_FIRE] = 33;
sndSlotMap[SOUND_KEEN_BLOK] = 34;
sndSlotMap[SOUND_MEEP] = 35;
sndSlotMap[SOUND_ANKH] = 36;
sndSlotMap[SOUND_MORTIMER] = 37;
sndSlotMap[SOUND_FOOTSLAM] = 38;
}
bool CAudioVorticon::loadSoundData()
{
setupAudioMap();
bool ok = true;
const int episode = m_ExeFile.getEpisode();
const std::string soundfile = "sounds.ck" + itoa(episode);
......
......@@ -12,57 +12,18 @@
#include "fileio/CExeFile.h"
// Map for the vorticon sound slots
const unsigned char SndSlotMapVort[]=
{
0, 1,
2, 3,
4, 5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38
};
class CAudioVorticon : public CAudioResources {
public:
CAudioVorticon(const CExeFile &ExeFile, const SDL_AudioSpec &AudioSpec);
bool loadSoundData();
void unloadSound();
std::map<GameSound, int> sndSlotMap;
private:
void setupAudioMap();
Uint8* loadSoundStream(Uint32 &buffer_size, Uint8* exedata);
template <typename T>
......
......@@ -59,7 +59,6 @@ m_mixing_channels(0),
m_MusicVolume(SDL_MIX_MAXVOLUME),
m_SoundVolume(SDL_MIX_MAXVOLUME),
m_sound_blaster_mode(false),
mp_SndSlotMap(NULL),
m_OPL_Player(mAudioSpec),
m_pause_gameplay(false)
{
......@@ -296,12 +295,15 @@ void CSound::playStereofromCoord( const GameSound snd,
}
}
void CSound::playStereosound(const GameSound snd, const char mode, const short balance)
{
if( m_mixing_channels == 0 ) return;
CSoundSlot *mp_Slots = mpAudioRessources->getSlotPtr();
unsigned char slotplay = mp_SndSlotMap[snd];
int slotplay = sndSlotMap[snd];
const unsigned int speaker_snds_end_off = mpAudioRessources->getNumberofSounds()/2;
if(slotplay >= speaker_snds_end_off)
......@@ -309,12 +311,19 @@ void CSound::playStereosound(const GameSound snd, const char mode, const short b
if(m_sound_blaster_mode && mp_Slots[slotplay+speaker_snds_end_off].getSoundData())
slotplay += speaker_snds_end_off;
CSoundSlot &new_slot = mp_Slots[slotplay];
if (mode==PLAY_NORESTART && isPlaying(snd))
return;
playStereosoundSlot(slotplay, mode, balance);
}
void CSound::playStereosoundSlot(unsigned char slotplay, const char mode, const short balance)
{
CSoundSlot *mp_Slots = mpAudioRessources->getSlotPtr();
CSoundSlot &new_slot = mp_Slots[slotplay];
if(mode==PLAY_PAUSEALL)
m_pause_gameplay = true;
......@@ -343,21 +352,24 @@ void CSound::playStereosound(const GameSound snd, const char mode, const short b
}
bool CSound::loadSoundData()
{
{
const CExeFile &ExeFile = g_pBehaviorEngine->m_ExeFile;
if(ExeFile.getEpisode() >= 1 && ExeFile.getEpisode() <= 3) // Vorticon based Keengame
const unsigned int ep = ExeFile.getEpisode();
if(ep >= 1 && ep <= 3) // Vorticon based Keengame
{
std::unique_ptr<CAudioVorticon> vorticonAudio(new CAudioVorticon(ExeFile, mAudioSpec));
const bool ok = vorticonAudio->loadSoundData();
sndSlotMap = vorticonAudio->sndSlotMap;
mpAudioRessources = move(vorticonAudio);
mp_SndSlotMap = const_cast<unsigned char*>(SndSlotMapVort);
return(mpAudioRessources->loadSoundData());
return ok;
}
else if(ExeFile.getEpisode() >= 4 && ExeFile.getEpisode() <= 7) // Galaxy based Keengame
else if(ep >= 4 && ep <= 7) // Galaxy based Keengame
{
std::unique_ptr<CAudioGalaxy> galaxyAudio(new CAudioGalaxy(ExeFile, mAudioSpec));
mpAudioRessources = move(galaxyAudio);
mp_SndSlotMap = const_cast<unsigned char*>(SndSlotMapGalaxy);
return(mpAudioRessources->loadSoundData());
const bool ok = galaxyAudio->loadSoundData();
sndSlotMap = galaxyAudio->sndSlotMapGalaxy[ep];
mpAudioRessources = move(galaxyAudio);
return ok;
}
return false;
......
......@@ -44,6 +44,7 @@ public:
const SoundPlayMode mode,
const int xcoordinate);
void playStereosound(const GameSound snd, const char mode, const short balance);
void playStereosoundSlot(unsigned char slotplay, const char mode, const short balance);
bool isPlaying(const GameSound snd);
void stopSound(const GameSound snd);
void destroy();
......@@ -91,7 +92,7 @@ private:
std::vector<Uint8> m_MixedForm; // Mainly used by the callback function. Declared once and allocated
// for the whole program
unsigned char *mp_SndSlotMap;
std::map<GameSound, int> sndSlotMap;
COPLEmulator m_OPL_Player;
bool m_pause_gameplay;
......
......@@ -107,5 +107,5 @@ void COPLEmulator::shutdown()
void COPLEmulator::clear()
{
Chip.clear();
//Chip.clear();
}
......@@ -105,6 +105,8 @@ public:
*/
void shutdown();
void clear();
private:
const SDL_AudioSpec &m_AudioDevSpec;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment