Skip to content

Commit

Permalink
Merge branch 'zmusic_dll'
Browse files Browse the repository at this point in the history
# Conflicts:
#	libraries/zmusic/zmusic/configuration.cpp
  • Loading branch information
coelckers committed Jan 4, 2020
2 parents fca3da8 + 829d43b commit 4253fb6
Show file tree
Hide file tree
Showing 52 changed files with 1,112 additions and 785 deletions.
3 changes: 0 additions & 3 deletions libraries/dumb/include/dumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,6 @@ DUH *make_duh(

void DUMBEXPORT duh_set_length(DUH *duh, int32 length);

extern short *(*dumb_decode_vorbis)(int outlen, const void *oggstream, int sizebytes);


#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions libraries/dumb/src/it/readxm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <stdlib.h>
#include <assert.h>

short * (*dumb_decode_vorbis)(int outlen, const void *oggstream, int sizebytes);
short * dumb_decode_vorbis(int outlen, const void *oggstream, int sizebytes);

/** TODO:
Expand Down Expand Up @@ -830,7 +830,7 @@ static int it_xm_read_sample_data(IT_SAMPLE *sample, unsigned char roguebytes, D
sample->loop_start >>= 1;
sample->loop_end >>= 1;
}
output = dumb_decode_vorbis? dumb_decode_vorbis(outlen, (char *)sample->data + 4, datasizebytes - 4) : NULL;
output = dumb_decode_vorbis(outlen, (char *)sample->data + 4, datasizebytes - 4);
if (output != NULL)
{
free(sample->data);
Expand Down
31 changes: 18 additions & 13 deletions libraries/music_common/fileio.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ struct FileInterface
virtual ~FileInterface() {}
public:
virtual char* gets(char* buff, int n) = 0;
virtual long read(void* buff, int32_t size, int32_t nitems) = 0;
long read(void* buff, int32_t size) { return read(buff, 1, size); }
virtual long read(void* buff, int32_t size) = 0;
virtual long seek(long offset, int whence) = 0;
virtual long tell() = 0;
virtual void close()
Expand Down Expand Up @@ -101,10 +100,10 @@ struct StdioFileReader : public FileInterface
if (!f) return nullptr;
return fgets(buff, n, f);
}
long read(void* buff, int32_t size, int32_t nitems) override
long read(void* buff, int32_t size) override
{
if (!f) return 0;
return (long)fread(buff, size, nitems, f);
return (long)fread(buff, 1, size, f);
}
long seek(long offset, int whence) override
{
Expand Down Expand Up @@ -165,14 +164,14 @@ struct MemoryReader : public FileInterface
*p++ = 0;
return strbuf;
}
long read(void* buff, int32_t size, int32_t nitems) override
long read(void* buff, int32_t size) override
{
long len = long(size) * nitems;
long len = long(size);
if (len > mLength - mPos) len = mLength - mPos;
if (len < 0) len = 0;
memcpy(buff, mData + mPos, len);
mPos += len;
return len / size;
return len;
}
long seek(long offset, int whence) override
{
Expand Down Expand Up @@ -217,15 +216,18 @@ struct VectorReader : public MemoryReader
mLength = (long)mVector.size();
mPos = 0;
}


VectorReader(const uint8_t* data, size_t size)
{
mVector.resize(size);
memcpy(mVector.data(), data, size);
}
};


//==========================================================================
//
// The follpwing two functions are needed to allow using UTF-8 in the file interface.
// fopen on Windows is only safe for ASCII,
// The following two functions are needed to allow using UTF-8 in the file interface.
// fopen on Windows is only safe for ASCII.
//
//==========================================================================

Expand Down Expand Up @@ -271,10 +273,12 @@ inline bool fileExists(const char *fn)

class SoundFontReaderInterface
{
public:
protected:
virtual ~SoundFontReaderInterface() {}
public:
virtual struct FileInterface* open_file(const char* fn) = 0;
virtual void add_search_path(const char* path) = 0;
virtual void close() { delete this; }
};


Expand Down Expand Up @@ -375,6 +379,7 @@ class SF2Reader : public FileSystemSoundFontReader
}
};


MusicIO::SoundFontReaderInterface* ClientOpenSoundFont(const char* name, int type);

}

14 changes: 13 additions & 1 deletion libraries/oplsynth/oplio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,26 @@ int OPLio::Init(int core, uint32_t numchips, bool stereo, bool initopl3)
uint32_t i;
IsOPL3 = (core == 1 || core == 2 || core == 3);

using CoreInit = OPLEmul* (*)(bool);
static CoreInit inits[] =
{
YM3812Create,
DBOPLCreate,
JavaOPLCreate,
NukedOPL3Create,
};

if (core < 0) core = 0;
if (core > 3) core = 3;

memset(chips, 0, sizeof(chips));
if (IsOPL3)
{
numchips = (numchips + 1) >> 1;
}
for (i = 0; i < numchips; ++i)
{
OPLEmul *chip = IsOPL3 ? (core == 1 ? DBOPLCreate(stereo) : (core == 2 ? JavaOPLCreate(stereo) : NukedOPL3Create(stereo))) : YM3812Create(stereo);
OPLEmul* chip = inits[core](stereo);
if (chip == NULL)
{
break;
Expand Down
10 changes: 10 additions & 0 deletions libraries/timidity/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Timidity
/* This'll allocate memory or die. */
void *safe_malloc(size_t count)
{
#if 0
char buffer[80];
void *p;
if (count > (1 << 21))
Expand All @@ -51,6 +52,15 @@ void *safe_malloc(size_t count)
throw std::runtime_error(buffer);
}
return 0; // Unreachable.
#else
// No, we cannot throw exceptions here - this code can get called from real-time worker threads.
auto p = malloc(count);
if (!p)
{
abort(); // we must abort, though...
}
return p;
#endif
}


