Code: Select all
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// Quake Music player, code by Rikku2000...
#include <fmod/fmod.h>
#include <fmod/fmod_errors.h>
#include "quakedef.h"
char track_file[MAX_OSPATH];
qboolean loop_track = false;
int current_track = 0;
FMOD_SYSTEM *fmod_system;
FMOD_SOUND *fmod_sound;
FMOD_CHANNEL *fmod_channel = 0;
/*
CDAudio_Play
Note: edited cd_null.c for use Quake Soundsystem \
by useing ".mp3" files as music track.
*/
void CDAudio_Play(byte track, qboolean looping) {
if (current_track == track) // If current track is not same as new track stop music.
return;
CDAudio_Stop();
// Setup the new track.
current_track = track;
loop_track = looping;
// Precache new music file.
sprintf(track_file, "%s/sound/music/track%d.mp3", GAMENAME, current_track);
FMOD_System_CreateSound (fmod_system, track_file, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &fmod_sound);
if(track_file != NULL) // If no track file is set start music now!
FMOD_System_PlaySound (fmod_system, FMOD_CHANNEL_FREE, fmod_sound, 0, &fmod_channel); // load and play sample
}
/*
CDAudio_PlayMod - FMod Func...
Note: edited cd_null.c for use Quake Soundsystem \
by useing ".mp3" files as custom music track.
*/
void CDAudio_PlayMod (void) {
char *command;
command = Cmd_Argv (2);
if (stricmp (command, "stop") == 0) {
CDAudio_Stop ();
} else if (stricmp (command, "play") == 0) {
if (track_file == Cmd_Argv (0)) // If current track is not same as new track stop music.
return;
CDAudio_Stop();
// Precache new music file.
sprintf(track_file, "%s/sound/music/%s.mp3", GAMENAME, Cmd_Argv (1));
FMOD_System_CreateSound (fmod_system, track_file, FMOD_SOFTWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &fmod_sound);
if(track_file != NULL) // If no track file is set start music now!
FMOD_System_PlaySound (fmod_system, FMOD_CHANNEL_FREE, fmod_sound, 0, &fmod_channel); // load and play sample
} else if (stricmp (command, "pause") == 0) {
CDAudio_Pause ();
} else
Con_Printf ("Playmp3: <file> <play|pause|stop>\n", Cmd_Argv (0));
}
void CDAudio_Stop(void) {
current_track = 0;
if(track_file != NULL)
FMOD_Sound_Release (fmod_sound);
}
void CDAudio_Pause(void) {
}
void CDAudio_Resume(void) {
}
void CDAudio_Update(void) {
}
int CDAudio_Init(void) {
unsigned int version;
// init FMOD sound system
if (FMOD_System_Create (&fmod_system))
Con_Printf ("FMOD_System_Create failed!\n");
if (FMOD_System_GetVersion (fmod_system, &version))
Con_Printf ("FMOD_System_GetVersion failed!\n");
if (FMOD_System_Init (fmod_system, 1, FMOD_INIT_NORMAL, NULL))
Con_Printf ("FMOD_System_Init failed!\n");
Cmd_AddCommand ("playmp3", CDAudio_PlayMod);
return 0;
}
void CDAudio_Shutdown(void) {
FMOD_Sound_Release (fmod_sound); // Stop sound file
// Close Fmod System
FMOD_System_Close (fmod_system);
FMOD_System_Release (fmod_system);
}