On Wed, Aug 23, 2000 at 10:52:28PM +0200, Stefan Westerfeld wrote: > Hi! > > Here is yet-another-patch for making mpeglib resample correct in those cases > where the samplingrate is something like 32000. The essential part here is > not the float -> double conversion but this section: > I have applied it. Martin > // calculate how many input samples we need, then to satisfy the request > - float wantWavSamples = ((float)samples+byteMultiplikator)*speed; > + // use a larger amount than "really" required, to ensure that samples are > + // available for rounding errors and interpolation > + double wantWavSamples = (double)samples*speed+8.0; > > Adding 8.0 should be a pretty safe choice for covering up both: float -> int > rounding errors here and in the actual conversion, and the fact that you need > more than one sample to do interpolation (currently one more due to linear > interpolation). The byteMultiplikator seems to have nothing to do with the > problem here, so I removed it. > > Full patch is attached. > > Cu... Stefan > -- > -* Stefan Westerfeld, stefan@space.twc.de (PGP!), Hamburg/Germany > KDE Developer, project infos at http://space.twc.de/~stefan/kde *- > Index: decoderBaseObject_impl.cpp > =================================================================== > RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/decoderBaseObject_impl.cpp,v > retrieving revision 1.9 > diff -u -r1.9 decoderBaseObject_impl.cpp > --- decoderBaseObject_impl.cpp 2000/08/17 12:01:52 1.9 > +++ decoderBaseObject_impl.cpp 2000/08/23 20:38:17 > @@ -286,10 +286,12 @@ > > // calculate "how fast" we consume input samples (2.0 means, we need 2 > // input samples to generate one output sample) > - float speed = (float)wav_samplingRate / samplingRateFloat; > + double speed = (double)wav_samplingRate / (double)samplingRateFloat; > > // calculate how many input samples we need, then to satisfy the request > - float wantWavSamples = ((float)samples+byteMultiplikator)*speed; > + // use a larger amount than "really" required, to ensure that samples are > + // available for rounding errors and interpolation > + double wantWavSamples = (double)samples*speed+8.0; > > // convert that into bytes and try to read that many bytes > wantBytes=(int) (wantWavSamples*byteMultiplikator); > @@ -308,7 +310,7 @@ > //haveSamples=samples; > // calculate where we are now (as floating point position) in our > // inputsample buffer > - flpos += (float)haveSamples * speed; > + flpos += (double)haveSamples * speed; > > // Good - so how many input samples we won't need anymore (for the > // next request)? Skip them. > Index: decoderBaseObject_impl.h > =================================================================== > RCS file: /home/kde/kdemultimedia/mpeglib_artsplug/decoderBaseObject_impl.h,v > retrieving revision 1.4 > diff -u -r1.4 decoderBaseObject_impl.h > --- decoderBaseObject_impl.h 2000/07/18 19:23:47 1.4 > +++ decoderBaseObject_impl.h 2000/08/23 20:38:18 > @@ -49,7 +49,7 @@ > DecoderPlugin* decoderPlugin; > InputStream* inputStream; > ArtsOutputStream* outputStream; > - float flpos; > + double flpos; > float startTime; > int instance; > int lastAudioBufferSize; _______________________________________________ Kde-multimedia mailing list Kde-multimedia@master.kde.org http://master.kde.org/mailman/listinfo/kde-multimedia