[Plib-cvs] plib/src/sl slSample.cxx,1.9,1.10
Brought to you by:
sjbaker
From: M?rten Str?m. <str...@us...> - 2004-02-08 18:44:21
|
Update of /cvsroot/plib/plib/src/sl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12659 Modified Files: slSample.cxx Log Message: Fixed bug in slSample::changeRate. Index: slSample.cxx =================================================================== RCS file: /cvsroot/plib/plib/src/sl/slSample.cxx,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- slSample.cxx 2 Sep 2002 06:05:47 -0000 1.9 +++ slSample.cxx 8 Feb 2004 18:41:15 -0000 1.10 @@ -50,13 +50,15 @@ { if ( r == rate ) return ; - int length1 = length / (getBps ()/8) ; - int length2 = (int) ( (float) length1 * ( (float) r / (float) rate ) ) ; + int length2 = (int) ( (float) length * ( (float) r / (float) rate ) ) ; Uchar *buffer2 = new Uchar [ length2 ] ; - float step = (float) length1 / (float) length2 ; + int samps = length / (getBps() / 8) ; + int samps2 = length2 / (getBps() / 8) ; - for ( int i = 0 ; i < length2 / (getBps()/8); i++ ) + float step = (float) length / (float) length2 ; + + for ( int i = 0 ; i < samps2 ; i++ ) { float pos = (float) i * step ; @@ -72,11 +74,11 @@ float ratio = pos - (float) p1 ; float b1 = (getBps()==8) ? - (float) buffer [(p1<0)?0:(p1>=length1)?length1-1:p1] : - (float) ((Ushort*)buffer)[(p1<0)?0:(p1>=length1)?length1-1:p1] ; + (float) buffer [(p1<0)?0:(p1>=samps)?samps-1:p1] : + (float) ((Ushort*)buffer)[(p1<0)?0:(p1>=samps)?samps-1:p1] ; float b2 = (getBps()==8) ? - (float) buffer [(p2<0)?0:(p2>=length1)?length1-1:p2] : - (float) ((Ushort*)buffer)[(p2<0)?0:(p2>=length1)?length1-1:p2] ; + (float) buffer [(p2<0)?0:(p2>=samps)?samps-1:p2] : + (float) ((Ushort*)buffer)[(p2<0)?0:(p2>=samps)?samps-1:p2] ; float res = b1 * (1.0f-ratio) + b2 * ratio ; |