Skip to content

Commit

Permalink
FMOD: Playing CD music on Ubuntu
Browse files Browse the repository at this point in the history
There are some issues, though: a brief crackle before the track begins,
and it seems the wrong track is played for the title screen.
  • Loading branch information
skyjake committed Dec 9, 2011
1 parent 2608eec commit e594da1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion doomsday/engine/portable/src/dd_wad.c
Expand Up @@ -746,6 +746,7 @@ int W_IsIWAD(const char* fn)
FILE* file;
char id[5];
const char* ext;
int result;

if(!M_FileExists(fn))
return false;
Expand All @@ -765,7 +766,7 @@ int W_IsIWAD(const char* fn)
if((file = fopen(fn, "rb")) == NULL)
return false;

fread(id, 4, 1, file);
result = fread(id, 4, 1, file);
id[4] = 0;
fclose(file);

Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/m_args.c
Expand Up @@ -171,6 +171,8 @@ int ArgParse(int mode, const char* cmdline)
// Try to open it.
if((file = fopen(word, "rt")) != NULL)
{
int result;

// How long is it?
if(fseek(file, 0, SEEK_END))
Con_Error("ArgParse: fseek failed on SEEK_END!");
Expand All @@ -182,11 +184,9 @@ int ArgParse(int mode, const char* cmdline)
Con_Error("ArgParse: failed on alloc of %d bytes.",
i + 1);

fread(response, 1, i, file);
result = fread(response, 1, i, file);
fclose(file);
count +=
ArgParse(mode == PM_COUNT ? PM_COUNT : PM_NORMAL_REC,
response);
count += ArgParse(mode == PM_COUNT ? PM_COUNT : PM_NORMAL_REC, response);
M_Free(response);
}
}
Expand Down
12 changes: 6 additions & 6 deletions doomsday/plugins/fmod/include/driver_fmod.h
Expand Up @@ -40,16 +40,16 @@ int DS_Set(int prop, const void* ptr);

}

#define DSFMOD_TRACE(args) std::cerr << "[dsFMOD] " << args << std::endl;

#ifdef _DEBUG
# define DSFMOD_ERRCHECK(result) \
# define DSFMOD_TRACE(args) std::cerr << "[dsFMOD] " << args << std::endl;
#else
# define DSFMOD_TRACE(args)
#endif

#define DSFMOD_ERRCHECK(result) \
if(result != FMOD_OK) { \
printf("[dsFMOD] Error at %s, line %i: (%d) %s\n", __FILE__, __LINE__, result, FMOD_ErrorString(result)); \
}
#else
# define DSFMOD_ERRCHECK(result)
#endif

extern FMOD::System* fmodSystem;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/fmod/include/fmod_music.h
Expand Up @@ -49,6 +49,6 @@ int DM_Music_PlayFile(const char *filename, int looped);

// Internal:
void DM_Music_SetSoundFont(const char* fileName);
bool DM_Music_PlaySound(FMOD::Sound* customSound);
bool DM_Music_PlaySound(FMOD::Sound* customSound, bool needRelease);

#endif /* end of include guard: __DSFMOD_MUS_H__ */
7 changes: 5 additions & 2 deletions doomsday/plugins/fmod/src/fmod_cd.cpp
Expand Up @@ -107,6 +107,7 @@ int DM_CDAudio_Play(int track, int looped)
DSFMOD_TRACE("CDAudio_Play: CD drive name: '" << driveName << "'");

FMOD::Sound* trackSound = 0;
bool needRelease = false;

#ifdef MACOSX
// The CD tracks are mapped to files.
Expand All @@ -117,11 +118,13 @@ int DM_CDAudio_Play(int track, int looped)
result = fmodSystem->createStream(trackPath, (looped? FMOD_LOOP_NORMAL : 0), 0, &trackSound);
DSFMOD_TRACE("CDAudio_Play: Track " << track << " => Sound " << trackSound);
DSFMOD_ERRCHECK(result);

needRelease = true;
#else
if(!cdSound)
{
// Get info about the CD tracks.
result = fmodSystem->createStream(driveName, FMOD_OPENONLY /* | (looped? FMOD_LOOP_NORMAL : 0)*/, 0, &cdSound);
result = fmodSystem->createStream(driveName, FMOD_OPENONLY, 0, &cdSound);
DSFMOD_TRACE("CDAudio_Play: Opening CD, cdSound " << cdSound);
DSFMOD_ERRCHECK(result);
}
Expand All @@ -146,7 +149,7 @@ int DM_CDAudio_Play(int track, int looped)
}
#endif

return DM_Music_PlaySound(trackSound); // takes ownership
return DM_Music_PlaySound(trackSound, needRelease); // takes ownership
}

void DM_CDAudio_Pause(int pause)
Expand Down
20 changes: 18 additions & 2 deletions doomsday/plugins/fmod/src/fmod_music.cpp
Expand Up @@ -40,6 +40,7 @@ struct SongBuffer

static FMOD::Sound* song;
static FMOD::Channel* music;
static bool needReleaseSong;
static float musicVolume;
static SongBuffer* songBuffer;
static const char* soundFontFileName;
Expand Down Expand Up @@ -68,8 +69,17 @@ static void releaseSong()
{
if(song)
{
song->release();
if(needReleaseSong)
{
DSFMOD_TRACE("releaseSong: Song " << song << " will be released.")
song->release();
}
else
{
DSFMOD_TRACE("releaseSong: Song " << song << " will NOT be released.");
}
song = 0;
needReleaseSong = false;
}
music = 0;
}
Expand All @@ -96,6 +106,7 @@ int DM_Music_Init(void)
{
music = 0;
song = 0;
needReleaseSong = false;
musicVolume = 1.f;
songBuffer = 0;
soundFontFileName = 0; // empty for the default
Expand Down Expand Up @@ -196,12 +207,13 @@ static bool startSong()
}

/// @internal
bool DM_Music_PlaySound(FMOD::Sound* customSound)
bool DM_Music_PlaySound(FMOD::Sound* customSound, bool needRelease)
{
releaseSong();
releaseSongBuffer();

// Use this as the song.
needReleaseSong = needRelease;
song = customSound;
return startSong();
}
Expand Down Expand Up @@ -234,6 +246,8 @@ int DM_Music_Play(int looped)
DSFMOD_TRACE("Music_Play: songBuffer has " << songBuffer->size << " bytes, created Sound " << song);
DSFMOD_ERRCHECK(result);

needReleaseSong = true;

// The song buffer remains in memory, in case FMOD needs to stream from it.
}
return startSong();
Expand Down Expand Up @@ -283,5 +297,7 @@ int DM_Music_PlayFile(const char *filename, int looped)
DSFMOD_TRACE("Music_Play: loaded '" << filename << "' => Sound " << song);
DSFMOD_ERRCHECK(result);

needReleaseSong = true;

return startSong();
}

0 comments on commit e594da1

Please sign in to comment.