Expand Down
2 changes: 1 addition & 1 deletion libraries/timidity/instrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ Instruments::~Instruments()
drumset[i] = NULL;
}
}
if (sfreader != nullptr) delete sfreader;
if (sfreader != nullptr) sfreader->close();
sfreader = nullptr;
}

Expand Down
8 changes: 4 additions & 4 deletions libraries/timidityplus/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void *safe_malloc(size_t count)
auto p = malloc(count);
if (p == nullptr)
{
// I_FatalError("Out of memory");
abort();
}
return p;
}
Expand All @@ -54,7 +54,7 @@ void *safe_realloc(void *ptr, size_t count)
auto p = realloc(ptr, count);
if (p == nullptr)
{
// I_FatalError("Out of memory");
abort();
}
return p;
}
Expand All @@ -65,7 +65,7 @@ char *safe_strdup(const char *s)
auto p = strdup(s);
if (p == nullptr)
{
// I_FatalError("Out of memory");
abort();
}
return p;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ void skip(timidity_file *tf, size_t len)
int tf_getc(timidity_file *tf)
{
unsigned char c;
auto read = tf_read(&c, 1, 1, tf);
auto read = tf_read(&c, 1, tf);
return read == 0 ? EOF : c;
}

Expand Down
16 changes: 8 additions & 8 deletions libraries/timidityplus/instrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Instruments::~Instruments()
free_tone_bank();
free_instrument_map();

if (sfreader != nullptr) delete sfreader;
if (sfreader != nullptr) sfreader->close();
}

