Changeset 4728 for pjproject/trunk/third_party/resample/src/resamplesubs.c
- Timestamp:
- Feb 4, 2014 10:13:56 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/third_party/resample/src/resamplesubs.c
r3085 r4728 7 7 * 8 8 * Snippet from the resample.1 man page: 9 * 9 * 10 10 * HISTORY 11 11 * … … 14 14 * 1981. It was called SRCONV and was written in SAIL for PDP-10 15 15 * compatible machines. The algorithm was first published in 16 * 16 * 17 17 * Smith, Julius O. and Phil Gossett. ``A Flexible Sampling-Rate 18 18 * Conversion Method,'' Proceedings (2): 19.4.1-19.4.4, IEEE Conference 19 19 * on Acoustics, Speech, and Signal Processing, San Diego, March 1984. 20 * 20 * 21 21 * An expanded tutorial based on this paper is available at the Digital 22 22 * Audio Resampling Home Page given above. 23 * 23 * 24 24 * Circa 1988, the SRCONV program was translated from SAIL to C by 25 25 * Christopher Lee Fraley working with Roger Dannenberg at CMU. 26 * 26 * 27 27 * Since then, the C version has been maintained by jos. 28 * 28 * 29 29 * Sndlib support was added 6/99 by John Gibson <jgg9c@virginia.edu>. 30 * 30 * 31 31 * The resample program is free software distributed in accordance 32 32 * with the Lesser GNU Public License (LGPL). There is NO warranty; not … … 78 78 #undef INLINE 79 79 #define INLINE 80 #define HAVE_FILTER 0 80 #define HAVE_FILTER 0 81 81 82 82 #ifndef NULL … … 95 95 } else if (v < MIN_HWORD) { 96 96 v = MIN_HWORD; 97 } 97 } 98 98 out = (RES_HWORD) v; 99 99 return out; … … 102 102 /* Sampling rate conversion using linear interpolation for maximum speed. 103 103 */ 104 static int 104 static int 105 105 SrcLinear(const RES_HWORD X[], RES_HWORD Y[], double pFactor, RES_UHWORD nx) 106 106 { … … 110 110 RES_HWORD *Ystart, *Yend; 111 111 RES_WORD v,x1,x2; 112 113 double dt; /* Step through input signal */ 112 113 double dt; /* Step through input signal */ 114 114 RES_UWORD dtb; /* Fixed-point version of Dt */ 115 RES_UWORD endTime; /* When time reaches EndTime, return to user */116 115 //RES_UWORD endTime; /* When time reaches EndTime, return to user */ 116 117 117 dt = 1.0/pFactor; /* Output sampling period */ 118 118 dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ 119 119 120 120 Ystart = Y; 121 121 Yend = Ystart + (unsigned)(nx * pFactor + 0.5); 122 endTime = time + (1<<Np)*(RES_WORD)nx;123 124 // Integer round down in dtb calculation may cause (endTime % dtb > 0), 122 //endTime = time + (1<<Np)*(RES_WORD)nx; 123 124 // Integer round down in dtb calculation may cause (endTime % dtb > 0), 125 125 // so it may cause resample write pass the output buffer (Y >= Yend). 126 126 // while (time < endTime) … … 140 140 } 141 141 142 static RES_WORD FilterUp(const RES_HWORD Imp[], const RES_HWORD ImpD[], 142 static RES_WORD FilterUp(const RES_HWORD Imp[], const RES_HWORD ImpD[], 143 143 RES_UHWORD Nwing, RES_BOOL Interp, 144 144 const RES_HWORD *Xp, RES_HWORD Ph, RES_HWORD Inc) … … 149 149 RES_HWORD a = 0; 150 150 RES_WORD v, t; 151 151 152 152 v=0; 153 153 Hp = &Imp[Ph>>Na]; … … 179 179 180 180 Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */ 181 } 182 else 181 } 182 else 183 183 while (Hp < End) { 184 184 t = *Hp; /* Get filter coeff */ … … 203 203 RES_WORD v, t; 204 204 RES_UWORD Ho; 205 205 206 206 v=0; 207 207 Ho = (Ph*(RES_UWORD)dhb)>>Np; … … 228 228 Xp += Inc; /* Input signal step. NO CHECK ON BOUNDS */ 229 229 } 230 else 230 else 231 231 while ((Hp = &Imp[Ho>>Na]) < End) { 232 232 t = *Hp; /* Get IR sample */ … … 245 245 * Slightly faster than down-conversion; 246 246 */ 247 static int SrcUp(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 247 static int SrcUp(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 248 248 RES_UHWORD nx, RES_UHWORD pNwing, RES_UHWORD pLpScl, 249 249 const RES_HWORD pImp[], const RES_HWORD pImpD[], RES_BOOL Interp) … … 252 252 RES_HWORD *Ystart, *Yend; 253 253 RES_WORD v; 254 255 double dt; /* Step through input signal */ 254 255 double dt; /* Step through input signal */ 256 256 RES_UWORD dtb; /* Fixed-point version of Dt */ 257 257 RES_UWORD time = 0; 258 RES_UWORD endTime; /* When time reaches EndTime, return to user */259 258 //RES_UWORD endTime; /* When time reaches EndTime, return to user */ 259 260 260 dt = 1.0/pFactor; /* Output sampling period */ 261 261 dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ 262 262 263 263 Ystart = Y; 264 264 Yend = Ystart + (unsigned)(nx * pFactor + 0.5); 265 endTime = time + (1<<Np)*(RES_WORD)nx;266 267 // Integer round down in dtb calculation may cause (endTime % dtb > 0), 265 //endTime = time + (1<<Np)*(RES_WORD)nx; 266 267 // Integer round down in dtb calculation may cause (endTime % dtb > 0), 268 268 // so it may cause resample write pass the output buffer (Y >= Yend). 269 269 // while (time < endTime) … … 289 289 /* Sampling rate conversion subroutine */ 290 290 291 static int SrcUD(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 291 static int SrcUD(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 292 292 RES_UHWORD nx, RES_UHWORD pNwing, RES_UHWORD pLpScl, 293 293 const RES_HWORD pImp[], const RES_HWORD pImpD[], RES_BOOL Interp) … … 296 296 RES_HWORD *Ystart, *Yend; 297 297 RES_WORD v; 298 298 299 299 double dh; /* Step through filter impulse response */ 300 300 double dt; /* Step through input signal */ 301 301 RES_UWORD time = 0; 302 RES_UWORD endTime; /* When time reaches EndTime, return to user */302 //RES_UWORD endTime; /* When time reaches EndTime, return to user */ 303 303 RES_UWORD dhb, dtb; /* Fixed-point versions of Dh,Dt */ 304 304 305 305 dt = 1.0/pFactor; /* Output sampling period */ 306 306 dtb = dt*(1<<Np) + 0.5; /* Fixed-point representation */ 307 307 308 308 dh = MIN(Npc, pFactor*Npc); /* Filter sampling period */ 309 309 dhb = dh*(1<<Na) + 0.5; /* Fixed-point representation */ 310 310 311 311 Ystart = Y; 312 312 Yend = Ystart + (unsigned)(nx * pFactor + 0.5); 313 endTime = time + (1<<Np)*(RES_WORD)nx;314 315 // Integer round down in dtb calculation may cause (endTime % dtb > 0), 313 //endTime = time + (1<<Np)*(RES_WORD)nx; 314 315 // Integer round down in dtb calculation may cause (endTime % dtb > 0), 316 316 // so it may cause resample write pass the output buffer (Y >= Yend). 317 317 // while (time < endTime) … … 332 332 333 333 334 DECL(int) res_SrcLinear(const RES_HWORD X[], RES_HWORD Y[], 334 DECL(int) res_SrcLinear(const RES_HWORD X[], RES_HWORD Y[], 335 335 double pFactor, RES_UHWORD nx) 336 336 { … … 338 338 } 339 339 340 DECL(int) res_Resample(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 340 DECL(int) res_Resample(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 341 341 RES_UHWORD nx, RES_BOOL LargeF, RES_BOOL Interp) 342 342 { … … 355 355 356 356 if (LargeF) 357 return SrcUD(X, Y, pFactor, nx, 357 return SrcUD(X, Y, pFactor, nx, 358 358 LARGE_FILTER_NWING, LARGE_FILTER_SCALE * pFactor + 0.5, 359 359 LARGE_FILTER_IMP, LARGE_FILTER_IMPD, Interp); 360 360 else 361 return SrcUD(X, Y, pFactor, nx, 361 return SrcUD(X, Y, pFactor, nx, 362 362 SMALL_FILTER_NWING, SMALL_FILTER_SCALE * pFactor + 0.5, 363 363 SMALL_FILTER_IMP, SMALL_FILTER_IMPD, Interp); … … 369 369 { 370 370 if (LargeF) 371 return (LARGE_FILTER_NMULT + 1) / 2.0 * 371 return (LARGE_FILTER_NMULT + 1) / 2.0 * 372 372 MAX(1.0, 1.0/pFactor); 373 373 else 374 return (SMALL_FILTER_NMULT + 1) / 2.0 * 374 return (SMALL_FILTER_NMULT + 1) / 2.0 * 375 375 MAX(1.0, 1.0/pFactor); 376 376 }
Note: See TracChangeset
for help on using the changeset viewer.