FMod for Quake1 CD Playback(MP3)

Post tutorials on how to do certain tasks within game or engine code here.
Post Reply
Rikku2000
Posts: 49
Joined: Wed Oct 20, 2010 6:33 pm
Location: Germany
Contact:

FMod for Quake1 CD Playback(MP3)

Post by Rikku2000 »

Today i add FMod to my Engine i use the follow code with the current FMod libs works for linux and Windows

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);
}
I am sorry for my English...
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: FMod for Quake1 CD Playback(MP3)

Post by frag.machine »

Earlier versions of TomazQuake had FMOD support, but it was later ditched for legal reasons (incompatible licenses). Be aware of this if you consider a public release of your engine.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: FMod for Quake1 CD Playback(MP3)

Post by mh »

I believe with GPL 3 FMOD should be OK, but beware of this: http://www.fmod.org/index.php/sales/mp3/
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: FMod for Quake1 CD Playback(MP3)

Post by Baker »

If API cannot be copyrighted (Google vs. Oracle), I'm not sure headers that provide access to a DLL that aren't "GPL compatible" really matter in the legalese equation.

Headers that provide the bare necessities to use a DLL aren't really source code.

I am not a lawyer, and all that. Still, I find some interpretations of the GPL to be outlandish --- and not everyone's interpretation of the GPL matters, only the upstream of the source base you are using. 95% percent of GPL source code contributing people care about the spirit of the GPL, not uber fringe cases and most of those that care about uber fringe cases are not generally actual producers of GPL source code (ie. having an opinion of the GPL does not qualify one to have influence or say, it takes someone using your code to have a voice). Still if someone is like the one major VLC source code contributor and has an ultra-hardline opinion, that opinion better be heeded when it comes to using the VLC source code :D
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: FMod for Quake1 CD Playback(MP3)

Post by revelator »

tbh id ditch mp3 totally ogg has better compression sounds better many game companies prefer it allready and it can even be used as a video codec with theora :) theres also code out there to hook it up to openal for
eax and surround effects.
Productivity is a state of mind.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: FMod for Quake1 CD Playback(MP3)

Post by frag.machine »

IMO the cool thing about FMOD was the easy to do built in effects (underwater distortion, echo, etc). I still haven't found a replacement for that.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
leileilol
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Re: FMod for Quake1 CD Playback(MP3)

Post by leileilol »

There's sound pitching in engoo so you could have Half-Lifeesque nearest neighbor'd slowmo pitch mixing.

I did once try to port ROTT's echo code to the mixing function (the same stuff that crashes the SBLives in Build games). I failed.

Other GPL'd sound postprocess code to check out is the modplug library in openmpt. Tracker yes, but it's hilariously feature-creeped for a sound library under the GPL and also in x86 asm, mostly written in 1997 for 486s originally for a netscape plugin (!). Maybe some of it could be adapted to Quake to make up for the lack of fmod novelties.
i should not be here
Post Reply