bring back MIDI support for linux plus a few bug fixes

git-svn-id: https://svn.eduke32.com/eduke32@1473 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2009-07-28 06:32:58 +00:00
parent 505d3475ce
commit 71cc476cb8
10 changed files with 476 additions and 55 deletions

View file

@ -165,25 +165,27 @@ ifeq ($(PLATFORM),WINDOWS)
EDITOROBJS+= $(OBJ)/buildres.$o
JAUDIOLIB=libjfaudiolib_win32.a
else
GAMEOBJS+= $(OBJ)/audiolib_musicstub.$o
ifeq ($(RENDERTYPE),SDL)
ifeq (0,$(SDL_FRAMEWORK))
OURCFLAGS+= $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags))
LIBS+= -lSDL_mixer
else
OURCFLAGS += -DSDL_FRAMEWORK
endif
ifeq (1,$(HAVE_GTK2))
OURCFLAGS+= -DHAVE_GTK2 $(shell pkg-config --cflags gtk+-2.0)
GAMEOBJS+= $(OBJ)/game_banner.$o $(OBJ)/startgtk.game.$o
EDITOROBJS+= $(OBJ)/editor_banner.$o
endif
GAMEOBJS+= $(OBJ)/game_icon.$o $(OBJ)/sdlmusic.$o
EDITOROBJS+= $(OBJ)/build_icon.$o
else
GAMEOBJS+= $(OBJ)/audiolib_musicstub.$o
endif
endif
ifeq ($(RENDERTYPE),SDL)
ifeq (0,$(SDL_FRAMEWORK))
OURCFLAGS+= $(subst -Dmain=SDL_main,,$(shell $(SDLCONFIG) --cflags))
else
OURCFLAGS += -DSDL_FRAMEWORK
endif
ifeq (1,$(HAVE_GTK2))
OURCFLAGS+= -DHAVE_GTK2 $(shell pkg-config --cflags gtk+-2.0)
GAMEOBJS+= $(OBJ)/game_banner.$o $(OBJ)/startgtk.game.$o
EDITOROBJS+= $(OBJ)/editor_banner.$o
endif
GAMEOBJS+= $(OBJ)/game_icon.$o
EDITOROBJS+= $(OBJ)/build_icon.$o
endif
EDITOROBJS+= $(OBJ)/sounds_mapster32.$o
OURCFLAGS+= $(BUILDCFLAGS)
@ -261,7 +263,7 @@ $(JAUDIOLIBDIR)/$(JAUDIOLIB):
ifeq ($(PRETTY_OUTPUT),1)
printf "\033[K\033[0;35mChanging dir to \033[1;35m$(CURDIR)/$(JAUDIOLIBDIR)\033[0;35m \033[0m\n"
endif
$(MAKE) -C $(JAUDIOLIBDIR) PRETTY_OUTPUT=$(PRETTY_OUTPUT) EROOT=$(EROOT)
$(MAKE) -C $(JAUDIOLIBDIR) PRETTY_OUTPUT=$(PRETTY_OUTPUT) EROOT=$(EROOT) RELEASE=$(RELEASE) OPTLEVEL=$(OPTLEVEL)
ifeq ($(PRETTY_OUTPUT),1)
printf "\033[K\033[0;35mChanging dir to \033[1;35m$(CURDIR)\033[0;35m \033[0m\n"
endif

View file

@ -452,6 +452,10 @@
RelativePath=".\source\savegame.c"
>
</File>
<File
RelativePath=".\source\sdlmusic.c"
>
</File>
<File
RelativePath=".\source\sector.c"
>

View file

@ -3268,6 +3268,8 @@ static void G_MoveTransports(void)
}
break;
case 4:
if (sectlotag != 0) goto JBOLT;
case 1:
if ((sprite[j].picnum == SHARK) || (sprite[j].picnum == COMMANDER) || (sprite[j].picnum == OCTABRAIN)
|| ((sprite[j].picnum >= GREENSLIME) && (sprite[j].picnum <= GREENSLIME+7)))
@ -3275,7 +3277,6 @@ static void G_MoveTransports(void)
if (sprite[j].extra > 0)
goto JBOLT;
}
// case 4:
case 5:
case 12:
case 13:

View file

