- extended $mididevice to add an optional parameter, which has the following meaning for the different MIDI devices:

* OPL: specify the core to use for playing this song
* FluidSynth: specify a soundfont that should be used for playing the song.
* WildMidi: specify a config file that should be used for playing the song.
* Timidity++: specify an executable that should be used for playing the song. At least under Windows this allows using Timidity++ with different configs if the executable and each single config are placed in different directories.
* GUS: currently not operational, but should later also specify the config. This will need some work, because right now this is initialized only when the sound system is initialized.
* all other: no function.

These options should mainly be for end users who want to fine-tune how to play the music.
This commit is contained in:
Christoph Oelckers 2015-12-31 23:03:53 +01:00
parent 1316120fe4
commit 5e975ac9f6
21 changed files with 135 additions and 79 deletions

View file

@ -48,6 +48,7 @@
#define HALF_PI (PI*0.5)
EXTERN_CVAR(Int, opl_core)
extern int current_opl_core;
OPLio::~OPLio()
{
@ -323,7 +324,7 @@ int OPLio::OPLinit(uint numchips, bool stereo, bool initopl3)
{
assert(numchips >= 1 && numchips <= countof(chips));
uint i;
IsOPL3 = (opl_core == 1 || opl_core == 2 || opl_core == 3);
IsOPL3 = (current_opl_core == 1 || current_opl_core == 2 || current_opl_core == 3);
memset(chips, 0, sizeof(chips));
if (IsOPL3)
@ -332,7 +333,7 @@ int OPLio::OPLinit(uint numchips, bool stereo, bool initopl3)
}
for (i = 0; i < numchips; ++i)
{
OPLEmul *chip = IsOPL3 ? (opl_core == 1 ? DBOPLCreate(stereo) : (opl_core == 2 ? JavaOPLCreate(stereo) : NukedOPL3Create(stereo))) : YM3812Create(stereo);
OPLEmul *chip = IsOPL3 ? (current_opl_core == 1 ? DBOPLCreate(stereo) : (current_opl_core == 2 ? JavaOPLCreate(stereo) : NukedOPL3Create(stereo))) : YM3812Create(stereo);
if (chip == NULL)
{
break;

View file

@ -53,6 +53,7 @@
#endif
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void OPL_SetCore(const char *args);
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
@ -76,8 +77,9 @@ CVAR(Bool, opl_fullpan, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
//
//==========================================================================
OPLMIDIDevice::OPLMIDIDevice()
OPLMIDIDevice::OPLMIDIDevice(const char *args)
{
OPL_SetCore(args);
FullPan = opl_fullpan;
FWadLump data = Wads.OpenLumpName("GENMIDI");
OPLloadBank(data);

View file

@ -262,6 +262,7 @@ protected:
//==========================================================================
OPLDumperMIDIDevice::OPLDumperMIDIDevice(const char *filename)
: OPLMIDIDevice(NULL)
{
// Replace the standard OPL device with a disk writer.
delete io;

View file

@ -1364,16 +1364,36 @@ static void S_AddSNDINFO (int lump)
case SI_MidiDevice: {
sc.MustGetString();
FName nm = sc.String;
FScanner::SavedPos save = sc.SavePos();
sc.SetCMode(true);
sc.MustGetString();
if (sc.Compare("timidity")) MidiDevices[nm] = MDEV_TIMIDITY;
else if (sc.Compare("fmod") || sc.Compare("sndsys")) MidiDevices[nm] = MDEV_SNDSYS;
else if (sc.Compare("standard")) MidiDevices[nm] = MDEV_MMAPI;
else if (sc.Compare("opl")) MidiDevices[nm] = MDEV_OPL;
else if (sc.Compare("default")) MidiDevices[nm] = MDEV_DEFAULT;
else if (sc.Compare("fluidsynth")) MidiDevices[nm] = MDEV_FLUIDSYNTH;
else if (sc.Compare("gus")) MidiDevices[nm] = MDEV_GUS;
else if (sc.Compare("wildmidi")) MidiDevices[nm] = MDEV_WILDMIDI;
MidiDeviceSetting devset;
if (sc.Compare("timidity")) devset.device = MDEV_TIMIDITY;
else if (sc.Compare("fmod") || sc.Compare("sndsys")) devset.device = MDEV_SNDSYS;
else if (sc.Compare("standard")) devset.device = MDEV_MMAPI;
else if (sc.Compare("opl")) devset.device = MDEV_OPL;
else if (sc.Compare("default")) devset.device = MDEV_DEFAULT;
else if (sc.Compare("fluidsynth")) devset.device = MDEV_FLUIDSYNTH;
else if (sc.Compare("gus")) devset.device = MDEV_GUS;
else if (sc.Compare("wildmidi")) devset.device = MDEV_WILDMIDI;
else sc.ScriptError("Unknown MIDI device %s\n", sc.String);
if (sc.CheckString(","))
{
sc.SetCMode(false);
sc.MustGetString();
devset.args = sc.String;
}
else
{
// This does not really do what one might expect, because the next token has already been parsed and can be a '$'.
// So in order to continue parsing without C-Mode, we need to reset and parse the last token again.
sc.SetCMode(false);
sc.RestorePos(save);
sc.MustGetString();
}
MidiDevices[nm] = devset;
}
break;

View file

@ -2421,11 +2421,8 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
{
int lumpnum = -1;
int length = 0;
int device = MDEV_DEFAULT;
MusInfo *handle = NULL;
int *devp = MidiDevices.CheckKey(musicname);
if (devp != NULL) device = *devp;
MidiDeviceSetting *devp = MidiDevices.CheckKey(musicname);
// Strip off any leading file:// component.
if (strncmp(musicname, "file://", 7) == 0)
@ -2495,7 +2492,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force)
}
else
{
mus_playing.handle = I_RegisterSong (reader, device);
mus_playing.handle = I_RegisterSong (reader, devp);
}
}

View file

@ -397,8 +397,19 @@ enum EMidiDevice
MDEV_WILDMIDI = 6,
};
struct MidiDeviceSetting
{
int device;
FString args;
MidiDeviceSetting()
{
device = MDEV_DEFAULT;
}
};
typedef TMap<FName, FName> MusicAliasMap;
typedef TMap<FName, int> MidiDeviceMap;
typedef TMap<FName, MidiDeviceSetting> MidiDeviceMap;
extern MusicAliasMap MusicAliases;
extern MidiDeviceMap MidiDevices;

View file

@ -311,21 +311,21 @@ MusInfo *MusInfo::GetWaveDumper(const char *filename, int rate)
//
//==========================================================================
static MIDIStreamer *CreateMIDIStreamer(FileReader &reader, EMidiDevice devtype, EMIDIType miditype)
static MIDIStreamer *CreateMIDIStreamer(FileReader &reader, EMidiDevice devtype, EMIDIType miditype, const char *args)
{
switch (miditype)
{
case MIDI_MUS:
return new MUSSong2(reader, devtype);
return new MUSSong2(reader, devtype, args);
case MIDI_MIDI:
return new MIDISong2(reader, devtype);
return new MIDISong2(reader, devtype, args);
case MIDI_HMI:
return new HMISong(reader, devtype);
return new HMISong(reader, devtype, args);
case MIDI_XMI:
return new XMISong(reader, devtype);
return new XMISong(reader, devtype, args);
default:
return NULL;
@ -387,7 +387,7 @@ static EMIDIType IdentifyMIDIType(DWORD *id, int size)
//
//==========================================================================
MusInfo *I_RegisterSong (FileReader *reader, int device)
MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device)
{
MusInfo *info = NULL;
const char *fmt;
@ -405,12 +405,6 @@ MusInfo *I_RegisterSong (FileReader *reader, int device)
return 0;
}
#ifndef _WIN32
// non-Windows platforms don't support MDEV_MMAPI so map to MDEV_SNDSYS
if (device == MDEV_MMAPI)
device = MDEV_SNDSYS;
#endif
// Check for gzip compression. Some formats are expected to have players
// that can handle it, so it simplifies things if we make all songs
// gzippable.
@ -447,10 +441,15 @@ MusInfo *I_RegisterSong (FileReader *reader, int device)
EMIDIType miditype = IdentifyMIDIType(id, sizeof(id));
if (miditype != MIDI_NOTMIDI)
{
EMidiDevice devtype = (EMidiDevice)device;
EMidiDevice devtype = device == NULL? MDEV_DEFAULT : (EMidiDevice)device->device;
#ifndef _WIN32
// non-Windows platforms don't support MDEV_MMAPI so map to MDEV_SNDSYS
if (devtype == MDEV_MMAPI)
devtype = MDEV_SNDSYS;
#endif
retry_as_sndsys:
info = CreateMIDIStreamer(*reader, devtype, miditype);
info = CreateMIDIStreamer(*reader, devtype, miditype, device != NULL? device->args.GetChars() : "");
if (info != NULL && !info->IsValid())
{
delete info;
@ -464,7 +463,7 @@ retry_as_sndsys:
#ifdef _WIN32
if (info == NULL && devtype != MDEV_MMAPI && snd_mididevice >= 0)
{
info = CreateMIDIStreamer(*reader, MDEV_MMAPI, miditype);
info = CreateMIDIStreamer(*reader, MDEV_MMAPI, miditype, "");
}
#endif
}
@ -475,7 +474,7 @@ retry_as_sndsys:
(id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL
(id[0] == MAKE_ID('A','D','L','I') && *((BYTE *)id + 4) == 'B')) // Martin Fernandez's modified IMF
{
info = new OPLMUSSong (*reader);
info = new OPLMUSSong (*reader, device != NULL? device->args.GetChars() : "");
}
// Check for game music
else if ((fmt = GME_CheckFormat(id[0])) != NULL && fmt[0] != '\0')

View file

@ -53,7 +53,8 @@ void I_SetMusicVolume (float volume);
// Registers a song handle to song data.
class MusInfo;
MusInfo *I_RegisterSong (FileReader *reader, int device);
struct MidiDeviceSetting;
MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device);
MusInfo *I_RegisterCDSong (int track, int cdid = 0);
MusInfo *I_RegisterURLSong (const char *url);

View file

@ -185,7 +185,7 @@ public:
class TimidityPPMIDIDevice : public PseudoMIDIDevice
{
public:
TimidityPPMIDIDevice();
TimidityPPMIDIDevice(const char *args);
~TimidityPPMIDIDevice();
int Open(void (*callback)(unsigned int, void *, DWORD, DWORD), void *userdata);
@ -270,7 +270,7 @@ protected:
class OPLMIDIDevice : public SoftSynthMIDIDevice, protected OPLmusicBlock
{
public:
OPLMIDIDevice();
OPLMIDIDevice(const char *args);
int Open(void (*callback)(unsigned int, void *, DWORD, DWORD), void *userdata);
void Close();
int GetTechnology() const;
@ -303,7 +303,7 @@ namespace Timidity { struct Renderer; }
class TimidityMIDIDevice : public SoftSynthMIDIDevice
{
public:
TimidityMIDIDevice();
TimidityMIDIDevice(const char *args);
~TimidityMIDIDevice();
int Open(void (*callback)(unsigned int, void *, DWORD, DWORD), void *userdata);
@ -337,7 +337,7 @@ protected:
class WildMIDIDevice : public SoftSynthMIDIDevice
{
public:
WildMIDIDevice();
WildMIDIDevice(const char *args);
~WildMIDIDevice();
int Open(void (*callback)(unsigned int, void *, DWORD, DWORD), void *userdata);
@ -366,7 +366,7 @@ struct fluid_synth_t;
class FluidSynthMIDIDevice : public SoftSynthMIDIDevice
{
public:
FluidSynthMIDIDevice();
FluidSynthMIDIDevice(const char *args);
~FluidSynthMIDIDevice();
int Open(void (*callback)(unsigned int, void *, DWORD, DWORD), void *userdata);
@ -431,7 +431,7 @@ protected:
class MIDIStreamer : public MusInfo
{
public:
MIDIStreamer(EMidiDevice type);
MIDIStreamer(EMidiDevice type, const char *args);
~MIDIStreamer();
void MusicVolumeChanged();
@ -517,6 +517,7 @@ protected:
bool CallbackIsThreaded;
int LoopLimit;
FString DumpFilename;
FString Args;
};
// MUS file played with a MIDI stream ---------------------------------------
@ -524,7 +525,7 @@ protected:
class MUSSong2 : public MIDIStreamer
{
public:
MUSSong2(FileReader &reader, EMidiDevice type);
MUSSong2(FileReader &reader, EMidiDevice type, const char *args);
~MUSSong2();
MusInfo *GetOPLDumper(const char *filename);
@ -550,7 +551,7 @@ protected:
class MIDISong2 : public MIDIStreamer
{
public:
MIDISong2(FileReader &reader, EMidiDevice type);
MIDISong2(FileReader &reader, EMidiDevice type, const char *args);
~MIDISong2();
MusInfo *GetOPLDumper(const char *filename);
@ -607,7 +608,7 @@ protected:
class HMISong : public MIDIStreamer
{
public:
HMISong(FileReader &reader, EMidiDevice type);
HMISong(FileReader &reader, EMidiDevice type, const char *args);
~HMISong();
MusInfo *GetOPLDumper(const char *filename);
@ -650,7 +651,7 @@ protected:
class XMISong : public MIDIStreamer
{
public:
XMISong(FileReader &reader, EMidiDevice type);
XMISong(FileReader &reader, EMidiDevice type, const char *args);
~XMISong();
MusInfo *GetOPLDumper(const char *filename);
@ -713,7 +714,7 @@ protected:
class OPLMUSSong : public StreamSong
{
public:
OPLMUSSong (FileReader &reader);
OPLMUSSong (FileReader &reader, const char *args);
~OPLMUSSong ();
void Play (bool looping, int subsong);
bool IsPlaying ();

View file

@ -255,7 +255,7 @@ CUSTOM_CVAR(Int, fluid_chorus_type, FLUID_CHORUS_DEFAULT_TYPE, CVAR_ARCHIVE|CVAR
//
//==========================================================================
FluidSynthMIDIDevice::FluidSynthMIDIDevice()
FluidSynthMIDIDevice::FluidSynthMIDIDevice(const char *args)
{
FluidSynth = NULL;
FluidSettings = NULL;
@ -293,7 +293,15 @@ FluidSynthMIDIDevice::FluidSynthMIDIDevice()
fluid_reverb_width, fluid_reverb_level);
fluid_synth_set_chorus(FluidSynth, fluid_chorus_voices, fluid_chorus_level,
fluid_chorus_speed, fluid_chorus_depth, fluid_chorus_type);
if (0 == LoadPatchSets(fluid_patchset))
// try loading a patch set that got specified with $mididevice.
int res = 0;
if (args != NULL && *args != 0)
{
res = LoadPatchSets(args);
}
if (res == 0 && 0 == LoadPatchSets(fluid_patchset))
{
#ifdef __unix__
// This is the standard location on Ubuntu.

View file

@ -128,8 +128,8 @@ extern char MIDI_CommonLengths[15];
//
//==========================================================================
HMISong::HMISong (FileReader &reader, EMidiDevice type)
: MIDIStreamer(type), MusHeader(0), Tracks(0)
HMISong::HMISong (FileReader &reader, EMidiDevice type, const char *args)
: MIDIStreamer(type, args), MusHeader(0), Tracks(0)
{
#ifdef _WIN32
if (ExitEvent == NULL)

View file

@ -72,7 +72,7 @@ CUSTOM_CVAR (Int, timidity_frequency, 22050, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
//
//==========================================================================
TimidityPPMIDIDevice::TimidityPPMIDIDevice()
TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args)
: DiskName("zmid"),
#ifdef _WIN32
ReadWavePipe(INVALID_HANDLE_VALUE), WriteWavePipe(INVALID_HANDLE_VALUE),
@ -86,6 +86,12 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice()
WavePipe[0] = WavePipe[1] = -1;
#endif
if (args == NULL || *args == 0) args = timidity_exe;
CommandLine.Format("%s %s -EFchorus=%s -EFreverb=%s -s%d ",
args, *timidity_extargs,
*timidity_chorus, *timidity_reverb, *timidity_frequency);
if (DiskName == NULL)
{
Printf(PRINT_BOLD, "Could not create temp music file\n");
@ -187,10 +193,6 @@ int TimidityPPMIDIDevice::Open(void (*callback)(unsigned int, void *, DWORD, DWO
Validated = true;
#endif // WIN32
CommandLine.Format("%s %s -EFchorus=%s -EFreverb=%s -s%d ",
*timidity_exe, *timidity_extargs,
*timidity_chorus, *timidity_reverb, *timidity_frequency);
pipeSize = (timidity_pipe * timidity_frequency / 1000)
<< (timidity_stereo + !timidity_8bit);

View file

@ -89,12 +89,12 @@ static const BYTE StaticMIDIhead[] =
//
//==========================================================================
MIDIStreamer::MIDIStreamer(EMidiDevice type)
MIDIStreamer::MIDIStreamer(EMidiDevice type, const char *args)
:
#ifdef _WIN32
PlayerThread(0), ExitEvent(0), BufferDoneEvent(0),
#endif
MIDI(0), Division(0), InitialTempo(500000), DeviceType(type)
MIDI(0), Division(0), InitialTempo(500000), DeviceType(type), Args(args)
{
#ifdef _WIN32
BufferDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
@ -269,19 +269,19 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype) const
#ifdef HAVE_FLUIDSYNTH
case MDEV_FLUIDSYNTH:
return new FluidSynthMIDIDevice;
return new FluidSynthMIDIDevice(Args);
#endif
case MDEV_SNDSYS:
return new SndSysMIDIDevice;
case MDEV_GUS:
return new TimidityMIDIDevice;
return new TimidityMIDIDevice(Args);
case MDEV_OPL:
try
{
return new OPLMIDIDevice;
return new OPLMIDIDevice(Args);
}
catch (CRecoverableError &err)
{
@ -291,10 +291,10 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype) const
}
case MDEV_TIMIDITY:
return new TimidityPPMIDIDevice;
return new TimidityPPMIDIDevice(Args);
case MDEV_WILDMIDI:
return new WildMIDIDevice;
return new WildMIDIDevice(Args);
default:
return NULL;

View file

@ -93,8 +93,8 @@ static const BYTE CtrlTranslate[15] =
//
//==========================================================================
MUSSong2::MUSSong2 (FileReader &reader, EMidiDevice type)
: MIDIStreamer(type), MusHeader(0), MusBuffer(0)
MUSSong2::MUSSong2 (FileReader &reader, EMidiDevice type, const char *args)
: MIDIStreamer(type, args), MusHeader(0), MusBuffer(0)
{
#ifdef _WIN32
if (ExitEvent == NULL)

View file

@ -20,16 +20,25 @@ CUSTOM_CVAR (Int, opl_numchips, 2, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
}
}
CVAR(Int, opl_core, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Int, opl_core, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
int current_opl_core;
OPLMUSSong::OPLMUSSong (FileReader &reader)
// Get OPL core override from $mididevice
void OPL_SetCore(const char *args)
{
current_opl_core = opl_core;
if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0';
}
OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args)
{
int samples = int(OPL_SAMPLE_RATE / 14);
OPL_SetCore(args);
Music = new OPLmusicFile (&reader);
m_Stream = GSnd->CreateStream (FillStream, samples*4,
(opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
(current_opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
if (m_Stream == NULL)
{
Printf (PRINT_BOLD, "Could not create music stream.\n");

View file

@ -102,8 +102,8 @@ char MIDI_CommonLengths[15] = { 0, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
//
//==========================================================================
MIDISong2::MIDISong2 (FileReader &reader, EMidiDevice type)
: MIDIStreamer(type), MusHeader(0), Tracks(0)
MIDISong2::MIDISong2 (FileReader &reader, EMidiDevice type, const char *args)
: MIDIStreamer(type, args), MusHeader(0), Tracks(0)
{
int p;
int i;

View file

@ -86,10 +86,10 @@ struct FmtChunk
//
//==========================================================================
TimidityMIDIDevice::TimidityMIDIDevice()
TimidityMIDIDevice::TimidityMIDIDevice(const char *args)
{
Renderer = NULL;
Renderer = new Timidity::Renderer((float)SampleRate);
Renderer = new Timidity::Renderer((float)SampleRate, args);
}
//==========================================================================
@ -245,6 +245,7 @@ FString TimidityMIDIDevice::GetStats()
//==========================================================================
TimidityWaveWriterMIDIDevice::TimidityWaveWriterMIDIDevice(const char *filename, int rate)
:TimidityMIDIDevice(NULL)
{
File = fopen(filename, "wb");
if (File != NULL)

View file

@ -81,7 +81,7 @@ CUSTOM_CVAR(Bool, wildmidi_enhanced_resampling, true, CVAR_ARCHIVE | CVAR_GLOBAL
//
//==========================================================================
WildMIDIDevice::WildMIDIDevice()
WildMIDIDevice::WildMIDIDevice(const char *args)
{
Renderer = NULL;
@ -94,16 +94,18 @@ WildMIDIDevice::WildMIDIDevice()
SampleRate = clamp(SampleRate, 11025, 65535);
}
if (CurrentConfig.CompareNoCase(wildmidi_config) != 0 || SampleRate != WildMidi_GetSampleRate())
if (args == NULL || *args == 0) args = wildmidi_config;
if (CurrentConfig.CompareNoCase(args) != 0 || SampleRate != WildMidi_GetSampleRate())
{
if (CurrentConfig.IsNotEmpty())
{
WildMidi_Shutdown();
CurrentConfig = "";
}
if (!WildMidi_Init(wildmidi_config, SampleRate, 0))
if (!WildMidi_Init(args, SampleRate, 0))
{
CurrentConfig = wildmidi_config;
CurrentConfig = args;
}
}
if (CurrentConfig.IsNotEmpty())

View file

@ -108,8 +108,8 @@ extern char MIDI_CommonLengths[15];
//
//==========================================================================
XMISong::XMISong (FileReader &reader, EMidiDevice type)
: MIDIStreamer(type), MusHeader(0), Songs(0)
XMISong::XMISong (FileReader &reader, EMidiDevice type, const char *args)
: MIDIStreamer(type, args), MusHeader(0), Songs(0)
{
#ifdef _WIN32
if (ExitEvent == NULL)

View file

@ -678,8 +678,9 @@ int LoadDMXGUS()
return 0;
}
Renderer::Renderer(float sample_rate)
Renderer::Renderer(float sample_rate, const char *args)
{
// 'args' should be used to load a custom config or DMXGUS, but since setup currently requires a snd_reset call, this will need some refactoring first
rate = sample_rate;
patches = NULL;
resample_buffer_size = 0;

View file

@ -630,7 +630,7 @@ struct Renderer
int voices;
int lost_notes, cut_notes;
Renderer(float sample_rate);
Renderer(float sample_rate, const char *args);
~Renderer();
void HandleEvent(int status, int parm1, int parm2);