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 #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 #define IBUFFSIZE 4096                         /* Input buffer size */
00040 
00072 class aflibConverter {
00073 
00074 public:
00075 
00076    // Available contructors and destructors
00077    aflibConverter (
00078       bool  high_quality,
00079       bool  linear_interpolation,
00080       bool  filter_interpolation);
00081 
00082    ~aflibConverter();
00083 
00084    void
00085    initialize(
00086       double factor,   /* factor = Sndout/Sndin */
00087       int    channels, /* number of sound channels */
00088       double volume = 1.0); /* factor to multiply amplitude */
00089 
00090    int
00091    resample(           /* number of output samples returned */
00092       int& inCount,    /* number of input samples to convert */
00093       int outCount,    /* number of output samples to compute */
00094       short inArray[], /* input array data (length inCount * nChans) */
00095       short outArray[]);/* output array data (length outCount * nChans) */
00096  
00097  
00098 private:
00099 
00100    aflibConverter();
00101 
00102    aflibConverter(const aflibConverter& op);
00103 
00104    const aflibConverter&
00105    operator=(const aflibConverter& op);
00106 
00107    int
00108    err_ret(char *s);
00109 
00110    void
00111    deleteMemory();
00112 
00113    int
00114    readData(
00115       int   inCount,       /* _total_ number of frames in input file */
00116       short inArray[],     /* input data */
00117       short *outPtr[],     /* array receiving chan samps */
00118       int   dataArraySize, /* size of these arrays */
00119       int   Xoff,          /* read into input array starting at this index */
00120       bool  init_count);
00121 
00122 
00123    inline short
00124    WordToHword(int v, int scl)
00125    {
00126        short out;
00127        int llsb = (1<<(scl-1));
00128        v += llsb;          /* round */
00129        v >>= scl;
00130        if (v>MAX_HWORD) {
00131 #ifdef DEBUG
00132            if (pof == 0)
00133              fprintf(stderr, "*** resample: sound sample overflow\n");
00134            else if ((pof % 10000) == 0)
00135              fprintf(stderr, "*** resample: another ten thousand overflows\n");
00136            pof++;
00137 #endif
00138            v = MAX_HWORD;
00139        } else if (v < MIN_HWORD) {
00140 #ifdef DEBUG
00141            if (nof == 0)
00142              fprintf(stderr, "*** resample: sound sample (-) overflow\n");
00143            else if ((nof % 1000) == 0)
00144              fprintf(stderr, "*** resample: another thousand (-) overflows\n");
00145            nof++;
00146 #endif
00147            v = MIN_HWORD;
00148        }
00149        out = (short) v;
00150        return out;
00151    };
00152 
00153    int
00154    SrcLinear(
00155       short X[],
00156       short Y[],
00157       double factor,
00158       unsigned int *Time,
00159       unsigned short& Nx,
00160       unsigned short Nout);
00161 
00162    int
00163    SrcUp(
00164       short X[],
00165       short Y[],
00166       double factor,
00167       unsigned int *Time,
00168       unsigned short& Nx,
00169       unsigned short Nout,
00170       unsigned short Nwing,
00171       unsigned short LpScl,
00172       short Imp[],
00173       short ImpD[],
00174       bool Interp);
00175 
00176    int
00177    SrcUD(
00178       short X[],
00179       short Y[],
00180       double factor,
00181       unsigned int *Time,
00182       unsigned short& Nx,
00183       unsigned short Nout,
00184       unsigned short Nwing,
00185       unsigned short LpScl,
00186       short Imp[],
00187       short ImpD[],
00188       bool Interp);
00189 
00190    int
00191    FilterUp(
00192       short Imp[],
00193       short ImpD[],
00194       unsigned short Nwing,
00195       bool Interp,
00196       short *Xp,
00197       short Ph,
00198       short Inc);
00199 
00200    int
00201    FilterUD(
00202       short Imp[],
00203       short ImpD[],
00204       unsigned short Nwing,
00205       bool Interp,
00206       short *Xp,
00207       short Ph,
00208       short Inc,
00209       unsigned short dhb);
00210 
00211    int
00212    resampleFast(  /* number of output samples returned */
00213       int& inCount,     /* number of input samples to convert */
00214       int outCount,    /* number of output samples to compute */
00215       short inArray[], /* input array data (length inCount * nChans) */
00216       short outArray[]);/* output array data (length outCount * nChans) */
00217  
00218    int
00219    resampleWithFilter(  /* number of output samples returned */
00220       int& inCount,      /* number of input samples to convert */
00221       int outCount,     /* number of output samples to compute */
00222       short inArray[],  /* input array data (length inCount * nChans) */
00223       short outArray[], /* output array data (length outCount * nChans) */
00224       short Imp[], short ImpD[],
00225       unsigned short LpScl, unsigned short Nmult, unsigned short Nwing);
00226 
00227 
00228 static short SMALL_FILTER_IMP[];
00229 static short LARGE_FILTER_IMP[];
00230 
00231 bool    interpFilt;
00232 bool    largeFilter;
00233 bool    linearInterp;
00234 short  ** X;
00235 short  ** Y;
00236 unsigned int Time;
00237 double  factor;
00238 int     nChans;
00239 bool    initial;
00240 double  vol;
00241 
00242 };
00243 
00244 
00245 #endif

Generated at Tue Aug 7 22:18:05 2001 for Open Source Audio Library Project by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001