- made the Timidity(GUS) device a separate library.

This commit is contained in:
Christoph Oelckers 2019-09-24 23:43:44 +02:00
parent dcef3681d4
commit 7962bf189e
27 changed files with 83 additions and 59 deletions

View file

@ -386,6 +386,7 @@ set( LZMA_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/lzma/C" )
set( ADL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/adlmidi" )
set( OPN_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/opnmidi" )
set( TIMIDITYPP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/timidityplus" )
set( TIMIDITY_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/libraries/timidity" )
if( NOT CMAKE_CROSSCOMPILING )
if( NOT CROSS_EXPORTS )
@ -409,6 +410,7 @@ add_subdirectory( libraries/dumb )
add_subdirectory( libraries/gdtoa )
add_subdirectory( libraries/adlmidi )
add_subdirectory( libraries/opnmidi )
add_subdirectory( libraries/timidity )
add_subdirectory( libraries/timidityplus )
add_subdirectory( wadsrc )
add_subdirectory( wadsrc_bm )

View file

@ -0,0 +1,28 @@
cmake_minimum_required( VERSION 2.8.7 )
make_release_only()
if( ZD_CMAKE_COMPILER_IS_GNUC_COMPATIBLE )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -fomit-frame-pointer" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
endif()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ZD_FASTMATH_FLAG}")
include_directories( timidity )
file( GLOB HEADER_FILES
timidity/*.h
)
add_library( timidity STATIC
common.cpp
instrum.cpp
instrum_dls.cpp
instrum_font.cpp
instrum_sf2.cpp
mix.cpp
playmidi.cpp
resample.cpp
timidity.cpp
)
target_link_libraries( timidity )

View file

@ -23,7 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <exception>
#include <stdexcept>
namespace Timidity

View file

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <math.h>
#include <memory>
#include <algorithm>
#include "timidity.h"
#include "gf1patch.h"
@ -598,11 +599,11 @@ int Renderer::fill_bank(int dr, int b)
{
if (bank->tone[i].fontbank >= 0)
{
ip = load_instrument_font(bank->tone[i].name, dr, b, i);
ip = load_instrument_font(bank->tone[i].name.c_str(), dr, b, i);
}
else
{
ip = load_instrument(bank->tone[i].name,
ip = load_instrument(bank->tone[i].name.c_str(),
(dr) ? 1 : 0,
bank->tone[i].pan,
(bank->tone[i].note != -1) ? bank->tone[i].note : ((dr) ? i : -1),
@ -618,7 +619,7 @@ int Renderer::fill_bank(int dr, int b)
bank->instrument[i] = ip;
if (ip == NULL)
{
if (bank->tone[i].name.IsEmpty())
if (bank->tone[i].name.length() == 0)
{
cmsg(CMSG_WARNING, (b != 0) ? VERB_VERBOSE : VERB_DEBUG,
"No instrument mapped to %s %d, program %d%s\n",
@ -629,7 +630,7 @@ int Renderer::fill_bank(int dr, int b)
{
cmsg(CMSG_ERROR, VERB_DEBUG,
"Couldn't load instrument %s (%s %d, program %d)\n",
bank->tone[i].name.GetChars(),
bank->tone[i].name.c_str(),
(dr) ? "drum set" : "tone bank", b, i);
}
if (b != 0)

View file

@ -32,15 +32,6 @@
#include "playmidi.h"
#ifndef MAKE_ID
#ifndef __BIG_ENDIAN__
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
#else
#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24)))
#endif
#endif
#define __Sound_SetError(x)
namespace Timidity

View file

@ -3,10 +3,10 @@
#include <errno.h>
#include <math.h>
#include <memory>
#include <assert.h>
#include <algorithm>
#include "doomdef.h"
#include "t_swap.h"
#include "templates.h"
#include "timidity.h"
#include "timidity_file.h"
#include "common.h"
@ -683,10 +683,10 @@ static void ParseShdr(SFFile *sf2, timidity_file *f, uint32_t chunkid, uint32_t
}
// Clamp sample positions to the available sample data.
sample->Start = MIN(sample->Start, sf2->SizeSampleData - 1);
sample->End = MIN(sample->End, sf2->SizeSampleData - 1);
sample->StartLoop = MIN(sample->StartLoop, sf2->SizeSampleData - 1);
sample->EndLoop = MIN(sample->EndLoop, sf2->SizeSampleData - 1);
sample->Start = std::min(sample->Start, sf2->SizeSampleData - 1);
sample->End = std::min(sample->End, sf2->SizeSampleData - 1);
sample->StartLoop = std::min(sample->StartLoop, sf2->SizeSampleData - 1);
sample->EndLoop = std::min(sample->EndLoop, sf2->SizeSampleData - 1);
if (sample->Start >= sample->End)
{
@ -872,7 +872,7 @@ void SFFile::SetAllOrders(int order)
{
Presets[i].LoadOrder = order;
}
for (unsigned int i = 0; i < Percussion.Size(); ++i)
for (size_t i = 0; i < Percussion.size(); ++i)
{
Percussion[i].LoadOrder = order;
}
@ -887,7 +887,7 @@ Instrument *SFFile::LoadInstrumentOrder(Renderer *song, int order, int drum, int
{
if (drum)
{
for (unsigned int i = 0; i < Percussion.Size(); ++i)
for (size_t i = 0; i < Percussion.size(); ++i)
{
if ((order < 0 || Percussion[i].LoadOrder == order) &&
Percussion[i].Generators.drumset == bank &&
@ -1040,11 +1040,11 @@ void SFFile::CheckZones(int start, int stop, bool instr)
// Check for swapped ranges. (Should we fix them or ignore them?)
if (bag[i].KeyRange.Lo > bag[i].KeyRange.Hi)
{
swapvalues(bag[i].KeyRange.Lo, bag[i].KeyRange.Hi);
std::swap(bag[i].KeyRange.Lo, bag[i].KeyRange.Hi);
}
if (bag[i].VelRange.Lo > bag[i].VelRange.Hi)
{
swapvalues(bag[i].VelRange.Lo, bag[i].VelRange.Hi);
std::swap(bag[i].VelRange.Lo, bag[i].VelRange.Hi);
}
}
}
@ -1147,10 +1147,10 @@ void SFFile::TranslatePercussionPresetZone(SFPreset *preset, SFBag *pzone)
AddPresetGenerators(&perc.Generators, pzone->GenIndex, (pzone + 1)->GenIndex, preset);
perc.Generators.drumset = (uint8_t)preset->Program;
perc.Generators.key = key;
perc.Generators.velRange.Lo = MAX(pzone->VelRange.Lo, InstrBags[i].VelRange.Lo);
perc.Generators.velRange.Hi = MIN(pzone->VelRange.Hi, InstrBags[i].VelRange.Hi);
perc.Generators.velRange.Lo = std::max(pzone->VelRange.Lo, InstrBags[i].VelRange.Lo);
perc.Generators.velRange.Hi = std::min(pzone->VelRange.Hi, InstrBags[i].VelRange.Hi);
perc.Generators.sampleID = InstrBags[i].Target;
Percussion.Push(perc);
Percussion.push_back(perc);
}
}
}
@ -1222,7 +1222,7 @@ void SFFile::AddPresetGenerators(SFGenComposite *composite, int start, int stop,
}
else
{
added = clamp<int>(added, def->Min, def->Max);
added = std::max<int>(def->Max, std::min<int>(def->Min, added));
}
((int16_t *)composite)[def->StructIndex] = added;
gen_set[gen->Oper] = true;
@ -1235,7 +1235,7 @@ void SFFile::AddPresetGenerators(SFGenComposite *composite, int start, int stop,
Instrument *SFFile::LoadPercussion(Renderer *song, SFPerc *perc)
{
unsigned int i;
size_t i;
int drumkey;
int drumset;
int j;
@ -1246,7 +1246,7 @@ Instrument *SFFile::LoadPercussion(Renderer *song, SFPerc *perc)
drumset = perc->Generators.drumset;
// Count all percussion composites that match this one's key and set.
for (i = 0; i < Percussion.Size(); ++i)
for (i = 0; i < Percussion.size(); ++i)
{
if (Percussion[i].Generators.key == drumkey &&
Percussion[i].Generators.drumset == drumset &&
@ -1272,7 +1272,7 @@ Instrument *SFFile::LoadPercussion(Renderer *song, SFPerc *perc)
memset(ip->sample, 0, sizeof(Sample) * ip->samples);
// Fill in Sample structure for each composite.
for (j = 0, i = 0; i < Percussion.Size(); ++i)
for (j = 0, i = 0; i < Percussion.size(); ++i)
{
SFPerc *zone = &Percussion[i];
SFGenComposite *gen = &zone->Generators;
@ -1385,12 +1385,12 @@ Instrument *SFFile::LoadPreset(Renderer *song, SFPreset *preset)
Sample *sp = ip->sample + k++;
// Set velocity range
sp->low_vel = MAX(InstrBags[j].VelRange.Lo, PresetBags[i].VelRange.Lo);
sp->high_vel = MIN(InstrBags[j].VelRange.Hi, PresetBags[i].VelRange.Hi);
sp->low_vel = std::max(InstrBags[j].VelRange.Lo, PresetBags[i].VelRange.Lo);
sp->high_vel = std::min(InstrBags[j].VelRange.Hi, PresetBags[i].VelRange.Hi);
// Set frequency range
sp->low_freq = note_to_freq(MAX(InstrBags[j].KeyRange.Lo, PresetBags[i].KeyRange.Lo));
sp->high_freq = note_to_freq(MIN(InstrBags[j].KeyRange.Hi, PresetBags[i].KeyRange.Hi));
sp->low_freq = note_to_freq(std::max(InstrBags[j].KeyRange.Lo, PresetBags[i].KeyRange.Lo));
sp->high_freq = note_to_freq(std::min(InstrBags[j].KeyRange.Hi, PresetBags[i].KeyRange.Hi));
gen = DefaultGenerators;
if (inst->bHasGlobalZone)
@ -1426,10 +1426,10 @@ void SFFile::ApplyGeneratorsToRegion(SFGenComposite *gen, SFSample *sfsamp, Rend
int start, end;
start = gen->startAddrsOffset + gen->startAddrsCoarseOffset * 32768;
end = gen->endAddrsOffset + gen->endAddrsCoarseOffset * 32768;
start = MAX<int>(sfsamp->Start, sfsamp->Start + start);
end = MIN<int>(sfsamp->End, sfsamp->End + end);
sp->loop_start = MAX<int>(start, sfsamp->StartLoop + gen->startLoopAddrsOffset + gen->startLoopAddrsCoarseOffset * 32768);
sp->loop_end = MIN<int>(end, sfsamp->EndLoop + gen->endLoopAddrsOffset + gen->endLoopAddrsCoarseOffset * 32768);
start = std::max<int>(sfsamp->Start, sfsamp->Start + start);
end = std::min<int>(sfsamp->End, sfsamp->End + end);
sp->loop_start = std::max<int>(start, sfsamp->StartLoop + gen->startLoopAddrsOffset + gen->startLoopAddrsCoarseOffset * 32768);
sp->loop_end = std::min<int>(end, sfsamp->EndLoop + gen->endLoopAddrsOffset + gen->endLoopAddrsCoarseOffset * 32768);
sp->loop_start = (sp->loop_start - start) << FRACTION_BITS;
sp->loop_end = (sp->loop_end - start) << FRACTION_BITS;

View file

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include "timidity.h"
#include "common.h"

View file

@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <memory>
#include <algorithm>
#include <stdarg.h>
#include "timidity.h"
#include "timidity_file.h"
@ -596,7 +598,7 @@ int Instruments::LoadDMXGUS(int gus_memsize)
long read = 0;
uint8_t remap[256];
FString patches[256];
std::string patches[256];
memset(remap, 255, sizeof(remap));
char temp[16];
int current = -1;
@ -680,7 +682,7 @@ int Instruments::LoadDMXGUS(int gus_memsize)
int j = (gusbank > 0) ? remap[k] : k;
if (k == 128) bank = drumset[0];
// No need to bother with things that don't exist
if (patches[j].IsEmpty())
if (patches[j].length() == 0)
continue;
int val = k % 128;
@ -727,7 +729,7 @@ Renderer::~Renderer()
{
if (resample_buffer != NULL)
{
M_Free(resample_buffer);
free(resample_buffer);
}
if (voice != NULL)
{
@ -752,7 +754,7 @@ void Renderer::ComputeOutput(float *buffer, int count)
if (resample_buffer_size < count)
{
resample_buffer_size = count;
resample_buffer = (sample_t *)M_Realloc(resample_buffer, count * sizeof(float) * 2);
resample_buffer = (sample_t *)realloc(resample_buffer, count * sizeof(float) * 2);
}
for (int i = 0; i < voices; i++, v++)
{

View file

@ -138,5 +138,12 @@ common.h
extern void *safe_malloc(size_t count);
#ifndef MAKE_ID
#ifndef __BIG_ENDIAN__
#define MAKE_ID(a,b,c,d) ((uint32_t)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
#else
#define MAKE_ID(a,b,c,d) ((uint32_t)((d)|((c)<<8)|((b)<<16)|((a)<<24)))
#endif
#endif
}

View file

@ -116,7 +116,7 @@ struct ToneBankElement
note(0), pan(0), strip_loop(0), strip_envelope(0), strip_tail(0)
{}
FString name;
std::string name;
int note, pan, fontbank, fontpreset, fontnote;
int8_t strip_loop, strip_envelope, strip_tail;
};

View file

@ -1,4 +1,5 @@
#pragma once
#include <vector>
namespace Timidity
{
typedef uint16_t SFGenerator;
@ -304,7 +305,7 @@ struct SFFile : public FontFile
SFBag *InstrBags;
SFGenList *InstrGenerators;
SFSample *Samples;
TArray<SFPerc> Percussion;
std::vector<SFPerc> Percussion;
int MinorVersion;
uint32_t SampleDataOffset;
uint32_t SampleDataLSBOffset;

View file

@ -11,6 +11,9 @@ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ZD_FASTMATH_FLAG}")
include_directories( timiditypp )
file( GLOB HEADER_FILES
timiditypp/*.h
)
add_library( timidityplus STATIC
fft4g.cpp
reverb.cpp

View file

@ -468,7 +468,7 @@ set( ZDOOM_LIBS ${ZDOOM_LIBS} "${ZLIB_LIBRARIES}" "${JPEG_LIBRARIES}" "${BZIP2_L
if (HAVE_VULKAN)
set( ZDOOM_LIBS ${ZDOOM_LIBS} "glslang" "SPIRV" "OGLCompiler")
endif()
include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GME_INCLUDE_DIR}" "${ADL_INCLUDE_DIR}" "${OPN_INCLUDE_DIR}" "${TIMIDITYPP_INCLUDE_DIR}" )
include_directories( "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIR}" "${JPEG_INCLUDE_DIR}" "${GME_INCLUDE_DIR}" "${ADL_INCLUDE_DIR}" "${OPN_INCLUDE_DIR}" "${TIMIDITYPP_INCLUDE_DIR}" "${TIMIDITY_INCLUDE_DIR}" )
if( ${HAVE_VM_JIT} )
add_definitions( -DHAVE_VM_JIT )
@ -693,7 +693,6 @@ file( GLOB HEADER_FILES
sound/oplsynth/*.h
sound/oplsynth/dosbox/*.h
sound/thirdparty/*.h
sound/timidity/*.h
sound/wildmidi/*.h
rendering/*.h
rendering/2d/*.h
@ -1220,15 +1219,6 @@ set (PCH_SOURCES
sound/oplsynth/dosbox/opl.cpp
sound/oplsynth/OPL3.cpp
sound/oplsynth/nukedopl3.cpp
sound/timidity/common.cpp
sound/timidity/instrum.cpp
sound/timidity/instrum_dls.cpp
sound/timidity/instrum_font.cpp
sound/timidity/instrum_sf2.cpp
sound/timidity/mix.cpp
sound/timidity/playmidi.cpp
sound/timidity/resample.cpp
sound/timidity/timidity.cpp
sound/wildmidi/file_io.cpp
sound/wildmidi/gus_pat.cpp
sound/wildmidi/reverb.cpp
@ -1330,7 +1320,7 @@ if( UNIX )
endif()
endif()
target_link_libraries( zdoom ${ZDOOM_LIBS} gdtoa dumb lzma adl opn timidityplus )
target_link_libraries( zdoom ${ZDOOM_LIBS} gdtoa dumb lzma adl opn timidity timidityplus )
include_directories( .
g_statusbar
@ -1348,7 +1338,6 @@ include_directories( .
sound/music
sound/backend
sound/oplsynth
sound/timidity
sound/wildmidi
xlat
utility
@ -1461,7 +1450,6 @@ source_group("Audio Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/soun
source_group("Audio Files\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/backend/.+")
source_group("Audio Files\\OPL Synth" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/oplsynth/.+")
source_group("Audio Files\\OPL Synth\\DOSBox" FILES sound/oplsynth/dosbox/opl.cpp sound/oplsynth/dosbox/opl.h)
source_group("Audio Files\\Timidity" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/timidity/.+")
source_group("Audio Files\\WildMidi" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/wildmidi/.+")
source_group("Audio Files\\MIDI Devices" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/mididevices/.+")
source_group("Audio Files\\MIDI Sources" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/midisources/.+")