From 39940fe20acbd3b2f0ebc6bd94d4c84c28653085 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 27 Mar 2008 04:25:52 +0000 Subject: [PATCH] - Added FMOD_OPENONLY to the callback version of CreateStream() to prevent it from doing prebuffering of the song. This was causing the Linux version to hang while waiting for input from the pipe, since Timidity hadn't been started yet. I tried using a select call in the FillStream() method, but it always seems to return the pipe as having nothing available. Unfortunately, the game still falls all over itself if Timidity isn't available. Instead of execvp failing nicely, X errors kill the game. I don't know why it's doing that. My advice for Linux music: Skip Timidity++ and get a DLS patch set (/WINDOWS/system32/drivers/gm.dls is probably the most common by far) and set the snd_midipatchset cvar to point to it. It's faster and also sounds a whole lot better than the crappy freepats Ubuntu wants to install with Timidity++. - GCC fixes. SVN r858 (trunk) --- Makefile.linux | 7 +++-- docs/rh-log.txt | 18 ++++++++++- src/d_main.cpp | 15 ++++++++- src/p_switch.cpp | 3 +- src/p_xlat.cpp | 2 +- src/r_anim.cpp | 4 +-- src/r_interpolate.h | 3 +- src/s_sndseq.cpp | 2 +- src/sound/fmodsound.cpp | 2 +- src/sound/i_music.cpp | 7 +---- src/sound/music_midi_timidity.cpp | 52 +++++++++++++++++++++++-------- src/sound/music_stream.cpp | 11 +++++-- 12 files changed, 93 insertions(+), 33 deletions(-) diff --git a/Makefile.linux b/Makefile.linux index aa0cb0336..d4b32152c 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -1,5 +1,6 @@ # created on 4/12/2006 by James Bentler - + +FMOD_PREFIX = /usr/local CXX ?= g++ CC ?= gcc NASM ?= nasm @@ -16,13 +17,13 @@ endif #endif CFLAGS += -MMD -DHAVE_FILELENGTH -D__forceinline=inline `sdl-config --cflags` `pkg-config gtk+-2.0 --cflags` CFLAGS += -Dstricmp=strcasecmp -Dstrnicmp=strncasecmp -DNEED_STRUPR -LDFLAGS += -lz -ljpeg -lfmodex `sdl-config --libs` `pkg-config gtk+-2.0 --libs` +LDFLAGS += -lz -ljpeg -`sdl-config --libs` `pkg-config gtk+-2.0 --libs` $(FMOD_PREFIX)/lib/libfmodex.so NASMFLAGS += -f elf -DM_TARGET_LINUX SRCDIRS = src/ $(addprefix src/,g_doom/ g_heretic/ g_hexen/ g_raven/ g_shared/ g_strife/ oplsynth/ sound/ sdl/ textures/ thingdef/ xlat/) VPATH = $(SRCDIRS) INCLUDES = $(addprefix -I,$(SRCDIRS)) -INCLUDES += -Isnes_spc/snes_spc/ -I/usr/include/fmodex/ +INCLUDES += -Isnes_spc/snes_spc/ -I$(FMOD_PREFIX)/include/fmodex/ CFLAGS += $(INCLUDES) RELEASEOBJ ?= releaseobj diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 06a177399..02a895112 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,19 @@ +March 26, 2008 +- Added FMOD_OPENONLY to the callback version of CreateStream() to prevent it + from doing prebuffering of the song. This was causing the Linux version to + hang while waiting for input from the pipe, since Timidity hadn't been + started yet. I tried using a select call in the FillStream() method, but it + always seems to return the pipe as having nothing available. Unfortunately, + the game still falls all over itself if Timidity isn't available. Instead + of execvp failing nicely, X errors kill the game. I don't know why it's + doing that. My advice for Linux music: Skip Timidity++ and get a DLS patch + set (/WINDOWS/system32/drivers/gm.dls is probably the most common by far) + and set the snd_midipatchset cvar to point to it. It's faster and also + sounds a whole lot better than the crappy freepats Ubuntu wants to install + with Timidity++ (thank goodness I have the official patches from a real + GUS so I don't need to use them). +- GCC fixes. + March 26, 2008 (Changes by Graf Zahl) - Fixed: After starting new music the music volume has to be reset so that the song's relative volume takes effect. @@ -16,7 +32,7 @@ March 25, 2008 - Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the default device. By default, it uses exactly the same DLS instruments as the Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set - you want to use, set the snd_midipatchfile cvar to specify where it should + you want to use, set the snd_midipatchset cvar to specify where it should load the instruments from. - Changed the ProduceMIDI function to store its output into a TArray. An overloaded version wraps around it to continue to supply file-writing diff --git a/src/d_main.cpp b/src/d_main.cpp index f6417657d..7841fa5ba 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -242,7 +242,20 @@ static const char *IWADNames[] = "hexen.wad", "hexdd.wad", "strife1.wad", - "strife0.wad", + "strife0.wad", +#ifdef unix + "DOOM2.WAD", // Also look for all-uppercase names + "PLUTONIA.WAD", + "TNT.WAD", + "DOOM.WAD", + "DOOM1.WAD", + "HERETIC.WAD", + "HERETIC1.WAD", + "HEXEN.WAD", + "HEXDD.WAD", + "STRIFE1.WAD", + "STRIFE0.WAD", +#endif NULL }; diff --git a/src/p_switch.cpp b/src/p_switch.cpp index 91f1efe28..f94b55305 100644 --- a/src/p_switch.cpp +++ b/src/p_switch.cpp @@ -370,7 +370,8 @@ FSwitchDef *ParseSwitchDef (FScanner &sc, bool ignoreBad) thisframe.Time = ((max - min + 1) << 16) | min; } else - { + { + thisframe.Time = 0; // Shush, GCC. sc.ScriptError ("Must specify a duration for switch frame"); } frames.Push(thisframe); diff --git a/src/p_xlat.cpp b/src/p_xlat.cpp index 7eafaa067..5a5b48102 100644 --- a/src/p_xlat.cpp +++ b/src/p_xlat.cpp @@ -343,7 +343,7 @@ int P_TranslateSectorSpecial (int special) } } - if (special>=0 && specialName, tex1->GetSourceLump(), Wads.GetLumpFile(tex1->GetSourceLump()), - tex2->Name, tex2->GetSourceLump(), Wads.GetLumpFile(tex2->GetSourceLump())); + tex1->Name, pic1, tex1->GetSourceLump(), Wads.GetLumpFile(tex1->GetSourceLump()), + tex2->Name, pic2, tex2->GetSourceLump(), Wads.GetLumpFile(tex2->GetSourceLump())); } /* FIXME: doesn't work with hires texture replacements. diff --git a/src/r_interpolate.h b/src/r_interpolate.h index 3820cb686..14b867268 100644 --- a/src/r_interpolate.h +++ b/src/r_interpolate.h @@ -61,4 +61,5 @@ void restoreinterpolations(); void clearinterpolations(); void SerializeInterpolations(FArchive &arc); -#endif \ No newline at end of file +#endif + diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index 53d335a0c..2af2d4bb1 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -502,7 +502,7 @@ void S_ParseSndSeq (int levellump) FScanner sc(lump, "SNDSEQ"); while (sc.GetString ()) { - bool bDoorSound; + bool bDoorSound = false; if (*sc.String == ':' || *sc.String == '[') { diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index c89aae99a..d06253401 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -942,7 +942,7 @@ SoundStream *FMODSoundRenderer::CreateStream (SoundStreamCallback callback, int capsule = new FMODStreamCapsule (userdata, callback, this); - mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_SOFTWARE | FMOD_CREATESTREAM; + mode = FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_SOFTWARE | FMOD_CREATESTREAM | FMOD_OPENONLY; sample_shift = (flags & SoundStream::Bits8) ? 0 : 1; channel_shift = (flags & SoundStream::Mono) ? 0 : 1; diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index 6f3438552..b2ad10cf8 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -335,7 +335,7 @@ void *I_RegisterSong (const char *filename, char *musiccache, int offset, int le { BYTE *mus = new BYTE[len]; size_t did_read = fread(mus, 1, len, file); - if (did_read == len) + if (did_read == (size_t)len) { midi_made = ProduceMIDI(mus, midi); } @@ -344,11 +344,6 @@ void *I_RegisterSong (const char *filename, char *musiccache, int offset, int le } if (midi_made) { - /* - FILE *f = fopen("latest.mid", "wb"); - fwrite(&midi[0], 1, midi.Size(), f); - fclose(f); - */ info = new StreamSong((char *)&midi[0], -1, midi.Size()); if (!info->IsValid()) { diff --git a/src/sound/music_midi_timidity.cpp b/src/sound/music_midi_timidity.cpp index 3f45d1654..c8ab55e02 100644 --- a/src/sound/music_midi_timidity.cpp +++ b/src/sound/music_midi_timidity.cpp @@ -244,6 +244,7 @@ TimiditySong::TimiditySong (FILE *file, char * musiccache, int len) void TimiditySong::PrepTimidity () { int pipeSize; + #ifdef _WIN32 static SECURITY_ATTRIBUTES inheritable = { sizeof(inheritable), NULL, TRUE }; @@ -267,6 +268,11 @@ void TimiditySong::PrepTimidity () pipeSize = (timidity_pipe * timidity_frequency / 1000) << (timidity_stereo + !timidity_8bit); + + if (GSnd == NULL) + { // Can't pipe if using no sound. + pipeSize = 0; + } if (pipeSize != 0) { @@ -520,11 +526,11 @@ bool TimiditySong::LaunchTimidity () close (WavePipe[0]); dup2 (WavePipe[1], STDOUT_FILENO); freopen ("/dev/null", "r", stdin); - freopen ("/dev/null", "w", stderr); +// freopen ("/dev/null", "w", stderr); close (WavePipe[1]); - printf ("exec %s\n", words.we_wordv[0]); - execvp (words.we_wordv[0], words.we_wordv); + execvp (words.we_wordv[0], words.we_wordv); + fprintf(stderr,"execvp failed\n"); exit (0); // if execvp succeeds, we never get here } else if (forkres < 0) @@ -536,7 +542,12 @@ bool TimiditySong::LaunchTimidity () // printf ("child is %d\n", forkres); ChildProcess = forkres; close (WavePipe[1]); - WavePipe[1] = -1; + WavePipe[1] = -1; +/* usleep(1000000); + if (waitpid(ChildProcess, NULL, WNOHANG) == ChildProcess) + { + fprintf(stderr,"Launching timidity failed\n"); + }*/ } wordfree (&words); @@ -575,21 +586,36 @@ bool TimiditySong::FillStream (SoundStream *stream, void *buff, int len, void *u } } #else - ssize_t got; + ssize_t got; + fd_set rfds; + struct timeval tv; + + if (ChildQuit == song->ChildProcess) + { + ChildQuit = 0; + fprintf (stderr, "child gone\n"); + song->ChildProcess = -1; + return false; + } + + FD_ZERO(&rfds); + FD_SET(song->WavePipe[0], &rfds); + tv.tv_sec = 0; + tv.tv_usec = 50; +// fprintf(stderr,"select\n"); + if (select(1, &rfds, NULL, NULL, &tv) <= 0 && 0) + { // Nothing available, so play silence. +// fprintf(stderr,"nothing\n"); + // memset(buff, 0, len); + return true; + } +// fprintf(stderr,"something\n"); got = read (song->WavePipe[0], (BYTE *)buff, len); if (got < len) { memset ((BYTE *)buff+got, 0, len-got); } - - if (ChildQuit == song->ChildProcess) - { - ChildQuit = 0; -// printf ("child gone\n"); - song->ChildProcess = -1; - return false; - } #endif return true; } diff --git a/src/sound/music_stream.cpp b/src/sound/music_stream.cpp index e6fdea535..19ff431f3 100644 --- a/src/sound/music_stream.cpp +++ b/src/sound/music_stream.cpp @@ -50,8 +50,15 @@ StreamSong::~StreamSong () } StreamSong::StreamSong (const char *filename_or_data, int offset, int len) -{ - m_Stream = GSnd->OpenStream (filename_or_data, SoundStream::Loop, offset, len); +{ + if (GSnd != NULL) + { + m_Stream = GSnd->OpenStream (filename_or_data, SoundStream::Loop, offset, len); + } + else + { + m_Stream = NULL; + } } bool StreamSong::IsPlaying ()