void Instruments::free_instrument(Instrument *ip)
Expand Down Expand Up @@ -545,21 +545,21 @@ void Instruments::apply_bank_parameter(Instrument *ip, ToneBankElement *tone)
#define READ_CHAR(thing) { \
uint8_t tmpchar; \
\
if (tf_read(&tmpchar, 1, 1, tf) != 1) \
if (tf_read(&tmpchar, 1, tf) != 1) \
goto fail; \
thing = tmpchar; \
}
#define READ_SHORT(thing) { \
uint16_t tmpshort; \
\
if (tf_read(&tmpshort, 2, 1, tf) != 1) \
if (tf_read(&tmpshort, 2, tf) != 2) \
goto fail; \
thing = LE_SHORT(tmpshort); \
}
#define READ_LONG(thing) { \
int32_t tmplong; \
\
if (tf_read(&tmplong, 4, 1, tf) != 1) \
if (tf_read(&tmplong, 4, tf) != 4) \
goto fail; \
thing = LE_LONG(tmplong); \
}
Expand Down Expand Up @@ -661,7 +661,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
skip(tf, 127);
tmp[0] = tf_getc(tf);
}
if ((tf_read(tmp + 1, 1, 238, tf) != 238)
if ((tf_read(tmp + 1, 238, tf) != 238)
|| (memcmp(tmp, "GF1PATCH110\0ID#000002", 22)
&& memcmp(tmp, "GF1PATCH100\0ID#000002", 22))) {
/* don't know what the differences are */
Expand Down Expand Up @@ -689,7 +689,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
memset(ip->sample, 0, sizeof(Sample) * ip->samples);
for (i = 0; i < ip->samples; i++) {
skip(tf, 7); /* Skip the wave name */
if (tf_read(&fractions, 1, 1, tf) != 1) {
if (tf_read(&fractions, 1, tf) != 1) {
fail:
printMessage(CMSG_ERROR, VERB_NORMAL, "Error reading sample %d", i);
for (j = 0; j < i; j++)
Expand Down Expand Up @@ -738,7 +738,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
else
sp->panning = (uint8_t)(panning & 0x7f);
/* envelope, tremolo, and vibrato */
if (tf_read(tmp, 1, 18, tf) != 18)
if (tf_read(tmp, 18, tf) != 18)
goto fail;
if (!tmp[13] || !tmp[14]) {
sp->tremolo_sweep_increment = sp->tremolo_phase_increment = 0;
Expand Down Expand Up @@ -845,7 +845,7 @@ Instrument *Instruments::load_gus_instrument(char *name, ToneBank *bank, int dr,
/* Then read the sample data */
sp->data = (sample_t *)safe_malloc(sp->data_length + 4);
sp->data_alloced = 1;
if ((j = tf_read(sp->data, 1, sp->data_length, tf)) != (int)sp->data_length) {
if ((j = tf_read(sp->data, sp->data_length, tf)) != (int)sp->data_length) {
printMessage(CMSG_ERROR, VERB_NORMAL, "Too small this patch length: %d < %d", j, sp->data_length);
goto fail;
}
Expand Down
14 changes: 7 additions & 7 deletions libraries/timidityplus/sffile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ namespace TimidityPlus

static int READCHUNK(SFChunk *vp, timidity_file *tf)
{
if (tf_read(vp, 8, 1, tf) != 1)
if (tf_read(vp, 8, tf) != 8)
return -1;
vp->size = LE_LONG(vp->size);
return 1;
}

static int READDW(uint32_t *vp, timidity_file *tf)
{
if (tf_read(vp, 4, 1, tf) != 1)
if (tf_read(vp, 4, tf) != 4)
return -1;
*vp = LE_LONG(*vp);
return 1;
}

static int READW(uint16_t *vp, timidity_file *tf)
{
if (tf_read(vp, 2, 1, tf) != 1)
if (tf_read(vp, 2, tf) != 2)
return -1;
*vp = LE_SHORT(*vp);
return 1;
Expand All @@ -92,7 +92,7 @@ static int READSTR(char *str, timidity_file *tf)
{
int n;

if (tf_read(str, 20, 1, tf) != 1)
if (tf_read(str, 20, tf) != 20)
return -1;
str[19] = '\0';
n = (int)strlen(str);
Expand All @@ -102,8 +102,8 @@ static int READSTR(char *str, timidity_file *tf)
return n;
}

#define READID(var,tf) tf_read(var, 4, 1, tf)
#define READB(var,tf) tf_read(&var, 1, 1, tf)
#define READID(var,tf) tf_read(var, 4, tf)
#define READB(var,tf) tf_read(&var, 1, tf)
#define SKIPB(tf) skip(tf, 1)
#define SKIPW(tf) skip(tf, 2)
#define SKIPDW(tf) skip(tf, 4)
Expand Down Expand Up @@ -327,7 +327,7 @@ int Instruments::process_info(int size, SFInfo *sf, timidity_file *fd)
case INAM_ID:
/* name of the font */
sf->sf_name = (char*)safe_malloc(chunk.size + 1);
tf_read(sf->sf_name, 1, chunk.size, fd);
tf_read(sf->sf_name, chunk.size, fd);
sf->sf_name[chunk.size] = 0;
printMessage(CMSG_INFO, VERB_DEBUG,
" name %s", sf->sf_name);
Expand Down
Loading

0 comments on commit 4253fb6

Please sign in to comment.