updated imported aflib sources to OSALP 7.3
This commit is contained in:
parent
e4da2d70b8
commit
374763d680
|
@ -29,6 +29,8 @@ darkice_SOURCES = AudioEncoder.h\
|
||||||
LameLibEncoder.h\
|
LameLibEncoder.h\
|
||||||
VorbisLibEncoder.cpp\
|
VorbisLibEncoder.cpp\
|
||||||
VorbisLibEncoder.h\
|
VorbisLibEncoder.h\
|
||||||
|
aflibDebug.h\
|
||||||
|
aflibDebug.cc\
|
||||||
aflibConverter.h\
|
aflibConverter.h\
|
||||||
aflibConverter.cc\
|
aflibConverter.cc\
|
||||||
aflibConverterLargeFilter.h\
|
aflibConverterLargeFilter.h\
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,7 +18,7 @@
|
||||||
* Julius O. Smith jos@ccrma.stanford.edu
|
* Julius O. Smith jos@ccrma.stanford.edu
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* This code was modified by Bruce Forsberg (forsberg@adnc.com) to make it
|
/* This code was modified by Bruce Forsberg (forsberg@tns.net) to make it
|
||||||
into a C++ class
|
into a C++ class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@
|
||||||
#ifndef _AFLIBCONVERTER_H_
|
#ifndef _AFLIBCONVERTER_H_
|
||||||
#define _AFLIBCONVERTER_H_
|
#define _AFLIBCONVERTER_H_
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
#define MAX(x,y) ((x)>(y) ?(x):(y))
|
#define MAX(x,y) ((x)>(y) ?(x):(y))
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,11 +40,6 @@
|
||||||
#define MAX_HWORD (32767)
|
#define MAX_HWORD (32767)
|
||||||
#define MIN_HWORD (-32768)
|
#define MIN_HWORD (-32768)
|
||||||
|
|
||||||
typedef char BOOL;
|
|
||||||
typedef short HWORD;
|
|
||||||
typedef unsigned short UHWORD;
|
|
||||||
typedef int WORD;
|
|
||||||
typedef unsigned int UWORD;
|
|
||||||
#define IBUFFSIZE 4096 /* Input buffer size */
|
#define IBUFFSIZE 4096 /* Input buffer size */
|
||||||
|
|
||||||
/*! \class aflibConverter
|
/*! \class aflibConverter
|
||||||
|
@ -58,18 +57,22 @@ typedef unsigned int UWORD;
|
||||||
|
|
||||||
This class was designed to stream audio data. It also expects audio data as 16 bit values.
|
This class was designed to stream audio data. It also expects audio data as 16 bit values.
|
||||||
Each time a new stream is started some initialization needs to be done. Thus the function
|
Each time a new stream is started some initialization needs to be done. Thus the function
|
||||||
initialize should be called to initialize everything. This class will work on any
|
initialize should be called to initialize everything. This initialize function will set
|
||||||
number of channels. Once everything is specified then resample should be called as many
|
the conversion factor as well as a multiplecation factor for volume. The volume only
|
||||||
times as is necessary to process all the data. The value inCount will be returned
|
applies to the small and large filter. Since this filter uses a history of the audio data
|
||||||
indicating how many inArray samples were actually used to produce the output. This
|
it is possible for it to vary in amplitude. This allows users to scale the data. This
|
||||||
value can be used to indicate where the next block of inArray data should start. The
|
class will work on any number of channels. Once everything is specified then resample
|
||||||
resample function is driven by the outCount value specified. The inArray should
|
should be called as many times as is necessary to process all the data. The value
|
||||||
contain at least:
|
inCount will be returned indicating how many inArray samples were actually used to
|
||||||
|
produce the output. This value can be used to indicate where the next block of
|
||||||
|
inArray data should start. The resample function is driven by the outCount value
|
||||||
|
specified. The inArray should contain at least:
|
||||||
outCount / factor + extra_samples.
|
outCount / factor + extra_samples.
|
||||||
extra_samples depends on the type of filtering done. As a rule of thumb 50 should be
|
extra_samples depends on the type of filtering done. As a rule of thumb 50 should be
|
||||||
adequate for any type of filter.
|
adequate for any type of filter.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
class aflibData;
|
||||||
|
|
||||||
class aflibConverter {
|
class aflibConverter {
|
||||||
|
|
||||||
|
@ -86,14 +89,15 @@ public:
|
||||||
void
|
void
|
||||||
initialize(
|
initialize(
|
||||||
double factor, /* factor = Sndout/Sndin */
|
double factor, /* factor = Sndout/Sndin */
|
||||||
int channels);/* number of sound channels */
|
int channels, /* number of sound channels */
|
||||||
|
double volume = 1.0); /* factor to multiply amplitude */
|
||||||
|
|
||||||
int
|
int
|
||||||
resample( /* number of output samples returned */
|
resample( /* number of output samples returned */
|
||||||
int& inCount, /* number of input samples to convert */
|
int& inCount, /* number of input samples to convert */
|
||||||
int outCount, /* number of output samples to compute */
|
int outCount, /* number of output samples to compute */
|
||||||
HWORD inArray[], /* input array data (length inCount * nChans) */
|
short inArray[], /* input array data (length inCount * nChans) */
|
||||||
HWORD outArray[]);/* output array data (length outCount * nChans) */
|
short outArray[]);/* output array data (length outCount * nChans) */
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -114,130 +118,117 @@ private:
|
||||||
int
|
int
|
||||||
readData(
|
readData(
|
||||||
int inCount, /* _total_ number of frames in input file */
|
int inCount, /* _total_ number of frames in input file */
|
||||||
HWORD inArray[], /* input data */
|
short inArray[], /* input data */
|
||||||
HWORD *outPtr[], /* array receiving chan samps */
|
short *outPtr[], /* array receiving chan samps */
|
||||||
int dataArraySize, /* size of these arrays */
|
int dataArraySize, /* size of these arrays */
|
||||||
int Xoff, /* read into input array starting at this index */
|
int Xoff, /* read into input array starting at this index */
|
||||||
bool init_count);
|
bool init_count);
|
||||||
|
|
||||||
|
|
||||||
inline HWORD
|
inline short
|
||||||
WordToHword(WORD v, int scl)
|
WordToHword(int v, int scl)
|
||||||
{
|
{
|
||||||
HWORD out;
|
short out;
|
||||||
WORD llsb = (1<<(scl-1));
|
int llsb = (1<<(scl-1));
|
||||||
v += llsb; /* round */
|
v += llsb; /* round */
|
||||||
v >>= scl;
|
v >>= scl;
|
||||||
if (v>MAX_HWORD) {
|
if (v>MAX_HWORD) {
|
||||||
#ifdef DEBUG
|
|
||||||
if (pof == 0)
|
|
||||||
fprintf(stderr, "*** resample: sound sample overflow\n");
|
|
||||||
else if ((pof % 10000) == 0)
|
|
||||||
fprintf(stderr, "*** resample: another ten thousand overflows\n");
|
|
||||||
pof++;
|
|
||||||
#endif
|
|
||||||
v = MAX_HWORD;
|
v = MAX_HWORD;
|
||||||
} else if (v < MIN_HWORD) {
|
} else if (v < MIN_HWORD) {
|
||||||
#ifdef DEBUG
|
|
||||||
if (nof == 0)
|
|
||||||
fprintf(stderr, "*** resample: sound sample (-) overflow\n");
|
|
||||||
else if ((nof % 1000) == 0)
|
|
||||||
fprintf(stderr, "*** resample: another thousand (-) overflows\n");
|
|
||||||
nof++;
|
|
||||||
#endif
|
|
||||||
v = MIN_HWORD;
|
v = MIN_HWORD;
|
||||||
}
|
}
|
||||||
out = (HWORD) v;
|
out = (short) v;
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
SrcLinear(
|
SrcLinear(
|
||||||
HWORD X[],
|
short X[],
|
||||||
HWORD Y[],
|
short Y[],
|
||||||
double factor,
|
double factor,
|
||||||
UWORD *Time,
|
unsigned int *Time,
|
||||||
UHWORD& Nx,
|
unsigned short& Nx,
|
||||||
UHWORD Nout);
|
unsigned short Nout);
|
||||||
|
|
||||||
int
|
int
|
||||||
SrcUp(
|
SrcUp(
|
||||||
HWORD X[],
|
short X[],
|
||||||
HWORD Y[],
|
short Y[],
|
||||||
double factor,
|
double factor,
|
||||||
UWORD *Time,
|
unsigned int *Time,
|
||||||
UHWORD& Nx,
|
unsigned short& Nx,
|
||||||
UHWORD Nout,
|
unsigned short Nout,
|
||||||
UHWORD Nwing,
|
unsigned short Nwing,
|
||||||
UHWORD LpScl,
|
unsigned short LpScl,
|
||||||
HWORD Imp[],
|
short Imp[],
|
||||||
HWORD ImpD[],
|
short ImpD[],
|
||||||
BOOL Interp);
|
bool Interp);
|
||||||
|
|
||||||
int
|
int
|
||||||
SrcUD(
|
SrcUD(
|
||||||
HWORD X[],
|
short X[],
|
||||||
HWORD Y[],
|
short Y[],
|
||||||
double factor,
|
double factor,
|
||||||
UWORD *Time,
|
unsigned int *Time,
|
||||||
UHWORD& Nx,
|
unsigned short& Nx,
|
||||||
UHWORD Nout,
|
unsigned short Nout,
|
||||||
UHWORD Nwing,
|
unsigned short Nwing,
|
||||||
UHWORD LpScl,
|
unsigned short LpScl,
|
||||||
HWORD Imp[],
|
short Imp[],
|
||||||
HWORD ImpD[],
|
short ImpD[],
|
||||||
BOOL Interp);
|
bool Interp);
|
||||||
|
|
||||||
WORD
|
int
|
||||||
FilterUp(
|
FilterUp(
|
||||||
HWORD Imp[],
|
short Imp[],
|
||||||
HWORD ImpD[],
|
short ImpD[],
|
||||||
UHWORD Nwing,
|
unsigned short Nwing,
|
||||||
BOOL Interp,
|
bool Interp,
|
||||||
HWORD *Xp,
|
short *Xp,
|
||||||
HWORD Ph,
|
short Ph,
|
||||||
HWORD Inc);
|
short Inc);
|
||||||
|
|
||||||
WORD
|
int
|
||||||
FilterUD(
|
FilterUD(
|
||||||
HWORD Imp[],
|
short Imp[],
|
||||||
HWORD ImpD[],
|
short ImpD[],
|
||||||
UHWORD Nwing,
|
unsigned short Nwing,
|
||||||
BOOL Interp,
|
bool Interp,
|
||||||
HWORD *Xp,
|
short *Xp,
|
||||||
HWORD Ph,
|
short Ph,
|
||||||
HWORD Inc,
|
short Inc,
|
||||||
UHWORD dhb);
|
unsigned short dhb);
|
||||||
|
|
||||||
int
|
int
|
||||||
resampleFast( /* number of output samples returned */
|
resampleFast( /* number of output samples returned */
|
||||||
int& inCount, /* number of input samples to convert */
|
int& inCount, /* number of input samples to convert */
|
||||||
int outCount, /* number of output samples to compute */
|
int outCount, /* number of output samples to compute */
|
||||||
HWORD inArray[], /* input array data (length inCount * nChans) */
|
short inArray[], /* input array data (length inCount * nChans) */
|
||||||
HWORD outArray[]);/* output array data (length outCount * nChans) */
|
short outArray[]);/* output array data (length outCount * nChans) */
|
||||||
|
|
||||||
int
|
int
|
||||||
resampleWithFilter( /* number of output samples returned */
|
resampleWithFilter( /* number of output samples returned */
|
||||||
int& inCount, /* number of input samples to convert */
|
int& inCount, /* number of input samples to convert */
|
||||||
int outCount, /* number of output samples to compute */
|
int outCount, /* number of output samples to compute */
|
||||||
HWORD inArray[], /* input array data (length inCount * nChans) */
|
short inArray[], /* input array data (length inCount * nChans) */
|
||||||
HWORD outArray[], /* output array data (length outCount * nChans) */
|
short outArray[], /* output array data (length outCount * nChans) */
|
||||||
HWORD Imp[], HWORD ImpD[],
|
short Imp[], short ImpD[],
|
||||||
UHWORD LpScl, UHWORD Nmult, UHWORD Nwing);
|
unsigned short LpScl, unsigned short Nmult, unsigned short Nwing);
|
||||||
|
|
||||||
|
|
||||||
static HWORD SMALL_FILTER_IMP[];
|
static short SMALL_FILTER_IMP[];
|
||||||
static HWORD LARGE_FILTER_IMP[];
|
static short LARGE_FILTER_IMP[];
|
||||||
|
|
||||||
bool interpFilt;
|
bool interpFilt;
|
||||||
bool largeFilter;
|
bool largeFilter;
|
||||||
bool linearInterp;
|
bool linearInterp;
|
||||||
HWORD ** X;
|
short ** _X;
|
||||||
HWORD ** Y;
|
short ** _Y;
|
||||||
UWORD Time;
|
unsigned int _Time;
|
||||||
double factor;
|
double _factor;
|
||||||
int nChans;
|
int _nChans;
|
||||||
bool initial;
|
bool _initial;
|
||||||
|
double _vol;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,16 @@ well for its level of computational expense.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LARGE_FILTER_NMULT ((HWORD)65)
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define LARGE_FILTER_NMULT ((short)65)
|
||||||
#define LARGE_FILTER_SCALE 14746 /* Unity-gain scale factor */
|
#define LARGE_FILTER_SCALE 14746 /* Unity-gain scale factor */
|
||||||
#define LARGE_FILTER_NWING 8192 /* Filter table length */
|
#define LARGE_FILTER_NWING 8192 /* Filter table length */
|
||||||
|
|
||||||
HWORD aflibConverter::LARGE_FILTER_IMP[] /* Impulse response */ = {
|
short aflibConverter::LARGE_FILTER_IMP[] /* Impulse response */ = {
|
||||||
32767,
|
32767,
|
||||||
32766,
|
32766,
|
||||||
32764,
|
32764,
|
||||||
|
@ -8232,7 +8237,7 @@ HWORD aflibConverter::LARGE_FILTER_IMP[] /* Impulse response */ = {
|
||||||
0,
|
0,
|
||||||
0};
|
0};
|
||||||
|
|
||||||
static HWORD LARGE_FILTER_IMPD[] /* Impulse response differences */ = {
|
static short LARGE_FILTER_IMPD[] /* Impulse response differences */ = {
|
||||||
-1,
|
-1,
|
||||||
-2,
|
-2,
|
||||||
-3,
|
-3,
|
||||||
|
|
|
@ -19,11 +19,16 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SMALL_FILTER_NMULT ((HWORD)13)
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SMALL_FILTER_NMULT ((short)13)
|
||||||
#define SMALL_FILTER_SCALE 13128 /* Unity-gain scale factor */
|
#define SMALL_FILTER_SCALE 13128 /* Unity-gain scale factor */
|
||||||
#define SMALL_FILTER_NWING 1536 /* Filter table length */
|
#define SMALL_FILTER_NWING 1536 /* Filter table length */
|
||||||
|
|
||||||
HWORD aflibConverter::SMALL_FILTER_IMP[] /* Impulse response */ = {
|
short aflibConverter::SMALL_FILTER_IMP[] /* Impulse response */ = {
|
||||||
32767,
|
32767,
|
||||||
32766,
|
32766,
|
||||||
32764,
|
32764,
|
||||||
|
@ -1562,7 +1567,7 @@ HWORD aflibConverter::SMALL_FILTER_IMP[] /* Impulse response */ = {
|
||||||
-1
|
-1
|
||||||
};
|
};
|
||||||
|
|
||||||
static HWORD SMALL_FILTER_IMPD[] = {
|
static short SMALL_FILTER_IMPD[] = {
|
||||||
-1,
|
-1,
|
||||||
-2,
|
-2,
|
||||||
-4,
|
-4,
|
||||||
|
|
|
@ -0,0 +1,228 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2000 Stefan Westerfeld
|
||||||
|
stefan@space.twc.de
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "aflibDebug.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static int aflib_debug_level = ::aflibDebug::lInfo;
|
||||||
|
static bool aflib_debug_abort = false;
|
||||||
|
static const char *aflib_debug_prefix = "";
|
||||||
|
static char *messageAppName = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
static char* status_strs[] =
|
||||||
|
{
|
||||||
|
"Success",
|
||||||
|
"Error Open",
|
||||||
|
"Unsupported",
|
||||||
|
"AFLIB_ERROR_INITIALIZATION_FAILURE",
|
||||||
|
"AFLIB_NOT_FOUND",
|
||||||
|
"AFLIB_END_OF_FILE",
|
||||||
|
"AFLIB_NO_DATA",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static char* data_size_strs[] =
|
||||||
|
{
|
||||||
|
"UNDEFINED",
|
||||||
|
"8 bit signed",
|
||||||
|
"8 bit unsigned",
|
||||||
|
"16 bit signed",
|
||||||
|
"16 bit unsigned",
|
||||||
|
"32 bit signed",
|
||||||
|
"32 bit unsigned",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
static char* data_endian_strs[] =
|
||||||
|
{
|
||||||
|
"UNDEFINED",
|
||||||
|
"ENDIAN_LITTLE",
|
||||||
|
"ENDIAN_BIG",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Call the graphical application to display a message, if
|
||||||
|
* defined. Otherwise, send to standard error. Debug messages are
|
||||||
|
* always sent to standard error because they tend to be very verbose.
|
||||||
|
* Note that the external application is run in the background to
|
||||||
|
* avoid blocking the sound server.
|
||||||
|
*/
|
||||||
|
void output_message(::aflibDebug::Level level, const char *msg) {
|
||||||
|
char buff[1024];
|
||||||
|
|
||||||
|
/* default to text output if no message app is defined or if it is a debug message. */
|
||||||
|
if (messageAppName == 0 || !strcmp(messageAppName, "") || (level == ::aflibDebug::lDebug))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s\n", msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (level) {
|
||||||
|
case ::aflibDebug::lFatal:
|
||||||
|
sprintf(buff, "%s -e \"aflib fatal error:\n\n%s\" &", messageAppName, msg);
|
||||||
|
break;
|
||||||
|
case ::aflibDebug::lWarning:
|
||||||
|
sprintf(buff, "%s -w \"aflib warning message:\n\n%s\" &", messageAppName, msg);
|
||||||
|
break;
|
||||||
|
case ::aflibDebug::lInfo:
|
||||||
|
sprintf(buff, "%s -i \"aflib informational message:\n\n%s\" &", messageAppName, msg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break; // avoid compile warning
|
||||||
|
}
|
||||||
|
system(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Display a message using output_message. If the message is the same
|
||||||
|
* as the previous one, just increment a count but don't display
|
||||||
|
* it. This prevents flooding the user with duplicate warnings. If the
|
||||||
|
* message is not the same as the previous one, then we report the
|
||||||
|
* previously repeated message (if any) and reset the last message and
|
||||||
|
* count.
|
||||||
|
*/
|
||||||
|
void display_message(::aflibDebug::Level level, const char *msg) {
|
||||||
|
static char lastMsg[1024];
|
||||||
|
static ::aflibDebug::Level lastLevel;
|
||||||
|
static int msgCount = 0;
|
||||||
|
|
||||||
|
if (!strncmp(msg, lastMsg, 1024))
|
||||||
|
{
|
||||||
|
msgCount++;
|
||||||
|
} else {
|
||||||
|
if (msgCount > 0)
|
||||||
|
{
|
||||||
|
char buff[1024];
|
||||||
|
sprintf(buff, "%s\n(The previous message was repeated %d times.)", lastMsg, msgCount);
|
||||||
|
output_message(lastLevel, buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(lastMsg, msg, 1024);
|
||||||
|
lastLevel = level;
|
||||||
|
msgCount = 0;
|
||||||
|
output_message(level, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class DebugInitFromEnv {
|
||||||
|
|
||||||
|
public:
|
||||||
|
DebugInitFromEnv() {
|
||||||
|
const char *env = getenv("AFLIB_DEBUG");
|
||||||
|
if(env)
|
||||||
|
{
|
||||||
|
if(strcmp(env,"debug") == 0)
|
||||||
|
aflib_debug_level = ::aflibDebug::lDebug;
|
||||||
|
else if(strcmp(env,"info") == 0)
|
||||||
|
aflib_debug_level = ::aflibDebug::lInfo;
|
||||||
|
else if(strcmp(env,"warning") == 0)
|
||||||
|
aflib_debug_level = ::aflibDebug::lWarning;
|
||||||
|
else if(strcmp(env,"quiet") == 0)
|
||||||
|
aflib_debug_level = ::aflibDebug::lFatal;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"AFLIB_DEBUG must be one of debug,info,warning,quiet\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env = getenv("AFLIB_DEBUG_ABORT");
|
||||||
|
if(env)
|
||||||
|
aflib_debug_abort = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debugInitFromEnv;
|
||||||
|
|
||||||
|
|
||||||
|
void aflibDebug::init(const char *prefix, Level level)
|
||||||
|
{
|
||||||
|
aflib_debug_level = level;
|
||||||
|
aflib_debug_prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void aflibDebug::fatal(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buff[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsprintf(buff, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
display_message(::aflibDebug::lFatal, buff);
|
||||||
|
|
||||||
|
if(aflib_debug_abort) abort();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void aflibDebug::warning(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(lWarning >= aflib_debug_level)
|
||||||
|
{
|
||||||
|
char buff[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsprintf(buff, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
display_message(::aflibDebug::lWarning, buff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void aflibDebug::info(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(lInfo >= aflib_debug_level)
|
||||||
|
{
|
||||||
|
char buff[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsprintf(buff, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
display_message(::aflibDebug::lInfo, buff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void aflibDebug::debug(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if(lDebug >= aflib_debug_level)
|
||||||
|
{
|
||||||
|
char buff[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsprintf(buff, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
display_message(::aflibDebug::lDebug, buff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void aflibDebug::messageApp(const char *appName)
|
||||||
|
{
|
||||||
|
messageAppName = (char*) realloc(messageAppName, strlen(appName)+1);
|
||||||
|
strcpy(messageAppName, appName);
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
Copyright (C) 2000 Stefan Westerfeld
|
||||||
|
stefan@space.twc.de
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Library General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Library General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Library General Public License
|
||||||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
|
||||||
|
Some inspiration taken from glib.
|
||||||
|
Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
|
Modified by the GLib Team and others 1997-1999.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _AFLIBDEBUG_H_
|
||||||
|
#define _AFLIBDEBUG_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BC - Status (2000-09-30): Debug.
|
||||||
|
*
|
||||||
|
* Collection class, no instance, no members. Thus binary compatible (will
|
||||||
|
* be kept).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define aflib_fatal ::aflibDebug::fatal
|
||||||
|
#define aflib_warning ::aflibDebug::warning
|
||||||
|
#define aflib_info ::aflibDebug::info
|
||||||
|
#define aflib_debug ::aflibDebug::debug
|
||||||
|
|
||||||
|
/* source compatibility with older sources */
|
||||||
|
#define aflibdebug ::aflibDebug::debug
|
||||||
|
#define setaflibdebug(x) aflib_warning("setaflibdebug is obsolete")
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
|
||||||
|
#define aflib_return_if_fail(expr) \
|
||||||
|
if (!(expr)) \
|
||||||
|
{ \
|
||||||
|
aflib_warning ("file %s: line %d (%s): assertion failed: (%s)", \
|
||||||
|
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define aflib_return_val_if_fail(expr,val) \
|
||||||
|
if (!(expr)) \
|
||||||
|
{ \
|
||||||
|
aflib_warning ("file %s: line %d (%s): assertion failed: (%s)", \
|
||||||
|
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
|
||||||
|
return (val); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define aflib_assert(expr) \
|
||||||
|
if (!(expr)) \
|
||||||
|
aflib_fatal ("file %s: line %d (%s): assertion failed: (%s)", \
|
||||||
|
__FILE__, __LINE__, __PRETTY_FUNCTION__, #expr); \
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define aflib_return_if_fail(expr) \
|
||||||
|
if (!(expr)) \
|
||||||
|
{ \
|
||||||
|
aflib_warning ("file %s: line %d: assertion failed: (%s)", \
|
||||||
|
__FILE__, __LINE__, #expr); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define aflib_return_val_if_fail(expr,val) \
|
||||||
|
if (!(expr)) \
|
||||||
|
{ \
|
||||||
|
aflib_warning ("file %s: line %d: assertion failed: (%s)", \
|
||||||
|
__FILE__, __LINE__, #expr); \
|
||||||
|
return (val); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define aflib_assert(expr) \
|
||||||
|
if (!(expr)) \
|
||||||
|
aflib_fatal ("file %s: line %d: assertion failed: (%s)", \
|
||||||
|
__FILE__, __LINE__, #expr); \
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class aflibDebug {
|
||||||
|
public:
|
||||||
|
enum Level { lFatal = 3, lWarning = 2, lInfo = 1, lDebug = 0 };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes at which is the minimum level to react to. If you
|
||||||
|
* call this, call this before creating the Arts::Dispatcher object.
|
||||||
|
*/
|
||||||
|
static void init(const char *prefix, Level level);
|
||||||
|
|
||||||
|
static void fatal(const char *fmt,...); // print on stderr & abort
|
||||||
|
static void warning(const char *fmt,...); // print on stderr
|
||||||
|
static void info(const char *fmt,...); // print on stdout
|
||||||
|
static void debug(const char *fmt,...); // print on stdout
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method sets the name of an external application to
|
||||||
|
* display messages graphically.
|
||||||
|
*/
|
||||||
|
static void messageApp(const char *appName);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue