Skip to content

Commit

Permalink
Noah music #712
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Apr 10, 2024
1 parent 7acf4ac commit e018dc4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 45 deletions.
4 changes: 4 additions & 0 deletions src/cdogs/cwolfmap/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ int CWAudioGetLevelMusic(const CWMapType type, const int level)
return CWAudioWL6GetLevelMusic(level);
case CWMAPTYPE_SOD:
return CWAudioSODGetLevelMusic(level);
case CWMAPTYPE_N3D:
return CWAudioN3DGetLevelMusic(level);
default:
return -1;
}
Expand All @@ -435,6 +437,8 @@ int CWAudioGetSong(const CWMapType type, const CWSongType song)
return CWAudioWL6GetSong(song);
case CWMAPTYPE_SOD:
return CWAudioSODGetSong(song);
case CWMAPTYPE_N3D:
return CWAudioN3DGetSong(song);
default:
return -1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/cdogs/cwolfmap/audion3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Base offsets
//
#define STARTPCSOUNDS 0
#define STARTADLIBSOUNDS 100
#define STARTDIGISOUNDS 200
#define STARTMUSIC 300
#define STARTADLIBSOUNDS 43
#define STARTDIGISOUNDS 86
#define STARTMUSIC 119

#define LASTSOUND 100
#define LASTSOUND 43

#define SONG1_MUS 0
#define ALLGOOD_MUS 1
Expand Down
6 changes: 3 additions & 3 deletions src/cdogs/cwolfmap/wad/wad.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static int WAD_ExpandBuffer(wad_t *wad, int newsize)
{
wad->handle.buffer = oldarray;
return 1;
}
}

