mirror of
https://github.com/ZDoom/gzdoom-last-svn.git
synced 2025-06-04 19:20:53 +00:00
- 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. - Fixed: After starting new music the music volume has to be reset so that the song's relative volume takes effect. - Removed the arbitrary 1024 bytes limit when the file being played is a MIDI file. I had a D_DM2TTL that's only 990 bytes. - Restructured I_RegisterSong so that $mididevice works again and also supports selecting FMOD. - Added Jim' Linux fix. - Added MartinHowe's fix for mugshot display in status bars. - The garbage collector is now run one last time just before exiting the game. - Removed movie volume from the sound menu and renamed some of the other options to give the MIDI device name more room to display itself. - Moved the midi device selection into the main sound menu. - 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_midipatchset cvar to specify where it should load the instruments from. - Changed the ProduceMIDI function to store its output into a TArray<BYTE>. An overloaded version wraps around it to continue to supply file-writing support for external Timidity++ usage. - Added an FMOD credits banner to comply with their non-commercial license. - Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather than a time in ms, this is now the length in samples of the DSP buffer. Also added the snd_buffercount cvar to offer complete control over the call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate below about 44kHz, you will need to set snd_buffersize to avoid long latencies. - Reimplemented the snd_output cvar for the FMOD Ex sound system. - Changed snd_samplerate default to 0. This now means to use the default sample rate. - Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and snd_hrtf available through the menu. - Split the HRTF effect selection into its own cvar: snd_hrtf. - Removed 96000 Hz option from the menu. It's still available through the cvar, if desired. - Fixed: If Windows sound init failed, retry with DirectSound. (Apparently, WASAPI doesn't work with more than two speakers and PCM-Float output at the same time.) - Fixed: Area sounds only played from the front speakers once you got within the 2D panning area. git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@79 b0f79afe-0144-0410-b225-9a4edf0717df
173 lines
4.4 KiB
C++
173 lines
4.4 KiB
C++
/*
|
|
** music_modplug.cpp
|
|
**
|
|
** MOD playback using libmodplug
|
|
**
|
|
**---------------------------------------------------------------------------
|
|
** Copyright 2007 Christoph Oelckers
|
|
** All rights reserved.
|
|
**
|
|
** Redistribution and use in source and binary forms, with or without
|
|
** modification, are permitted provided that the following conditions
|
|
** are met:
|
|
**
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
** notice, this list of conditions and the following disclaimer.
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
** documentation and/or other materials provided with the distribution.
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
** derived from this software without specific prior written permission.
|
|
**
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
**---------------------------------------------------------------------------
|
|
**
|
|
*/
|
|
|
|
#include "i_musicinterns.h"
|
|
#include "templates.h"
|
|
#include "c_cvars.h"
|
|
#include "doomdef.h"
|
|
#include "modplug/modplug.h"
|
|
|
|
// 192 approximately replicates the volume of a WinAmp Wave export of the song.
|
|
CVAR(Int, snd_mod_mastervolume, 192, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
class ModPlugSong : public StreamSong
|
|
{
|
|
|
|
public:
|
|
~ModPlugSong ();
|
|
bool IsPlaying ();
|
|
bool SetPosition (int order);
|
|
void Play(bool);
|
|
|
|
static bool FillStream (SoundStream *stream, void *buff, int len, void *userdata);
|
|
ModPlugSong (ModPlugFile *dat);
|
|
|
|
ModPlugFile * Data;
|
|
int order;
|
|
};
|
|
|
|
|
|
StreamSong *ModPlugSong_Create (FILE *iofile, char * musiccache, int len)
|
|
{
|
|
char *buffer;
|
|
|
|
if (iofile != NULL)
|
|
{
|
|
buffer = new char[len];
|
|
fread(buffer, 1, len, iofile);
|
|
}
|
|
else buffer = musiccache;
|
|
|
|
ModPlugFile *Data = ModPlug_Load(buffer, len);
|
|
|
|
if (iofile != NULL) delete buffer;
|
|
if (Data == NULL) return NULL;
|
|
|
|
ModPlugSong *ret = new ModPlugSong(Data);
|
|
if (!ret->IsValid())
|
|
{
|
|
ModPlug_Unload(Data);
|
|
delete ret;
|
|
return NULL;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
ModPlugSong::ModPlugSong (ModPlugFile *dat)
|
|
{
|
|
Data = NULL;
|
|
order = 0;
|
|
|
|
m_Stream = GSnd->CreateStream (FillStream, 16384, 0, 44100, this);
|
|
if (m_Stream == NULL)
|
|
{
|
|
Printf (PRINT_BOLD, "Could not create music stream.\n");
|
|
return;
|
|
}
|
|
|
|
// For some reason the sound will stutter if Data is set before creating the stream.
|
|
Data = dat;
|
|
ModPlug_SetMasterVolume(Data, snd_mod_mastervolume);
|
|
}
|
|
|
|
ModPlugSong::~ModPlugSong ()
|
|
{
|
|
Stop ();
|
|
if (Data != NULL) ModPlug_Unload(Data);
|
|
Data = NULL;
|
|
}
|
|
|
|
bool ModPlugSong::IsPlaying ()
|
|
{
|
|
return m_Status == STATE_Playing;
|
|
}
|
|
|
|
void ModPlugSong::Play(bool looping)
|
|
{
|
|
ModPlug_Settings settings;
|
|
ModPlug_GetSettings(&settings);
|
|
settings.mLoopCount=looping? -1:0;
|
|
ModPlug_SetSettings(&settings);
|
|
StreamSong::Play(looping);
|
|
}
|
|
|
|
bool ModPlugSong::SetPosition (int order)
|
|
{
|
|
this->order = order;
|
|
ModPlug_SeekOrder(Data, order);
|
|
return true;
|
|
}
|
|
|
|
bool ModPlugSong::FillStream (SoundStream *stream, void *buf, int len, void *userdata)
|
|
{
|
|
char *buff = (char *)buf;
|
|
ModPlugSong *song = (ModPlugSong *)userdata;
|
|
|
|
if (song->Data == NULL)
|
|
{
|
|
memset(buff, 0, len);
|
|
return true;
|
|
}
|
|
|
|
int read = ModPlug_Read(song->Data, buff, len);
|
|
|
|
if (read < len)
|
|
{
|
|
buff += read;
|
|
len -= read;
|
|
if (song->m_Looping)
|
|
{
|
|
ModPlug_SeekOrder(song->Data, song->order);
|
|
read = ModPlug_Read(song->Data, buff, len);
|
|
if (read < len)
|
|
{
|
|
memset(buff+read, 0, len-read);
|
|
}
|
|
return true;
|
|
}
|
|
if (len > 0)
|
|
{
|
|
memset(buff+read, 0, len-read);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
song->Stop();
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|