00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00040
00072 class aflibConverter {
00073
00074 public:
00075
00076
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,
00087 int channels,
00088 double volume = 1.0);
00089
00090 int
00091 resample(
00092 int& inCount,
00093 int outCount,
00094 short inArray[],
00095 short outArray[]);
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,
00116 short inArray[],
00117 short *outPtr[],
00118 int dataArraySize,
00119 int Xoff,
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;
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(
00213 int& inCount,
00214 int outCount,
00215 short inArray[],
00216 short outArray[]);
00217
00218 int
00219 resampleWithFilter(
00220 int& inCount,
00221 int outCount,
00222 short inArray[],
00223 short outArray[],
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