@ -3,11 +3,28 @@ OBJ=obj
OBJNAME?=libjfaudiolib.a
PRETTY_OUTPUT?=1
EROOT?=build
RELEASE?=1
OPTLEVEL?=2
SRC=src
include ../../$(EROOT)/Makefile.shared
CFLAGS=-g -O2 -Wall
ifneq (0,$(RELEASE))
# Debugging disabled
debug=-fomit-frame-pointer -funswitch-loops -O$(OPTLEVEL)
else
# Debugging enabled
debug=-ggdb -O0 -DDEBUGGINGAIDS
endif
ifneq (0,$(DEBUGANYWAY))
debug+=-ggdb
endif
CFLAGS=$(debug) -W -Wall -Wimplicit -Werror-implicit-function-declaration \
-funsigned-char -fno-strict-aliasing -DNO_GCC_BUILTINS -D_FORTIFY_SOURCE=2 \
-fjump-tables -fno-stack-protector
CPPFLAGS=-Iinclude -Isrc -DHAVE_VORBIS
OBJECTS=$(OBJ)/drivers.o \
@ -20,7 +37,7 @@ OBJECTS=$(OBJ)/drivers.o \
$(OBJ)/driver_nosound.o
ifeq ($(PLATFORM),WINDOWS)
CPPFLAGS+= -I/z/sdks/directx/dx7/include -Ithird-party/mingw32/include
CPPFLAGS+= -Ithird-party/mingw32/include
OBJECTS+= $(OBJ)/driver_directsound.o
OBJNAME=libjfaudiolib_win32.a
OBJ=obj_win

View file

