Page 1 of 1

FMod for Quake1 CD Playback(MP3)

Posted: Mon May 28, 2012 6:04 pm
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);
}

Re: FMod for Quake1 CD Playback(MP3)

Posted: Tue May 29, 2012 12:02 am
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.

Re: FMod for Quake1 CD Playback(MP3)

Posted: Tue May 29, 2012 6:36 am
by mh
I believe with GPL 3 FMOD should be OK, but beware of this: http://www.fmod.org/index.php/sales/mp3/

Re: FMod for Quake1 CD Playback(MP3)

Posted: Mon Jun 04, 2012 2:51 am
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

Re: FMod for Quake1 CD Playback(MP3)

Posted: Mon Jun 04, 2012 3:28 am
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.

Re: FMod for Quake1 CD Playback(MP3)

Posted: Tue Jun 05, 2012 2:14 am
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.

Re: FMod for Quake1 CD Playback(MP3)

Posted: Tue Jun 05, 2012 3:16 pm
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.