Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

aflibConverter.h

Go to the documentation of this file.
00001 /*
00002  * Copyright: (C) 2000 Julius O. Smith
00003  *
00004  *   This library is free software; you can redistribute it and/or
00005  *   modify it under the terms of the GNU Lesser General Public
00006  *   License as published by the Free Software Foundation; either
00007  *   version 2.1 of the License, or any later version.
00008  *
00009  *   This library is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *   Lesser General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU Lesser General Public
00015  *   License along with this library; if not, write to the Free Software
00016  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00017  *
00018  *   Julius O. Smith  jos@ccrma.stanford.edu
00019  *
00020  */
00021 /* This code was modified by Bruce Forsberg (forsberg@adnc.com) to make it
00022    into a C++ class
00023 */
00024 
00025 
00026 #ifndef _AFLIBCONVERTER_H_
00027 #define _AFLIBCONVERTER_H_
00028 
00029 #ifndef MAX
00030 #define MAX(x,y) ((x)>(y) ?(x):(y))
00031 #endif
00032 #ifndef MIN
00033 #define MIN(x,y) ((x)<(y) ?(x):(y))
00034 #endif
00035 
00036 #define MAX_HWORD (32767)
00037 #define MIN_HWORD (-32768)
00038 
00039 typedef char           BOOL;
00040 typedef short          HWORD;
00041 typedef unsigned short UHWORD;
00042 typedef int            WORD;
00043 typedef unsigned int   UWORD;
00044 #define IBUFFSIZE 4096                         /* Input buffer size */
00045 
00074 class aflibConverter {
00075 
00076 public:
00077 
00078    // Available contructors and destructors
00079    aflibConverter (
00080       bool  high_quality,
00081       bool  linear_interpolation,
00082       bool  filter_interpolation);
00083 
00084    ~aflibConverter();
00085 
00086    void
00087    initialize(
00088       double factor,   /* factor = Sndout/Sndin */
00089       int    channels);/* number of sound channels */
00090 
00091    int
00092    resample(           /* number of output samples returned */
00093       int& inCount,    /* number of input samples to convert */
00094       int outCount,    /* number of output samples to compute */
00095       HWORD inArray[], /* input array data (length inCount * nChans) */
00096       HWORD outArray[]);/* output array data (length outCount * nChans) */
00097  
00098  
00099 private:
00100 
00101    aflibConverter();
00102 
00103    aflibConverter(const aflibConverter& op);
00104 
00105    const aflibConverter&
00106    operator=(const aflibConverter& op);
00107 
00108    int
00109    err_ret(char *s);
00110 
00111    void
00112    deleteMemory();
00113 
00114    int
00115    readData(
00116       int   inCount,       /* _total_ number of frames in input file */
00117       HWORD inArray[],     /* input data */
00118       HWORD *outPtr[],     /* array receiving chan samps */
00119       int   dataArraySize, /* size of these arrays */
00120       int   Xoff,          /* read into input array starting at this index */
00121       bool  init_count);
00122 
00123 
00124    inline HWORD
00125    WordToHword(WORD v, int scl)
00126    {
00127        HWORD out;
00128        WORD llsb = (1<<(scl-1));
00129        v += llsb;          /* round */
00130        v >>= scl;
00131        if (v>MAX_HWORD) {
00132 #ifdef DEBUG
00133            if (pof == 0)
00134              fprintf(stderr, "*** resample: sound sample overflow\n");
00135            else if ((pof % 10000) == 0)
00136              fprintf(stderr, "*** resample: another ten thousand overflows\n");
00137            pof++;
00138 #endif
00139            v = MAX_HWORD;
00140        } else if (v < MIN_HWORD) {
00141 #ifdef DEBUG
00142            if (nof == 0)
00143              fprintf(stderr, "*** resample: sound sample (-) overflow\n");
00144            else if ((nof % 1000) == 0)
00145              fprintf(stderr, "*** resample: another thousand (-) overflows\n");
00146            nof++;
00147 #endif
00148            v = MIN_HWORD;
00149        }
00150        out = (HWORD) v;
00151        return out;
00152    };
00153 
00154    int
00155    SrcLinear(
00156       HWORD X[],
00157       HWORD Y[],
00158       double factor,
00159       UWORD *Time,
00160       UHWORD& Nx,
00161       UHWORD Nout);
00162 
00163    int
00164    SrcUp(
00165       HWORD X[],
00166       HWORD Y[],
00167       double factor,
00168       UWORD *Time,
00169       UHWORD& Nx,
00170       UHWORD Nout,
00171       UHWORD Nwing,
00172       UHWORD LpScl,
00173       HWORD Imp[],
00174       HWORD ImpD[],
00175       BOOL Interp);
00176 
00177    int
00178    SrcUD(
00179       HWORD X[],
00180       HWORD Y[],
00181       double factor,
00182       UWORD *Time,
00183       UHWORD& Nx,
00184       UHWORD Nout,
00185       UHWORD Nwing,
00186       UHWORD LpScl,
00187       HWORD Imp[],
00188       HWORD ImpD[],
00189       BOOL Interp);
00190 
00191    WORD
00192    FilterUp(
00193       HWORD Imp[],
00194       HWORD ImpD[],
00195       UHWORD Nwing,
00196       BOOL Interp,
00197       HWORD *Xp,
00198       HWORD Ph,
00199       HWORD Inc);
00200 
00201    WORD
00202    FilterUD(
00203       HWORD Imp[],
00204       HWORD ImpD[],
00205       UHWORD Nwing,
00206       BOOL Interp,
00207       HWORD *Xp,
00208       HWORD Ph,
00209       HWORD Inc,
00210       UHWORD dhb);
00211 
00212    int
00213    resampleFast(  /* number of output samples returned */
00214       int& inCount,     /* number of input samples to convert */
00215       int outCount,    /* number of output samples to compute */
00216       HWORD inArray[], /* input array data (length inCount * nChans) */
00217       HWORD outArray[]);/* output array data (length outCount * nChans) */
00218  
00219    int
00220    resampleWithFilter(  /* number of output samples returned */
00221       int& inCount,      /* number of input samples to convert */
00222       int outCount,     /* number of output samples to compute */
00223       HWORD inArray[],  /* input array data (length inCount * nChans) */
00224       HWORD outArray[], /* output array data (length outCount * nChans) */
00225       HWORD Imp[], HWORD ImpD[],
00226       UHWORD LpScl, UHWORD Nmult, UHWORD Nwing);
00227 
00228 
00229 static HWORD SMALL_FILTER_IMP[];
00230 static HWORD LARGE_FILTER_IMP[];
00231 
00232 bool    interpFilt;
00233 bool    largeFilter;
00234 bool    linearInterp;
00235 HWORD  ** X;
00236 HWORD  ** Y;
00237 UWORD   Time;
00238 double  factor;
00239 int     nChans;
00240 bool    initial;
00241 
00242 };
00243 
00244 
00245 #endif

Generated at Sun May 13 16:18:53 2001 for Open Source Audio Library Project by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001