@ -24,8 +24,13 @@
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include "driver_sdl.h"
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(P) (P)=(P)
#endif
enum {
SDLErr_Warning = -2,
SDLErr_Error = -1,
@ -47,11 +52,18 @@ static int32_t MixBufferCurrent = 0;
static int32_t MixBufferUsed = 0;
static void ( *MixCallBack )( void ) = 0;
static void fillData(void * userdata, Uint8 * ptr, int32_t remaining)
static Mix_Chunk *DummyChunk = NULL;
static uint8_t *DummyBuffer = NULL;
// static int32_t InterruptsDisabled = 0;
static void fillData(int32_t chan, void *ptr, int32_t remaining, void *udata)
{
int32_t len;
char *sptr;
UNREFERENCED_PARAMETER(chan);
UNREFERENCED_PARAMETER(udata);
while (remaining > 0) {
if (MixBufferUsed == MixBufferSize) {
MixCallBack();
@ -123,8 +135,9 @@ const char *SDLDrv_ErrorString( int32_t ErrorNumber )
int32_t SDLDrv_Init(int32_t mixrate, int32_t numchannels, int32_t samplebits, void * initdata)
{
Uint32 inited;
Uint32 err = 0;
SDL_AudioSpec spec;
int32_t err = 0;
UNREFERENCED_PARAMETER(initdata);
if (Initialised) {
SDLDrv_Shutdown();
@ -146,19 +159,30 @@ int32_t SDLDrv_Init(int32_t mixrate, int32_t numchannels, int32_t samplebits, vo
return SDLErr_Error;
}
spec.freq = mixrate;
spec.format = (samplebits == 8) ? AUDIO_U8 : AUDIO_S16SYS;
spec.channels = numchannels;
spec.samples = 256;
spec.callback = fillData;
spec.userdata = 0;
// same problem occurs here as in the icculus driver...
// we need a dummy channel so we don't fuck up the music
// thus numchannels + 1 here
err = Mix_OpenAudio(mixrate, (samplebits == 8) ? AUDIO_U8 : AUDIO_S16SYS, numchannels + 1, 512);
err = SDL_OpenAudio(&spec, NULL);
if (err < 0) {
ErrorCode = SDLErr_OpenAudio;
return SDLErr_Error;
}
//Mix_SetPostMix(fillData, NULL);
// channel 0 and 1 are actual sounds
// dummy channel 2 runs our fillData() callback as an effect
Mix_RegisterEffect(2, fillData, NULL, NULL);
DummyBuffer = (uint8_t *) malloc(sizeof(intptr_t));
memset(DummyBuffer, 0, sizeof(intptr_t));
DummyChunk = Mix_QuickLoad_RAW(DummyBuffer, sizeof(intptr_t));
Mix_PlayChannel(2, DummyChunk, -1);
Initialised = 1;
return SDLErr_Ok;
@ -171,11 +195,39 @@ void SDLDrv_Shutdown(void)
}
if (StartedSDL > 0) {
if (Initialised)
{
Mix_HaltChannel(0);
}
if (DummyChunk != NULL)
{
Mix_FreeChunk(DummyChunk);
}
DummyChunk = NULL;
if (DummyBuffer != NULL)
{
free(DummyBuffer);
}
DummyBuffer = NULL;
if (Initialised)
{
Mix_CloseAudio();
}
Initialised = 0;
SDL_QuitSubSystem(SDL_INIT_AUDIO);
} else if (StartedSDL == 0) {
}
else if (StartedSDL == 0) {
SDL_Quit();
}
StartedSDL = -1;
}
@ -201,7 +253,7 @@ int32_t SDLDrv_BeginPlayback(char *BufferStart, int32_t BufferSize,
// prime the buffer
MixCallBack();
SDL_PauseAudio(0);
Mix_Resume(-1);
Playing = 1;
@ -214,18 +266,28 @@ void SDLDrv_StopPlayback(void)
return;
}
SDL_PauseAudio(1);
Mix_Pause(-1);
Playing = 0;
}
void SDLDrv_Lock(void)
{
SDL_LockAudio();
/*
if (InterruptsDisabled++)
return;
SDL_LockAudio();*/
}
void SDLDrv_Unlock(void)
{
SDL_UnlockAudio();
/*
if (--InterruptsDisabled)
return;
SDL_UnlockAudio();*/
}

View file

@ -95,7 +95,7 @@ static int32_t seek_vorbis(void * datasource, ogg_int64_t offset, int32_t whence
}
vorb->pos += offset;
if (vorb->pos < 0) {
if ((int32_t)vorb->pos < 0) {
vorb->pos = 0;
} else if (vorb->pos > vorb->length) {
vorb->pos = vorb->length;
@ -176,7 +176,7 @@ playbackstatus MV_GetNextVorbisBlock
}
bytesread += bytes;
} while (bytesread < sizeof(vd->block));
} while (bytesread < (signed)sizeof(vd->block));
if (bytesread == 0) {
voice->Playing = FALSE;

View file

@ -48,16 +48,7 @@ static const int32_t _MIDI_CommandLengths[ NUM_MIDI_CHANNELS ] =
0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0
};
static int32_t(*_MIDI_RerouteFunctions[ NUM_MIDI_CHANNELS ])
(
int32_t event,
int32_t c1,
int32_t c2
) =
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
static int32_t (*_MIDI_RerouteFunctions[ NUM_MIDI_CHANNELS ]) ( int32_t event, int32_t c1, int32_t c2 );
static track *_MIDI_TrackPtr = NULL;
static int32_t _MIDI_TrackMemSize;

View file

@ -502,6 +502,8 @@ void G_CacheMapData(void)
}
else continue;
MUSIC_Update();
if ((j&7) == 0)
{
handleevents();
@ -1641,7 +1643,7 @@ int32_t G_FindLevelForFilename(const char *fn)
return ((volume * MAXLEVELS) + level);
}
}
return MAXLEVELS;
return MAXLEVELS*MAXVOLUMES;
}
int32_t G_EnterLevel(int32_t g)
@ -1679,7 +1681,7 @@ int32_t G_EnterLevel(int32_t g)
volume = level = G_FindLevelForFilename(boardfilename);
if (level != MAXLEVELS)
if (level != MAXLEVELS*MAXVOLUMES)
{
level &= MAXLEVELS-1;
volume = (volume - level) / MAXLEVELS;

View file

@ -0,0 +1,342 @@
/*
Copyright (C) 2003-2004 Ryan C. Gordon. and James Bentler
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.
Originally written by Ryan C. Gordon. (icculus@clutteredmind.org)
Adapted to work with JonoF's port by James Bentler (bentler@cs.umn.edu)
*/
/*
* A reimplementation of Jim Dose's FX_MAN routines, using SDL_mixer 1.2.
* Whee. FX_MAN is also known as the "Apogee Sound System", or "ASS" for
* short. How strangely appropriate that seems.
*/
#include <stdio.h>
#include <errno.h>
#include "duke3d.h"
#include "cache1d.h"
#define _NEED_SDLMIXER 1
#include "sdl_inc.h"
#include "music.h"
int32_t MUSIC_ErrorCode = MUSIC_Ok;
static char warningMessage[80];
static char errorMessage[80];
static int32_t external_midi = 0;
static int32_t music_initialized = 0;
static int32_t music_context = 0;
static int32_t music_loopflag = MUSIC_PlayOnce;
static Mix_Music *music_musicchunk = NULL;
static void setErrorMessage(const char *msg)
{
Bstrncpy(errorMessage, msg, sizeof(errorMessage));
// strncpy() doesn't add the null char if there isn't room...
errorMessage[sizeof(errorMessage) - 1] = '\0';
} // setErrorMessage
// The music functions...
char *MUSIC_ErrorString(int32_t ErrorNumber)
{
switch (ErrorNumber)
{
case MUSIC_Warning:
return(warningMessage);
case MUSIC_Error:
return(errorMessage);
case MUSIC_Ok:
return("OK; no error.");
case MUSIC_ASSVersion:
return("Incorrect sound library version.");
case MUSIC_SoundCardError:
return("General sound card error.");
case MUSIC_InvalidCard:
return("Invalid sound card.");
case MUSIC_MidiError:
return("MIDI error.");
case MUSIC_MPU401Error:
return("MPU401 error.");
case MUSIC_TaskManError:
return("Task Manager error.");
//case MUSIC_FMNotDetected:
// return("FM not detected error.");
case MUSIC_DPMI_Error:
return("DPMI error.");
default:
return("Unknown error.");
} // switch
return(NULL);
} // MUSIC_ErrorString
int32_t MUSIC_Init(int32_t SoundCard, int32_t Address)
{
// Use an external MIDI player if the user has specified to do so
char *command = getenv("EDUKE32_MUSIC_CMD");
const SDL_version *linked = Mix_Linked_Version();
UNREFERENCED_PARAMETER(Address);
if (SDL_VERSIONNUM(linked->major,linked->minor,linked->patch) < MIX_REQUIREDVERSION)
{
// reject running with SDL_Mixer versions older than what is stated in sdl_inc.h
initprintf("You need at least v%d.%d.%d of SDL_mixer for music\n",SDL_MIXER_MIN_X,SDL_MIXER_MIN_Y,SDL_MIXER_MIN_Z);
return(MUSIC_Error);
}
external_midi = (command != NULL && command[0] != 0);
if (external_midi)
Mix_SetMusicCMD(command);
else
{
char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" };
FILE *fp;
uint32_t i;
for (i = 0; i < sizeof(s)/sizeof(s[0]); i++)
{
fp = fopen(s[i], "r");
if (fp == NULL)
{
if (i == sizeof(s)/sizeof(s[0]))
{
initprintf("Error opening %s, %s or %s\n",s[0],s[1],s[2]);
return(MUSIC_Error);
}
continue;
}
else break;
}
Bfclose(fp);
}
if (music_initialized)
{
setErrorMessage("Music system is already initialized.");
return(MUSIC_Error);
} // if
SoundCard = 1;
music_initialized = 1;
return(MUSIC_Ok);
} // MUSIC_Init
int32_t MUSIC_Shutdown(void)
{
// TODO - make sure this is being called from the menu -- SA
if (external_midi)
Mix_SetMusicCMD(NULL);
MUSIC_StopSong();
music_context = 0;
music_initialized = 0;
music_loopflag = MUSIC_PlayOnce;
return(MUSIC_Ok);
} // MUSIC_Shutdown
void MUSIC_SetMaxFMMidiChannel(int32_t channel)
{
UNREFERENCED_PARAMETER(channel);
} // MUSIC_SetMaxFMMidiChannel
void MUSIC_SetVolume(int32_t volume)
{
volume = max(0, volume);
volume = min(volume, 255);
Mix_VolumeMusic(volume >> 1); // convert 0-255 to 0-128.
} // MUSIC_SetVolume
void MUSIC_SetMidiChannelVolume(int32_t channel, int32_t volume)
{
UNREFERENCED_PARAMETER(channel);
UNREFERENCED_PARAMETER(volume);
} // MUSIC_SetMidiChannelVolume
void MUSIC_ResetMidiChannelVolumes(void)
{
} // MUSIC_ResetMidiChannelVolumes
int32_t MUSIC_GetVolume(void)
{
return(Mix_VolumeMusic(-1) << 1); // convert 0-128 to 0-255.
} // MUSIC_GetVolume
void MUSIC_SetLoopFlag(int32_t loopflag)
{
music_loopflag = loopflag;
} // MUSIC_SetLoopFlag
int32_t MUSIC_SongPlaying(void)
{
return((Mix_PlayingMusic()) ? TRUE : FALSE);
} // MUSIC_SongPlaying
void MUSIC_Continue(void)
{
if (Mix_PausedMusic())
Mix_ResumeMusic();
} // MUSIC_Continue
void MUSIC_Pause(void)
{
Mix_PauseMusic();
} // MUSIC_Pause
int32_t MUSIC_StopSong(void)
{
//if (!fx_initialized)
if (!Mix_QuerySpec(NULL, NULL, NULL))
{
setErrorMessage("Need FX system initialized, too. Sorry.");
return(MUSIC_Error);
} // if
if ((Mix_PlayingMusic()) || (Mix_PausedMusic()))
Mix_HaltMusic();
if (music_musicchunk)
Mix_FreeMusic(music_musicchunk);
music_musicchunk = NULL;
return(MUSIC_Ok);
} // MUSIC_StopSong
// Duke3D-specific. --ryan.
// void MUSIC_PlayMusic(char *_filename)
int32_t MUSIC_PlaySong(char *song, int32_t loopflag)
{
MUSIC_StopSong();
music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem((char *) song, g_musicSize));
if (music_musicchunk != NULL)
{
Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0);
}
return MUSIC_Ok;
}
void MUSIC_SetContext(int32_t context)
{
music_context = context;
} // MUSIC_SetContext
int32_t MUSIC_GetContext(void)
{
return(music_context);
} // MUSIC_GetContext
void MUSIC_SetSongTick(uint32_t PositionInTicks)
{
UNREFERENCED_PARAMETER(PositionInTicks);
} // MUSIC_SetSongTick
void MUSIC_SetSongTime(uint32_t milliseconds)
{
UNREFERENCED_PARAMETER(milliseconds);
}// MUSIC_SetSongTime
void MUSIC_SetSongPosition(int32_t measure, int32_t beat, int32_t tick)
{
UNREFERENCED_PARAMETER(measure);
UNREFERENCED_PARAMETER(beat);
UNREFERENCED_PARAMETER(tick);
} // MUSIC_SetSongPosition
void MUSIC_GetSongPosition(songposition *pos)
{
UNREFERENCED_PARAMETER(pos);
} // MUSIC_GetSongPosition
void MUSIC_GetSongLength(songposition *pos)
{
UNREFERENCED_PARAMETER(pos);
} // MUSIC_GetSongLength
int32_t MUSIC_FadeVolume(int32_t tovolume, int32_t milliseconds)
{
UNREFERENCED_PARAMETER(tovolume);
Mix_FadeOutMusic(milliseconds);
return(MUSIC_Ok);
} // MUSIC_FadeVolume
int32_t MUSIC_FadeActive(void)
{
return((Mix_FadingMusic() == MIX_FADING_OUT) ? TRUE : FALSE);
} // MUSIC_FadeActive
void MUSIC_StopFade(void)
{
} // MUSIC_StopFade
void MUSIC_RerouteMidiChannel(int32_t channel, int32_t (*function)(int32_t event, int32_t c1, int32_t c2))
{
UNREFERENCED_PARAMETER(channel);
UNREFERENCED_PARAMETER(function);
} // MUSIC_RerouteMidiChannel
void MUSIC_RegisterTimbreBank(char *timbres)
{
UNREFERENCED_PARAMETER(timbres);
} // MUSIC_RegisterTimbreBank
void MUSIC_Update(void)
{}