if (oldarray)
{
Expand Down Expand Up @@ -859,7 +859,7 @@ static wadentry_t* wi_buffer_add_entry_at(wad_t *wad, const char *name, int inde
unsigned char *dest = &(wad->handle.buffer[wad->buffer_size]);
memcpy(dest, buffer, size);

wadentry_t* entry;
wadentry_t* entry;
if (!(entry = WAD_AddEntryCommon(wad, name, size, wad->buffer_size, index)))
{
waderrno = WADERROR_OUT_OF_MEMORY;
Expand Down Expand Up @@ -1068,7 +1068,7 @@ wad_t* WAD_Open(const char *filename)
}

out->type = WI_FILE;
out->handle.file = fp;
out->handle.file = fp;

return out;
}
Expand Down
45 changes: 26 additions & 19 deletions src/cdogs/map_wolf.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,18 @@ static const char *soundsSOD[] = {
"chars/die/trans", "chars/alert/bill", "chars/die/bill",
"chars/die/ubermutant", "chars/alert/knight", "chars/die/knight",
"chars/alert/angel", "chars/die/angel", "chaingun_pickup", "spear"};
// TODO: map unknown sounds
static const char *soundsN3D[] = {
// 0-9
"chars/alert/antelope", "somesortofooohsound?", "bullet_pickup", "oooh?",
"door_close", "cantaloupe", "cantaloupe_feeder", "goat_kick", "gulp?",
"chars/die/animal",
"chars/alert/antelope", "chars/alert/bear", "bullet_pickup",
"chars/alert/camel", "door_close", "cantaloupe", "cantaloupe_feeder",
"goat_kick", "gulp?", "chars/die/animal",
// 10-19
"chars/alert/elephant", "1up", "super_feeder", "chars/alert/giraffe",
"chars/alert/goat", "small_feeder", "doof?", "chars/alert/kangaroo",
"whistle", "hand_feed",
// 20-29
"chars/alert/monkey", "chars/alert/bear", "door", "chars/alert/ostrich",
"chars/alert/ox", "hurt", "dundundun?", "secret_door", "chars/alert/sheep",
"chars/alert/monkey", "footsteps/bear", "door", "chars/alert/ostrich",
"chars/alert/ox", "hurt", "hahaha", "secret_door", "chars/alert/sheep",
"large_feeder",
// 30-32
"spit", "watermelon", "watermelon_feeder"}; // TODO BS6:
Expand Down Expand Up @@ -454,7 +453,7 @@ static const char *GetAdlibSound(const CWMapType type, const int i)
case CWMAPTYPE_SOD:
return adlibSoundsSOD[i];
case CWMAPTYPE_N3D:
// N3D has no adlib sounds
// Not using any adlib sounds
return NULL;
default:
CASSERT(false, "unknown map type");
Expand All @@ -470,19 +469,23 @@ static const CWSongType songsCampaign[] = {
SONG_ROSTER, // lose
SONG_VICTORY, // victory
};
static Mix_Chunk *LoadMusic(CWolfMap *map, const int i)
static bool LoadMusic(CWolfMap *map, MusicChunk *chunk, const int i)
{
char *data;
size_t len;
const int err = CWAudioGetMusic(&map->audio, map->type, i, &data, &len);
if (err != 0)
{
goto bail;
return false;
}
return Mix_QuickLoad_RAW((Uint8 *)data, (Uint32)len);

bail:
return NULL;
if (map->type == CWMAPTYPE_N3D)
{
SDL_RWops *rwops = SDL_RWFromMem(data, (int)len);
chunk->u.Music = Mix_LoadMUS_RW(rwops, 1);
return true;
}
chunk->u.Chunk = Mix_QuickLoad_RAW((Uint8 *)data, (Uint32)len);
return false;
}

static bool IsDefaultMap(const char *filename)
Expand Down Expand Up @@ -638,11 +641,12 @@ typedef struct
CWolfMap *Map;
MusicType Type;
} CampaignSongData;
static Mix_Chunk *GetCampaignSong(void *data)
static bool GetCampaignSong(MusicChunk *chunk, void *data)
{
CampaignSongData *csd = data;
const int songIndex = songsCampaign[csd->Type];
return LoadMusic(csd->Map, CWAudioGetSong(csd->Map->type, songIndex));
return LoadMusic(
csd->Map, chunk, CWAudioGetSong(csd->Map->type, songIndex));
}
int MapWolfLoad(
const char *filename, const int spearMission, CampaignSetting *c)
Expand Down Expand Up @@ -676,7 +680,8 @@ int MapWolfLoad(
csd->Type = i;
c->CustomSongs[i].Data = csd;
c->CustomSongs[i].GetData = GetCampaignSong;
c->CustomSongs[i].Chunk = NULL;
c->CustomSongs[i].isMusic = false;
c->CustomSongs[i].u.Chunk = NULL;
}

