From 81baae7ddc2b16031af2526455993c06a2f24d25 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 28 Jul 2003 01:50:46 +0000 Subject: [PATCH] added CopyRateConverter (used if inrate == outrate) svn-id: r9214 --- sound/rate.cpp | 4 ++-- sound/rate.h | 20 ++++++++++++++++++++ sound/resample.cpp | 8 -------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/sound/rate.cpp b/sound/rate.cpp index 5d6faaeee34..f62d20e5366 100644 --- a/sound/rate.cpp +++ b/sound/rate.cpp @@ -107,7 +107,7 @@ int st_rate_flow(eff_t effp, AudioInputStream &input, st_sample_t *obuf, st_size ilast[i] = rate->ilast[i]; ostart = obuf; - oend = obuf + *osamp; + oend = obuf + *osamp * 2; while (obuf < oend && !input.eof()) { @@ -159,7 +159,7 @@ int st_rate_flow(eff_t effp, AudioInputStream &input, st_sample_t *obuf, st_size } the_end: - *osamp = obuf - ostart; + *osamp = (obuf - ostart) / 2; for (i = 0; i < channels; i++) rate->ilast[i] = ilast[i]; return (ST_SUCCESS); diff --git a/sound/rate.h b/sound/rate.h index 080107c831d..809042a8b2b 100644 --- a/sound/rate.h +++ b/sound/rate.h @@ -81,4 +81,24 @@ public: virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol); }; +class CopyRateConverter : public RateConverter { +public: + virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) { + int16 tmp; + st_size_t len = *osamp; + while (!input.eof() && len--) { + tmp = input.read() * vol / 256; + clampedAdd(*obuf++, tmp); + if (input.isStereo()) + tmp = input.read() * vol / 256; + clampedAdd(*obuf++, tmp); + } + return (ST_SUCCESS); + } + virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) { + return (ST_SUCCESS); + } +}; + + #endif diff --git a/sound/resample.cpp b/sound/resample.cpp index a621d892139..b2758f4517c 100644 --- a/sound/resample.cpp +++ b/sound/resample.cpp @@ -268,11 +268,7 @@ int st_resample_flow(eff_t effp, AudioInputStream &input, st_sample_t *obuf, st_ long Nout = 0; // The number of bytes we effectively output long Nx; // The number of bytes we will read from input long Nproc; // The number of bytes we process to generate Nout output bytes -#if 1 // FIXME: Hack to generate stereo output - const long obufSize = *osamp / 2; -#else const long obufSize = *osamp; -#endif TODO: adjust for the changes made to AudioInputStream; add support for stereo initially, could just average the left/right channel -> bad for quality of course, @@ -394,11 +390,7 @@ printf("osamp = %ld, Nout = %ld\n", obufSize, Nout); r->Yposition = 0; // Finally set *osamp to the number of samples we put into the output buffer -#if 1 // FIXME: Hack to generate stereo output - *osamp = numOutSamples * 2; -#else *osamp = numOutSamples; -#endif return (ST_SUCCESS); }