View file

@ -324,7 +324,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel)
// let's see if there's an ogg with the same base name
// lying around
strcpy(extension, ".ogg");
fp = kopen4load(testfn, 0);
fp = kopen4loadfrommod(testfn, 0);
if (fp >= 0)
{
free(testfn);
@ -334,7 +334,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel)
free(testfn);
// just use what we've been given
fp = kopen4load((char *)fn, 0);
fp = kopen4loadfrommod((char *)fn, 0);
}
while (0);
@ -342,7 +342,7 @@ int32_t S_PlayMusic(const char *fn, const int32_t sel)
S_StopMusic();
MusicLen = kfilelength(fp);
g_musicSize = MusicLen = kfilelength(fp);
MusicPtr = (char *) Bmalloc(MusicLen);
kread(fp, MusicPtr, MusicLen);
kclose(fp);
@ -376,7 +376,7 @@ void S_StopMusic(void)
{
Bfree(MusicPtr);
MusicPtr = 0;
MusicLen = 0;
g_musicSize = MusicLen = 0;
}
}
@ -635,7 +635,7 @@ int32_t A_PlaySound(uint32_t num, int32_t i)
return S_PlaySoundXYZ(num, i, (vec3_t *)&sprite[i]);
}
inline void S_StopSound(int32_t num)
void S_StopSound(int32_t num)
{
if (num >= 0 && num < MAXSOUNDS && g_sounds[num].num > 0)
{