char buf[CDOGS_PATH_MAX];
Expand Down Expand Up @@ -914,11 +919,12 @@ typedef struct
CWolfMap *Map;
int MissionIndex;
} MissionSongData;
static Mix_Chunk *GetMissionSong(void *data)
static bool GetMissionSong(MusicChunk *chunk, void *data)
{
MissionSongData *msd = data;
return LoadMusic(
msd->Map, CWAudioGetLevelMusic(msd->Map->type, msd->MissionIndex));
msd->Map, chunk,
CWAudioGetLevelMusic(msd->Map->type, msd->MissionIndex));
}
static void LoadMission(
CampaignSetting *c, const map_t tileClasses, CWolfMap *map,
Expand Down Expand Up @@ -965,7 +971,8 @@ static void LoadMission(
msd->MissionIndex = missionIndex;
m.Music.Data.Chunk.Data = msd;
m.Music.Data.Chunk.GetData = GetMissionSong;
m.Music.Data.Chunk.Chunk = NULL;
m.Music.Data.Chunk.isMusic = false;
m.Music.Data.Chunk.u.Chunk = NULL;

MissionStaticInit(&m.u.Static);

Expand Down
36 changes: 21 additions & 15 deletions src/cdogs/music.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2013-2016, 2019, 2021 Cong Xu
Copyright (c) 2013-2016, 2019, 2021, 2024 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -204,18 +204,25 @@ void MusicPlayFile(
MusicPlayGeneral(mp, type);
}
}
void MusicPlayChunk(MusicPlayer *mp, const MusicType type, Mix_Chunk *chunk)
void MusicPlayChunk(MusicPlayer *mp, const MusicType type, MusicChunk *chunk)
{
MusicStop(mp);
bool played = false;
if (chunk != NULL)
{
mp->type = MUSIC_SRC_CHUNK;
mp->u.chunk.chunk = chunk;
mp->u.chunk.channel = Mix_PlayChannel(-1, chunk, -1);
played = true;
if (chunk->isMusic)
{
mp->type = MUSIC_SRC_DYNAMIC;
mp->u.dynamic = chunk->u.Music;
PlayMusic(mp);
}
else
{
mp->type = MUSIC_SRC_CHUNK;
mp->u.chunk.chunk = chunk->u.Chunk;
mp->u.chunk.channel = Mix_PlayChannel(-1, chunk->u.Chunk, -1);
}
}
if (!played)
else
{
MusicPlayGeneral(mp, type);
}
Expand Down Expand Up @@ -262,7 +269,6 @@ void MusicPause(MusicPlayer *mp)
Mix_Pause(mp->u.chunk.channel);
break;
}

}

void MusicResume(MusicPlayer *mp)
Expand Down Expand Up @@ -322,9 +328,9 @@ const char *MusicGetErrorMessage(const MusicPlayer *mp)

void MusicChunkTerminate(MusicChunk *chunk)
{
if (chunk->Chunk)
if (!chunk->isMusic && chunk->u.Chunk)
{
Mix_FreeChunk(chunk->Chunk);
Mix_FreeChunk(chunk->u.Chunk);
}
CFREE(chunk->Data);
memset(chunk, 0, sizeof *chunk);
Expand All @@ -333,13 +339,13 @@ void MusicChunkTerminate(MusicChunk *chunk)
void MusicPlayFromChunk(
MusicPlayer *mp, const MusicType type, MusicChunk *chunk)
{
if (chunk->Chunk == NULL && chunk->GetData)
if ((chunk->isMusic ? chunk->u.Music == NULL : chunk->u.Chunk == NULL) &&
chunk->GetData)
{
chunk->Chunk =
chunk->GetData(chunk->Data);
chunk->isMusic = chunk->GetData(chunk, chunk->Data);
CFREE(chunk->Data);
chunk->Data = NULL;
chunk->GetData = NULL;
}
MusicPlayChunk(mp, type, chunk->Chunk);
MusicPlayChunk(mp, type, chunk);
}
12 changes: 8 additions & 4 deletions src/cdogs/music.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ typedef struct
char errorMessage[128];
} MusicPlayer;

typedef struct
typedef struct _MusicChunk
{
void *Data;
Mix_Chunk *(*GetData)(void *);
Mix_Chunk *Chunk;
bool (*GetData)(struct _MusicChunk *, void *);
bool isMusic;
union {
Mix_Chunk *Chunk;
Mix_Music *Music;
} u;
} MusicChunk;

void MusicPlayerInit(MusicPlayer *mp);
Expand All @@ -106,7 +110,7 @@ void MusicPlayGeneral(MusicPlayer *mp, const MusicType type);
void MusicPlayFile(
MusicPlayer *mp, const MusicType type, const char *missionPath,
const char *music);
void MusicPlayChunk(MusicPlayer *mp, const MusicType type, Mix_Chunk *chunk);
void MusicPlayChunk(MusicPlayer *mp, const MusicType type, MusicChunk *chunk);
void MusicStop(MusicPlayer *mp);
void MusicPause(MusicPlayer *mp);
void MusicResume(MusicPlayer *mp);
Expand Down

0 comments on commit e018dc4

Please sign in to comment.