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@tns.net) to make it
00022    into a C++ class
00023 */
00024 
00025 
00026 #ifndef _AFLIBCONVERTER_H_
00027 #define _AFLIBCONVERTER_H_
00028 
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032 
00033 #ifndef MAX
00034 #define MAX(x,y) ((x)>(y) ?(x):(y))
00035 #endif
00036 #ifndef MIN
00037 #define MIN(x,y) ((x)<(y) ?(x):(y))
00038 #endif
00039 
00040 #define MAX_HWORD (32767)
00041 #define MIN_HWORD (-32768)
00042 
00043 #define IBUFFSIZE 4096                         /* Input buffer size */
00044 
00075 class aflibData;
00076 
00077 class aflibConverter {
00078 
00079 public:
00080 
00081    // Available contructors and destructors
00082    aflibConverter (
00083       bool  high_quality,
00084       bool  linear_interpolation,
00085       bool  filter_interpolation);
00086 
00087    ~aflibConverter();
00088 
00089    void
00090    initialize(
00091       double factor,   /* factor = Sndout/Sndin */
00092       int    channels, /* number of sound channels */
00093       double volume = 1.0); /* factor to multiply amplitude */
00094 
00095    int
00096    resample(           /* number of output samples returned */
00097       int& inCount,    /* number of input samples to convert */
00098         int outCount,    /* number of output samples to compute */
00099       short inArray[], /* input array data (length inCount * nChans) */
00100       short outArray[]);/* output array data (length outCount * nChans) */
00101  
00102  
00103 private:
00104 
00105    aflibConverter();
00106 
00107    aflibConverter(const aflibConverter& op);
00108 
00109    const aflibConverter&
00110    operator=(const aflibConverter& op);
00111 
00112    int
00113    err_ret(char *s);
00114 
00115    void
00116    deleteMemory();
00117 
00118    int
00119    readData(
00120       int   inCount,       /* _total_ number of frames in input file */
00121       short inArray[],     /* input data */
00122       short *outPtr[],     /* array receiving chan samps */
00123       int   dataArraySize, /* size of these arrays */
00124       int   Xoff,          /* read into input array starting at this index */
00125       bool  init_count);
00126 
00127 
00128    inline short
00129    WordToHword(int v, int scl)
00130    {
00131        short out;
00132        int llsb = (1<<(scl-1));
00133        v += llsb;          /* round */
00134        v >>= scl;
00135        if (v>MAX_HWORD) {
00136            v = MAX_HWORD;
00137        } else if (v < MIN_HWORD) {
00138            v = MIN_HWORD;
00139        }
00140        out = (short) v;
00141        return out;
00142    };
00143 
00144    int
00145    SrcLinear(
00146       short X[],
00147       short Y[],
00148       double factor,
00149       unsigned int *Time,
00150       unsigned short& Nx,
00151       unsigned short Nout);
00152 
00153    int
00154    SrcUp(
00155       short X[],
00156       short Y[],
00157       double factor,
00158       unsigned int *Time,
00159       unsigned short& Nx,
00160       unsigned short Nout,
00161       unsigned short Nwing,
00162       unsigned short LpScl,
00163       short Imp[],
00164       short ImpD[],
00165       bool Interp);
00166 
00167    int
00168    SrcUD(
00169       short X[],
00170       short Y[],
00171       double factor,
00172       unsigned int *Time,
00173       unsigned short& Nx,
00174       unsigned short Nout,
00175       unsigned short Nwing,
00176       unsigned short LpScl,
00177       short Imp[],
00178       short ImpD[],
00179       bool Interp);
00180 
00181    int
00182    FilterUp(
00183       short Imp[],
00184       short ImpD[],
00185       unsigned short Nwing,
00186       bool Interp,
00187       short *Xp,
00188       short Ph,
00189       short Inc);
00190 
00191    int
00192    FilterUD(
00193       short Imp[],
00194       short ImpD[],
00195       unsigned short Nwing,
00196       bool Interp,
00197       short *Xp,
00198       short Ph,
00199       short Inc,
00200       unsigned short dhb);
00201 
00202    int
00203    resampleFast(  /* number of output samples returned */
00204       int& inCount,     /* number of input samples to convert */
00205       int outCount,    /* number of output samples to compute */
00206       short inArray[], /* input array data (length inCount * nChans) */
00207       short outArray[]);/* output array data (length outCount * nChans) */
00208  
00209    int
00210    resampleWithFilter(  /* number of output samples returned */
00211       int& inCount,      /* number of input samples to convert */
00212       int outCount,     /* number of output samples to compute */
00213       short inArray[],  /* input array data (length inCount * nChans) */
00214       short outArray[], /* output array data (length outCount * nChans) */
00215       short Imp[], short ImpD[],
00216       unsigned short LpScl, unsigned short Nmult, unsigned short Nwing);
00217 
00218 
00219 static short SMALL_FILTER_IMP[];
00220 static short LARGE_FILTER_IMP[];
00221 
00222 bool    interpFilt;
00223 bool    largeFilter;
00224 bool    linearInterp;
00225 short  ** _X;
00226 short  ** _Y;
00227 unsigned int _Time;
00228 double  _factor;
00229 int     _nChans;
00230 bool    _initial;
00231 double  _vol;
00232 
00233 };
00234 
00235 
00236 #endif

Generated on Wed May 8 20:51:05 2002 for Open Source Audio Library Project by doxygen1.2.15