Path: blob/master/libs/fluidsynth/src/utils/fluidsynth_priv.h
4396 views
/* FluidSynth - A Software Synthesizer1*2* Copyright (C) 2003 Peter Hanappe and others.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public License6* as published by the Free Software Foundation; either version 2.1 of7* the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful, but10* WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public15* License along with this library; if not, write to the Free16* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA17* 02110-1301, USA18*/1920/*21* @file fluidsynth_priv.h22*23* lightweight part of fluid_sys.h, containing forward declarations of fluidsynth's private types and private macros24*25* include this one file in fluidsynth's private header files26*/2728#ifndef _FLUIDSYNTH_PRIV_H29#define _FLUIDSYNTH_PRIV_H3031#include "config.h"3233#include <glib.h>3435#if HAVE_STDLIB_H36#include <stdlib.h> // malloc, free37#endif3839#if HAVE_STDIO_H40#include <stdio.h> // printf41#endif4243#if HAVE_STRING_H44#include <string.h>45#endif4647#if HAVE_STRINGS_H48#include <strings.h>49#endif5051#include "fluidsynth.h"5253#include "wine/debug.h"5455WINE_DEFAULT_DEBUG_CHANNEL(fluidsynth);5657#ifdef __cplusplus58extern "C" {59#endif6061/***************************************************************62*63* BASIC TYPES64*/6566#if defined(WITH_FLOAT)67typedef float fluid_real_t;68#else69typedef double fluid_real_t;70#endif7172#if defined(SUPPORTS_VLA)73# define FLUID_DECLARE_VLA(_type, _name, _len) \74_type _name[_len]75#else76# define FLUID_DECLARE_VLA(_type, _name, _len) \77_type* _name = g_newa(_type, (_len))78#endif798081/** Atomic types */82typedef int fluid_atomic_int_t;83typedef unsigned int fluid_atomic_uint_t;84typedef float fluid_atomic_float_t;858687/***************************************************************88*89* FORWARD DECLARATIONS90*/91typedef struct _fluid_env_data_t fluid_env_data_t;92typedef struct _fluid_adriver_definition_t fluid_adriver_definition_t;93typedef struct _fluid_channel_t fluid_channel_t;94typedef struct _fluid_tuning_t fluid_tuning_t;95typedef struct _fluid_hashtable_t fluid_hashtable_t;96typedef struct _fluid_client_t fluid_client_t;97typedef struct _fluid_server_socket_t fluid_server_socket_t;98typedef struct _fluid_sample_timer_t fluid_sample_timer_t;99typedef struct _fluid_zone_range_t fluid_zone_range_t;100typedef struct _fluid_rvoice_eventhandler_t fluid_rvoice_eventhandler_t;101102/* Declare rvoice related typedefs here instead of fluid_rvoice.h, as it's needed103* in fluid_lfo.c and fluid_adsr.c as well */104typedef union _fluid_rvoice_param_t105{106void *ptr;107int i;108fluid_real_t real;109} fluid_rvoice_param_t;110enum { MAX_EVENT_PARAMS = 7 }; /**< Maximum number of #fluid_rvoice_param_t to be passed to an #fluid_rvoice_function_t */111typedef void (*fluid_rvoice_function_t)(void *obj, const fluid_rvoice_param_t param[MAX_EVENT_PARAMS]);112113/* Macro for declaring an rvoice event function (#fluid_rvoice_function_t). The functions may only access114* those params that were previously set in fluid_voice.c115*/116#define DECLARE_FLUID_RVOICE_FUNCTION(name) void name(void* obj, const fluid_rvoice_param_t param[MAX_EVENT_PARAMS])117118119/***************************************************************120*121* CONSTANTS122*/123124#define FLUID_BUFSIZE 64 /**< FluidSynth internal buffer size (in samples) */125#define FLUID_MIXER_MAX_BUFFERS_DEFAULT (8192/FLUID_BUFSIZE) /**< Number of buffers that can be processed in one rendering run */126#define FLUID_MAX_EVENTS_PER_BUFSIZE 1024 /**< Maximum queued MIDI events per #FLUID_BUFSIZE */127#define FLUID_MAX_RETURN_EVENTS 1024 /**< Maximum queued synthesis thread return events */128#define FLUID_MAX_EVENT_QUEUES 16 /**< Maximum number of unique threads queuing events */129#define FLUID_DEFAULT_AUDIO_RT_PRIO 60 /**< Default setting for audio.realtime-prio */130#define FLUID_DEFAULT_MIDI_RT_PRIO 50 /**< Default setting for midi.realtime-prio */131#define FLUID_NUM_MOD 64 /**< Maximum number of modulators in a voice */132133/***************************************************************134*135* SYSTEM INTERFACE136*/137138/* Math constants */139#ifndef M_PI140#define M_PI 3.1415926535897932384626433832795141#endif142143#ifndef M_LN2144#define M_LN2 0.69314718055994530941723212145818145#endif146147#ifndef M_LN10148#define M_LN10 2.3025850929940456840179914546844149#endif150151#define FLUID_M_PI ((fluid_real_t)M_PI)152#define FLUID_M_LN2 ((fluid_real_t)M_LN2)153#define FLUID_M_LN10 ((fluid_real_t)M_LN10)154155/* Math functions */156#if defined WITH_FLOAT && defined HAVE_SINF157#define FLUID_SIN sinf158#else159#define FLUID_SIN (fluid_real_t)sin160#endif161162#if defined WITH_FLOAT && defined HAVE_COSF163#define FLUID_COS cosf164#else165#define FLUID_COS (fluid_real_t)cos166#endif167168#if defined WITH_FLOAT && defined HAVE_FABSF169#define FLUID_FABS fabsf170#else171#define FLUID_FABS (fluid_real_t)fabs172#endif173174#if defined WITH_FLOAT && defined HAVE_POWF175#define FLUID_POW powf176#else177#define FLUID_POW (fluid_real_t)pow178#endif179180#if defined WITH_FLOAT && defined HAVE_SQRTF181#define FLUID_SQRT sqrtf182#else183#define FLUID_SQRT (fluid_real_t)sqrt184#endif185186#if defined WITH_FLOAT && defined HAVE_LOGF187#define FLUID_LOGF logf188#else189#define FLUID_LOGF (fluid_real_t)log190#endif191192/* Memory allocation */193#define FLUID_MALLOC(_n) fluid_alloc(_n)194#define FLUID_REALLOC(_p,_n) realloc(_p,_n)195#define FLUID_FREE(_p) fluid_free(_p)196#define FLUID_NEW(_t) (_t*)FLUID_MALLOC(sizeof(_t))197#define FLUID_ARRAY_ALIGNED(_t,_n,_a) (_t*)FLUID_MALLOC((_n)*sizeof(_t) + ((unsigned int)_a - 1u))198#define FLUID_ARRAY(_t,_n) FLUID_ARRAY_ALIGNED(_t,_n,1u)199200void* fluid_alloc(size_t len);201202/* File access */203#define FLUID_FOPEN(_f,_m) fluid_fopen(_f,_m)204#define FLUID_FCLOSE(_f) fclose(_f)205#define FLUID_FREAD(_p,_s,_n,_f) fread(_p,_s,_n,_f)206207FILE *fluid_fopen(const char *filename, const char *mode);208209#ifdef _WIN32210#define FLUID_FSEEK(_f,_n,_set) _fseeki64(_f,_n,_set)211#else212#define FLUID_FSEEK(_f,_n,_set) fseek(_f,_n,_set)213#endif214215#define FLUID_FTELL(_f) fluid_file_tell(_f)216217/* Memory functions */218#define FLUID_MEMCPY(_dst,_src,_n) memcpy(_dst,_src,_n)219#define FLUID_MEMSET(_s,_c,_n) memset(_s,_c,_n)220221/* String functions */222#define FLUID_STRLEN(_s) strlen(_s)223#define FLUID_STRCMP(_s,_t) strcmp(_s,_t)224#define FLUID_STRNCMP(_s,_t,_n) strncmp(_s,_t,_n)225#define FLUID_STRCPY(_dst,_src) strcpy(_dst,_src)226#define FLUID_STRTOL(_s,_e,_b) strtol(_s,_e,_b)227228#define FLUID_STRNCPY(_dst,_src,_n) \229do { strncpy(_dst,_src,_n-1); \230(_dst)[(_n)-1]='\0'; \231}while(0)232233#define FLUID_STRCHR(_s,_c) strchr(_s,_c)234#define FLUID_STRRCHR(_s,_c) strrchr(_s,_c)235236#ifdef strdup237#define FLUID_STRDUP(s) strdup(s)238#else239#define FLUID_STRDUP(s) FLUID_STRCPY(FLUID_MALLOC(FLUID_STRLEN(s) + 1), s)240#endif241242#define FLUID_SPRINTF sprintf243#define FLUID_FPRINTF fprintf244245#if (defined(_WIN32) && _MSC_VER < 1900) || defined(MINGW32)246/* need to make sure we use a C99 compliant implementation of (v)snprintf(),247* i.e. not microsofts non compliant extension _snprintf() as it doesn't248* reliably null-terminate the buffer249*/250#define FLUID_SNPRINTF g_snprintf251#else252#define FLUID_SNPRINTF snprintf253#endif254255#if (defined(_WIN32) && _MSC_VER < 1500) || defined(MINGW32)256#define FLUID_VSNPRINTF g_vsnprintf257#else258#define FLUID_VSNPRINTF vsnprintf259#endif260261#if defined(_WIN32) && !defined(MINGW32)262#define FLUID_STRCASECMP _stricmp263#else264#define FLUID_STRCASECMP strcasecmp265#endif266267#if defined(_WIN32) && !defined(MINGW32)268#define FLUID_STRNCASECMP _strnicmp269#else270#define FLUID_STRNCASECMP strncasecmp271#endif272273274#define fluid_clip(_val, _min, _max) \275{ (_val) = ((_val) < (_min))? (_min) : (((_val) > (_max))? (_max) : (_val)); }276277#if WITH_FTS278#define FLUID_PRINTF post279#define FLUID_FLUSH()280#else281#define FLUID_PRINTF WINE_TRACE282#define FLUID_FLUSH()283#endif284285/* People who want to reduce the size of the may do this by entirely286* removing the logging system. This will cause all log messages to287* be discarded at compile time, allowing to save about 80 KiB for288* the compiled binary.289*/290#if 0291#define FLUID_LOG (void)sizeof292#else293#define WINE_FLUID_DBG WINE_TRACE294#define WINE_FLUID_INFO WINE_TRACE295#define WINE_FLUID_WARN WINE_WARN296#define WINE_FLUID_ERR WINE_ERR297#define WINE_FLUID_PANIC WINE_ERR298#define FLUID_LOG( x, msg, ... ) do { WINE_ ## x( msg, ## __VA_ARGS__ ); WINE_ ## x( "\n" ); } while (0)299#endif300301#if defined(DEBUG) && !defined(NDEBUG)302#define FLUID_ASSERT(a) g_assert(a)303#else304#define FLUID_ASSERT(a)305#endif306307#define FLUID_LIKELY G_LIKELY308#define FLUID_UNLIKELY G_UNLIKELY309310/* Misc */311#if defined(__INTEL_COMPILER)312#define FLUID_RESTRICT restrict313#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)314#define FLUID_RESTRICT __restrict__315#elif defined(_MSC_VER) && _MSC_VER >= 1400316#define FLUID_RESTRICT __restrict317#else318#warning "Dont know how this compiler handles restrict pointers, refuse to use them."319#define FLUID_RESTRICT320#endif321322#define FLUID_N_ELEMENTS(struct) (sizeof (struct) / sizeof (struct[0]))323#define FLUID_MEMBER_SIZE(struct, member) ( sizeof (((struct *)0)->member) )324325326#define fluid_return_if_fail(cond) \327if(cond) \328; \329else \330return331332#define fluid_return_val_if_fail(cond, val) \333fluid_return_if_fail(cond) (val)334335#ifdef __cplusplus336}337#endif338339#endif /* _FLUIDSYNTH_PRIV_H */340341342