mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-29 15:32:54 +00:00
- removed a few dependencies of the Timidity++ code from the main GZDoom code base.
The big issues, i.e. FileReader and SoundFontReader still need to be handled to make this a standalone library.
This commit is contained in:
parent
b3a9884eb1
commit
df7a4bb0d9
6 changed files with 265 additions and 15 deletions
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "m_random.h"
|
||||
#include "common.h"
|
||||
|
||||
namespace TimidityPlus
|
||||
|
@ -113,16 +112,19 @@ int string_to_7bit_range(const char *string_, int *start, int *end)
|
|||
}
|
||||
|
||||
|
||||
static FRandom pr_rnd;
|
||||
double GenRand_Real1()
|
||||
{
|
||||
return rand() * (1. / RAND_MAX);
|
||||
}
|
||||
|
||||
int int_rand(int n)
|
||||
{
|
||||
return (int)pr_rnd.GenRand_Real1() * n;
|
||||
return (int)GenRand_Real1() * n;
|
||||
}
|
||||
|
||||
double flt_rand()
|
||||
{
|
||||
return (int)pr_rnd.GenRand_Real1();
|
||||
return (int)GenRand_Real1();
|
||||
}
|
||||
|
||||
struct timidity_file *open_file(const char *name, FSoundFontReader *sfreader)
|
||||
|
|
|
@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
#include "common.h"
|
||||
#include "instrum.h"
|
||||
#include "quantity.h"
|
||||
#include "cmdlib.h"
|
||||
|
||||
|
||||
namespace TimidityPlus
|
||||
|
@ -642,8 +641,9 @@ int Instruments::read_config_file(const char *name, int self, int allow_missing_
|
|||
init_mblock(&varbuf);
|
||||
if (!self)
|
||||
{
|
||||
basedir = strdup_mblock(&varbuf, tf->filename.c_str());
|
||||
FixPathSeperator((char*)basedir);
|
||||
char *c = strdup_mblock(&varbuf, tf->filename.c_str());
|
||||
basedir = c;
|
||||
for (; c; c++) if (*c == '\\') *c = '/';
|
||||
sep = (char*)strrchr(basedir, '/');
|
||||
}
|
||||
else
|
||||
|
|
|
@ -210,11 +210,6 @@ void Effect::do_effect(int32_t *buf, int32_t count)
|
|||
effect_left_right_delay(buf, count);
|
||||
}
|
||||
|
||||
uint32_t Effect::frand(void)
|
||||
{
|
||||
return rng.GenRand32();
|
||||
}
|
||||
|
||||
int32_t Effect::my_mod(int32_t x, int32_t n)
|
||||
{
|
||||
if (x >= n)
|
||||
|
|
|
@ -14,7 +14,6 @@ class Effect
|
|||
{
|
||||
void effect_left_right_delay(int32_t *, int32_t);
|
||||
void init_mtrand(void);
|
||||
uint32_t frand(void);
|
||||
int32_t my_mod(int32_t, int32_t);
|
||||
|
||||
int turn_counter = 0, tc = 0;
|
||||
|
@ -22,7 +21,6 @@ class Effect
|
|||
double rate0 = 0, rate1 = 0, dr = 0;
|
||||
int32_t prev[AUDIO_BUFFER_SIZE * 2] = { 0 };
|
||||
|
||||
FRandom rng;
|
||||
Reverb *reverb;
|
||||
|
||||
public:
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <stdint.h> // int types are defined here
|
||||
|
||||
#include "m_swap.h"
|
||||
#include "t_swap.h"
|
||||
|
||||
namespace TimidityPlus
|
||||
{
|
||||
|
|
255
src/sound/timiditypp/t_swap.h
Normal file
255
src/sound/timiditypp/t_swap.h
Normal file
|
@ -0,0 +1,255 @@
|
|||
//
|
||||
// DESCRIPTION:
|
||||
// Endianess handling, swapping 16bit and 32bit.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef __M_SWAP_H__
|
||||
#define __M_SWAP_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// Endianess handling.
|
||||
// WAD files are stored little endian.
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <libkern/OSByteOrder.h>
|
||||
|
||||
inline short LittleShort(short x)
|
||||
{
|
||||
return (short)OSSwapLittleToHostInt16((uint16_t)x);
|
||||
}
|
||||
|
||||
inline unsigned short LittleShort(unsigned short x)
|
||||
{
|
||||
return OSSwapLittleToHostInt16(x);
|
||||
}
|
||||
|
||||
inline short LittleShort(int x)
|
||||
{
|
||||
return OSSwapLittleToHostInt16((uint16_t)x);
|
||||
}
|
||||
|
||||
inline unsigned short LittleShort(unsigned int x)
|
||||
{
|
||||
return OSSwapLittleToHostInt16((uint16_t)x);
|
||||
}
|
||||
|
||||
inline int LittleLong(int x)
|
||||
{
|
||||
return OSSwapLittleToHostInt32((uint32_t)x);
|
||||
}
|
||||
|
||||
inline unsigned int LittleLong(unsigned int x)
|
||||
{
|
||||
return OSSwapLittleToHostInt32(x);
|
||||
}
|
||||
|
||||
inline short BigShort(short x)
|
||||
{
|
||||
return (short)OSSwapBigToHostInt16((uint16_t)x);
|
||||
}
|
||||
|
||||
inline unsigned short BigShort(unsigned short x)
|
||||
{
|
||||
return OSSwapBigToHostInt16(x);
|
||||
}
|
||||
|
||||
inline int BigLong(int x)
|
||||
{
|
||||
return OSSwapBigToHostInt32((uint32_t)x);
|
||||
}
|
||||
|
||||
inline unsigned int BigLong(unsigned int x)
|
||||
{
|
||||
return OSSwapBigToHostInt32(x);
|
||||
}
|
||||
|
||||
#elif defined __BIG_ENDIAN__
|
||||
|
||||
// Swap 16bit, that is, MSB and LSB byte.
|
||||
// No masking with 0xFF should be necessary.
|
||||
inline short LittleShort (short x)
|
||||
{
|
||||
return (short)((((unsigned short)x)>>8) | (((unsigned short)x)<<8));
|
||||
}
|
||||
|
||||
inline unsigned short LittleShort (unsigned short x)
|
||||
{
|
||||
return (unsigned short)((x>>8) | (x<<8));
|
||||
}
|
||||
|
||||
inline short LittleShort (int x)
|
||||
{
|
||||
return LittleShort((short)x);
|
||||
}
|
||||
|
||||
inline unsigned short LittleShort (unsigned int x)
|
||||
{
|
||||
return LittleShort((unsigned short)x);
|
||||
}
|
||||
|
||||
// Swapping 32bit.
|
||||
inline unsigned int LittleLong (unsigned int x)
|
||||
{
|
||||
return (unsigned int)(
|
||||
(x>>24)
|
||||
| ((x>>8) & 0xff00)
|
||||
| ((x<<8) & 0xff0000)
|
||||
| (x<<24));
|
||||
}
|
||||
|
||||
inline int LittleLong (int x)
|
||||
{
|
||||
return (int)(
|
||||
(((unsigned int)x)>>24)
|
||||
| ((((unsigned int)x)>>8) & 0xff00)
|
||||
| ((((unsigned int)x)<<8) & 0xff0000)
|
||||
| (((unsigned int)x)<<24));
|
||||
}
|
||||
|
||||
inline short BigShort(short x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline unsigned short BigShort(unsigned short x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline unsigned int BigLong(unsigned int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline int BigLong(int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
inline short LittleShort(short x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline unsigned short LittleShort(unsigned short x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline unsigned int LittleLong(unsigned int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
inline int LittleLong(int x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
inline short BigShort(short x)
|
||||
{
|
||||
return (short)_byteswap_ushort((unsigned short)x);
|
||||
}
|
||||
|
||||
inline unsigned short BigShort(unsigned short x)
|
||||
{
|
||||
return _byteswap_ushort(x);
|
||||
}
|
||||
|
||||
inline int BigLong(int x)
|
||||
{
|
||||
return (int)_byteswap_ulong((unsigned long)x);
|
||||
}
|
||||
|
||||
inline unsigned int BigLong(unsigned int x)
|
||||
{
|
||||
return (unsigned int)_byteswap_ulong((unsigned long)x);
|
||||
}
|
||||
#pragma warning (default: 4035)
|
||||
|
||||
#else
|
||||
|
||||
inline short BigShort (short x)
|
||||
{
|
||||
return (short)((((unsigned short)x)>>8) | (((unsigned short)x)<<8));
|
||||
}
|
||||
|
||||
inline unsigned short BigShort (unsigned short x)
|
||||
{
|
||||
return (unsigned short)((x>>8) | (x<<8));
|
||||
}
|
||||
|
||||
inline unsigned int BigLong (unsigned int x)
|
||||
{
|
||||
return (unsigned int)(
|
||||
(x>>24)
|
||||
| ((x>>8) & 0xff00)
|
||||
| ((x<<8) & 0xff0000)
|
||||
| (x<<24));
|
||||
}
|
||||
|
||||
inline int BigLong (int x)
|
||||
{
|
||||
return (int)(
|
||||
(((unsigned int)x)>>24)
|
||||
| ((((unsigned int)x)>>8) & 0xff00)
|
||||
| ((((unsigned int)x)<<8) & 0xff0000)
|
||||
| (((unsigned int)x)<<24));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __BIG_ENDIAN__
|
||||
|
||||
// These may be destructive so they should create errors
|
||||
unsigned long BigLong(unsigned long) = delete;
|
||||
long BigLong(long) = delete;
|
||||
unsigned long LittleLong(unsigned long) = delete;
|
||||
long LittleLong(long) = delete;
|
||||
|
||||
|
||||
// Data accessors, since some data is highly likely to be unaligned.
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
|
||||
inline int GetShort(const unsigned char *foo)
|
||||
{
|
||||
return *(const short *)foo;
|
||||
}
|
||||
inline int GetInt(const unsigned char *foo)
|
||||
{
|
||||
return *(const int *)foo;
|
||||
}
|
||||
#else
|
||||
inline int GetShort(const unsigned char *foo)
|
||||
{
|
||||
return short(foo[0] | (foo[1] << 8));
|
||||
}
|
||||
inline int GetInt(const unsigned char *foo)
|
||||
{
|
||||
return int(foo[0] | (foo[1] << 8) | (foo[2] << 16) | (foo[3] << 24));
|
||||
}
|
||||
#endif
|
||||
inline int GetBigInt(const unsigned char *foo)
|
||||
{
|
||||
return int((foo[0] << 24) | (foo[1] << 16) | (foo[2] << 8) | foo[3]);
|
||||
}
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
inline int GetNativeInt(const unsigned char *foo)
|
||||
{
|
||||
return GetBigInt(foo);
|
||||
}
|
||||
#else
|
||||
inline int GetNativeInt(const unsigned char *foo)
|
||||
{
|
||||
return GetInt(foo);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __M_SWAP_H__
|
Loading…
Reference in a new issue