Changeset 641 for pjproject/trunk/pjmedia/src/pjmedia/resample.c
 Timestamp:
 Aug 1, 2006 11:09:35 PM (17 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

pjproject/trunk/pjmedia/src/pjmedia/resample.c
r513 r641 99 99 #endif 100 100 101 typedef char BOOL;102 typedef short HWORD;103 typedef unsigned short UHWORD;104 typedef intWORD;105 typedef unsigned int UWORD;101 typedef char RES_BOOL; 102 typedef short RES_HWORD; 103 typedef int RES_WORD; 104 typedef unsigned short RES_UHWORD; 105 typedef unsigned int RES_UWORD; 106 106 107 107 #define MAX_HWORD (32767) … … 222 222 223 223 224 static INLINE HWORD WordToHword(WORD v, int scl)225 { 226 HWORD out;227 WORD llsb = (1<<(scl1));224 static INLINE RES_HWORD WordToHword(RES_WORD v, int scl) 225 { 226 RES_HWORD out; 227 RES_WORD llsb = (1<<(scl1)); 228 228 v += llsb; /* round */ 229 229 v >>= scl; … … 233 233 v = MIN_HWORD; 234 234 } 235 out = ( HWORD) v;235 out = (RES_HWORD) v; 236 236 return out; 237 237 } … … 240 240 */ 241 241 static int 242 SrcLinear(const HWORD X[], HWORD Y[], double pFactor,UHWORD nx)243 { 244 HWORD iconst;245 UWORD time = 0;246 const HWORD *xp;247 HWORD *Ystart, *Yend;248 WORD v,x1,x2;242 SrcLinear(const RES_HWORD X[], RES_HWORD Y[], double pFactor, RES_UHWORD nx) 243 { 244 RES_HWORD iconst; 245 RES_UWORD time = 0; 246 const RES_HWORD *xp; 247 RES_HWORD *Ystart, *Yend; 248 RES_WORD v,x1,x2; 249 249 250 250 double dt; /* Step through input signal */ 251 UWORD dtb; /* Fixedpoint version of Dt */252 UWORD endTime; /* When time reaches EndTime, return to user */251 RES_UWORD dtb; /* Fixedpoint version of Dt */ 252 RES_UWORD endTime; /* When time reaches EndTime, return to user */ 253 253 254 254 dt = 1.0/pFactor; /* Output sampling period */ … … 257 257 Ystart = Y; 258 258 Yend = Ystart + (unsigned)(nx * pFactor); 259 endTime = time + (1<<Np)*( WORD)nx;259 endTime = time + (1<<Np)*(RES_WORD)nx; 260 260 while (time < endTime) 261 261 { … … 273 273 } 274 274 275 static WORD FilterUp(const HWORD Imp[], constHWORD ImpD[],276 UHWORD Nwing,BOOL Interp,277 const HWORD *Xp, HWORD Ph,HWORD Inc)278 { 279 const HWORD *Hp;280 const HWORD *Hdp = NULL;281 const HWORD *End;282 HWORD a = 0;283 WORD v, t;275 static RES_WORD FilterUp(const RES_HWORD Imp[], const RES_HWORD ImpD[], 276 RES_UHWORD Nwing, RES_BOOL Interp, 277 const RES_HWORD *Xp, RES_HWORD Ph, RES_HWORD Inc) 278 { 279 const RES_HWORD *Hp; 280 const RES_HWORD *Hdp = NULL; 281 const RES_HWORD *End; 282 RES_HWORD a = 0; 283 RES_WORD v, t; 284 284 285 285 v=0; … … 302 302 while (Hp < End) { 303 303 t = *Hp; /* Get filter coeff */ 304 t += ((( WORD)*Hdp)*a)>>Na; /* t is now interp'd filter coeff */304 t += (((RES_WORD)*Hdp)*a)>>Na; /* t is now interp'd filter coeff */ 305 305 Hdp += Npc; /* Filter coeff differences step */ 306 306 t *= *Xp; /* Mult coeff by input sample */ … … 328 328 329 329 330 static WORD FilterUD(const HWORD Imp[], constHWORD ImpD[],331 UHWORD Nwing,BOOL Interp,332 const HWORD *Xp, HWORD Ph, HWORD Inc,UHWORD dhb)333 { 334 HWORD a;335 const HWORD *Hp, *Hdp, *End;336 WORD v, t;337 UWORD Ho;330 static RES_WORD FilterUD(const RES_HWORD Imp[], const RES_HWORD ImpD[], 331 RES_UHWORD Nwing, RES_BOOL Interp, 332 const RES_HWORD *Xp, RES_HWORD Ph, RES_HWORD Inc, RES_UHWORD dhb) 333 { 334 RES_HWORD a; 335 const RES_HWORD *Hp, *Hdp, *End; 336 RES_WORD v, t; 337 RES_UWORD Ho; 338 338 339 339 v=0; 340 Ho = (Ph*( UWORD)dhb)>>Np;340 Ho = (Ph*(RES_UWORD)dhb)>>Np; 341 341 End = &Imp[Nwing]; 342 342 if (Inc == 1) /* If doing right wing... */ … … 352 352 Hdp = &ImpD[Ho>>Na]; /* get interp (lower Na) bits from diff table*/ 353 353 a = Ho & Amask; /* a is logically between 0 and 1 */ 354 t += ((( WORD)*Hdp)*a)>>Na; /* t is now interp'd filter coeff */354 t += (((RES_WORD)*Hdp)*a)>>Na; /* t is now interp'd filter coeff */ 355 355 t *= *Xp; /* Mult coeff by input sample */ 356 356 if (t & 1<<(Nhxn1)) /* Round, if needed */ … … 378 378 * Slightly faster than downconversion; 379 379 */ 380 static int SrcUp(const HWORD X[],HWORD Y[], double pFactor,381 UHWORD nx, UHWORD pNwing,UHWORD pLpScl,382 const HWORD pImp[], const HWORD pImpD[],BOOL Interp)383 { 384 const HWORD *xp;385 HWORD *Ystart, *Yend;386 WORD v;380 static int SrcUp(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 381 RES_UHWORD nx, RES_UHWORD pNwing, RES_UHWORD pLpScl, 382 const RES_HWORD pImp[], const RES_HWORD pImpD[], RES_BOOL Interp) 383 { 384 const RES_HWORD *xp; 385 RES_HWORD *Ystart, *Yend; 386 RES_WORD v; 387 387 388 388 double dt; /* Step through input signal */ 389 UWORD dtb; /* Fixedpoint version of Dt */390 UWORD time = 0;391 UWORD endTime; /* When time reaches EndTime, return to user */389 RES_UWORD dtb; /* Fixedpoint version of Dt */ 390 RES_UWORD time = 0; 391 RES_UWORD endTime; /* When time reaches EndTime, return to user */ 392 392 393 393 dt = 1.0/pFactor; /* Output sampling period */ … … 396 396 Ystart = Y; 397 397 Yend = Ystart + (unsigned)(nx * pFactor); 398 endTime = time + (1<<Np)*( WORD)nx;398 endTime = time + (1<<Np)*(RES_WORD)nx; 399 399 while (time < endTime) 400 400 { … … 402 402 /* Perform leftwing inner product */ 403 403 v = 0; 404 v = FilterUp(pImp, pImpD, pNwing, Interp, xp, ( HWORD)(time&Pmask),1);404 v = FilterUp(pImp, pImpD, pNwing, Interp, xp, (RES_HWORD)(time&Pmask),1); 405 405 406 406 /* Perform rightwing inner product */ 407 v += FilterUp(pImp, pImpD, pNwing, Interp, xp+1, ( HWORD)((time)&Pmask),1);407 v += FilterUp(pImp, pImpD, pNwing, Interp, xp+1, (RES_HWORD)((time)&Pmask),1); 408 408 409 409 v >>= Nhg; /* Make guard bits */ … … 418 418 /* Sampling rate conversion subroutine */ 419 419 420 static int SrcUD(const HWORD X[],HWORD Y[], double pFactor,421 UHWORD nx, UHWORD pNwing,UHWORD pLpScl,422 const HWORD pImp[], const HWORD pImpD[],BOOL Interp)423 { 424 const HWORD *xp;425 HWORD *Ystart, *Yend;426 WORD v;420 static int SrcUD(const RES_HWORD X[], RES_HWORD Y[], double pFactor, 421 RES_UHWORD nx, RES_UHWORD pNwing, RES_UHWORD pLpScl, 422 const RES_HWORD pImp[], const RES_HWORD pImpD[], RES_BOOL Interp) 423 { 424 const RES_HWORD *xp; 425 RES_HWORD *Ystart, *Yend; 426 RES_WORD v; 427 427 428 428 double dh; /* Step through filter impulse response */ 429 429 double dt; /* Step through input signal */ 430 UWORD time = 0;431 UWORD endTime;/* When time reaches EndTime, return to user */432 UWORD dhb, dtb;/* Fixedpoint versions of Dh,Dt */430 RES_UWORD time = 0; 431 RES_UWORD endTime; /* When time reaches EndTime, return to user */ 432 RES_UWORD dhb, dtb; /* Fixedpoint versions of Dh,Dt */ 433 433 434 434 dt = 1.0/pFactor; /* Output sampling period */ … … 440 440 Ystart = Y; 441 441 Yend = Ystart + (unsigned)(nx * pFactor); 442 endTime = time + (1<<Np)*( WORD)nx;442 endTime = time + (1<<Np)*(RES_WORD)nx; 443 443 while (time < endTime) 444 444 { 445 445 xp = &X[time>>Np]; /* Ptr to current input sample */ 446 v = FilterUD(pImp, pImpD, pNwing, Interp, xp, ( HWORD)(time&Pmask),446 v = FilterUD(pImp, pImpD, pNwing, Interp, xp, (RES_HWORD)(time&Pmask), 447 447 1, dhb); /* Perform leftwing inner product */ 448 v += FilterUD(pImp, pImpD, pNwing, Interp, xp+1, ( HWORD)((time)&Pmask),448 v += FilterUD(pImp, pImpD, pNwing, Interp, xp+1, (RES_HWORD)((time)&Pmask), 449 449 1, dhb); /* Perform rightwing inner product */ 450 450 v >>= Nhg; /* Make guard bits */
Note: See TracChangeset
for help on using the changeset viewer.