updated imported aflib sources to OSALP 7.3

This commit is contained in:
darkeye 2002-08-03 10:28:56 +00:00
parent e4da2d70b8
commit 374763d680
7 changed files with 895 additions and 484 deletions

View File

@ -29,6 +29,8 @@ darkice_SOURCES = AudioEncoder.h\
LameLibEncoder.h\
VorbisLibEncoder.cpp\
VorbisLibEncoder.h\
aflibDebug.h\
aflibDebug.cc\
aflibConverter.h\
aflibConverter.cc\
aflibConverterLargeFilter.h\

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@
* 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
*/
@ -26,6 +26,10 @@
#ifndef _AFLIBCONVERTER_H_
#define _AFLIBCONVERTER_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef MAX
#define MAX(x,y) ((x)>(y) ?(x):(y))
#endif
@ -36,11 +40,6 @@
#define MAX_HWORD (32767)
#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 */
/*! \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.
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
number of channels. Once everything is specified then resample should be called as many
times as is necessary to process all the data. The value 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:
initialize should be called to initialize everything. This initialize function will set
the conversion factor as well as a multiplecation factor for volume. The volume only
applies to the small and large filter. Since this filter uses a history of the audio data
it is possible for it to vary in amplitude. This allows users to scale the data. This
class will work on any number of channels. Once everything is specified then resample
should be called as many times as is necessary to process all the data. The value
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.
extra_samples depends on the type of filtering done. As a rule of thumb 50 should be
adequate for any type of filter.
*/
class aflibData;
class aflibConverter {
@ -86,14 +89,15 @@ public:
void
initialize(
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
resample( /* number of output samples returned */
int& inCount, /* number of input samples to convert */
int outCount, /* number of output samples to compute */
HWORD inArray[], /* input array data (length inCount * nChans) */
HWORD outArray[]);/* output array data (length outCount * nChans) */
int outCount, /* number of output samples to compute */
short inArray[], /* input array data (length inCount * nChans) */
short outArray[]);/* output array data (length outCount * nChans) */
private:
@ -114,130 +118,117 @@ private:
int
readData(
int inCount, /* _total_ number of frames in input file */
HWORD inArray[], /* input data */
HWORD *outPtr[], /* array receiving chan samps */
short inArray[], /* input data */
short *outPtr[], /* array receiving chan samps */
int dataArraySize, /* size of these arrays */
int Xoff, /* read into input array starting at this index */
bool init_count);
inline HWORD
WordToHword(WORD v, int scl)
inline short
WordToHword(int v, int scl)
{
HWORD out;
WORD llsb = (1<<(scl-1));
short out;
int llsb = (1<<(scl-1));
v += llsb; /* round */
v >>= scl;
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;
} 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;
}
out = (HWORD) v;
out = (short) v;
return out;
};
int
SrcLinear(
HWORD X[],
HWORD Y[],
short X[],
short Y[],
double factor,
UWORD *Time,
UHWORD& Nx,
UHWORD Nout);
unsigned int *Time,
unsigned short& Nx,
unsigned short Nout);
int
SrcUp(
HWORD X[],
HWORD Y[],
short X[],
short Y[],
double factor,
UWORD *Time,
UHWORD& Nx,
UHWORD Nout,
UHWORD Nwing,
UHWORD LpScl,
HWORD Imp[],
HWORD ImpD[],
BOOL Interp);
unsigned int *Time,
unsigned short& Nx,
unsigned short Nout,
unsigned short Nwing,
unsigned short LpScl,
short Imp[],
short ImpD[],
bool Interp);
int
SrcUD(
HWORD X[],
HWORD Y[],
short X[],
short Y[],
double factor,
UWORD *Time,
UHWORD& Nx,
UHWORD Nout,
UHWORD Nwing,
UHWORD LpScl,
HWORD Imp[],
HWORD ImpD[],
BOOL Interp);
unsigned int *Time,
unsigned short& Nx,
unsigned short Nout,
unsigned short Nwing,
unsigned short LpScl,
short Imp[],
short ImpD[],
bool Interp);
WORD
int
FilterUp(
HWORD Imp[],
HWORD ImpD[],
UHWORD Nwing,
BOOL Interp,
HWORD *Xp,
HWORD Ph,
HWORD Inc);
short Imp[],
short ImpD[],
unsigned short Nwing,
bool Interp,
short *Xp,
short Ph,
short Inc);
WORD
int
FilterUD(
HWORD Imp[],
HWORD ImpD[],
UHWORD Nwing,
BOOL Interp,
HWORD *Xp,
HWORD Ph,
HWORD Inc,
UHWORD dhb);
short Imp[],
short ImpD[],
unsigned short Nwing,
bool Interp,
short *Xp,
short Ph,
short Inc,
unsigned short dhb);
int
resampleFast( /* number of output samples returned */
int& inCount, /* number of input samples to convert */
int outCount, /* number of output samples to compute */
HWORD inArray[], /* input array data (length inCount * nChans) */
HWORD outArray[]);/* output array data (length outCount * nChans) */
short inArray[], /* input array data (length inCount * nChans) */
short outArray[]);/* output array data (length outCount * nChans) */
int
resampleWithFilter( /* number of output samples returned */
int& inCount, /* number of input samples to convert */
int outCount, /* number of output samples to compute */
HWORD inArray[], /* input array data (length inCount * nChans) */
HWORD outArray[], /* output array data (length outCount * nChans) */
HWORD Imp[], HWORD ImpD[],
UHWORD LpScl, UHWORD Nmult, UHWORD Nwing);
short inArray[], /* input array data (length inCount * nChans) */
short outArray[], /* output array data (length outCount * nChans) */
short Imp[], short ImpD[],
unsigned short LpScl, unsigned short Nmult, unsigned short Nwing);
static HWORD SMALL_FILTER_IMP[];
static HWORD LARGE_FILTER_IMP[];
static short SMALL_FILTER_IMP[];
static short LARGE_FILTER_IMP[];
bool interpFilt;
bool largeFilter;
bool linearInterp;
HWORD ** X;
HWORD ** Y;
UWORD Time;
double factor;
int nChans;
bool initial;
short ** _X;
short ** _Y;
unsigned int _Time;
double _factor;
int _nChans;
bool _initial;
double _vol;
};

View File

@ -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_NWING 8192 /* Filter table length */
HWORD aflibConverter::LARGE_FILTER_IMP[] /* Impulse response */ = {
short aflibConverter::LARGE_FILTER_IMP[] /* Impulse response */ = {
32767,
32766,
32764,
@ -8232,7 +8237,7 @@ HWORD aflibConverter::LARGE_FILTER_IMP[] /* Impulse response */ = {
0,
0};
static HWORD LARGE_FILTER_IMPD[] /* Impulse response differences */ = {
static short LARGE_FILTER_IMPD[] /* Impulse response differences */ = {
-1,
-2,
-3,

View File

@ -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_NWING 1536 /* Filter table length */
HWORD aflibConverter::SMALL_FILTER_IMP[] /* Impulse response */ = {
short aflibConverter::SMALL_FILTER_IMP[] /* Impulse response */ = {
32767,
32766,
32764,
@ -1562,7 +1567,7 @@ HWORD aflibConverter::SMALL_FILTER_IMP[] /* Impulse response */ = {
-1
};
static HWORD SMALL_FILTER_IMPD[] = {
static short SMALL_FILTER_IMPD[] = {
-1,
-2,
-4,

View File

@ -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);
}

View File

@ -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