2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-08-02 16:31:31 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2003-08-02 16:31:31 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2003-08-02 16:31:31 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-08-02 16:31:31 +00:00
|
|
|
*
|
|
|
|
*/
|
2003-07-24 17:46:38 +00:00
|
|
|
|
|
|
|
/*
|
2003-08-02 16:31:31 +00:00
|
|
|
* The code in this file is based on code with Copyright 1998 Fabrice Bellard
|
|
|
|
* Fabrice original code is part of SoX (http://sox.sourceforge.net).
|
|
|
|
* Max Horn adapted that code to the needs of ScummVM and rewrote it partial,
|
|
|
|
* in the process removing any use of floating point arithmetic. Various other
|
2010-03-12 00:37:25 +00:00
|
|
|
* improvements over the original code were made.
|
2003-07-24 17:46:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/rate.h"
|
|
|
|
#include "audio/mixer.h"
|
2007-06-28 19:35:48 +00:00
|
|
|
#include "common/frac.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/textconsole.h"
|
2005-01-10 22:51:42 +00:00
|
|
|
#include "common/util.h"
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
namespace Audio {
|
|
|
|
|
2003-08-02 16:31:31 +00:00
|
|
|
|
2003-08-04 22:15:16 +00:00
|
|
|
/**
|
|
|
|
* The size of the intermediate input cache. Bigger values may increase
|
|
|
|
* performance, but only until some point (depends largely on cache size,
|
|
|
|
* target processor and various other factors), at which it will decrease
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
#define INTERMEDIATE_BUFFER_SIZE 512
|
|
|
|
|
2013-07-02 21:04:17 +00:00
|
|
|
/**
|
|
|
|
* The default fractional type in frac.h (with 16 fractional bits) limits
|
|
|
|
* the rate conversion code to 65536Hz audio: we need to able to handle
|
|
|
|
* 96kHz audio, so we use fewer fractional bits in this code.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
FRAC_BITS_LOW = 15,
|
|
|
|
FRAC_ONE_LOW = (1L << FRAC_BITS_LOW),
|
|
|
|
FRAC_HALF_LOW = (1L << (FRAC_BITS_LOW-1))
|
|
|
|
};
|
2003-08-02 16:31:31 +00:00
|
|
|
|
2007-06-16 17:09:54 +00:00
|
|
|
/**
|
|
|
|
* Audio rate converter based on simple resampling. Used when no
|
|
|
|
* interpolation is required.
|
|
|
|
*
|
|
|
|
* Limited to sampling frequency <= 65535 Hz.
|
|
|
|
*/
|
|
|
|
template<bool stereo, bool reverseStereo>
|
|
|
|
class SimpleRateConverter : public RateConverter {
|
|
|
|
protected:
|
|
|
|
st_sample_t inBuf[INTERMEDIATE_BUFFER_SIZE];
|
|
|
|
const st_sample_t *inPtr;
|
|
|
|
int inLen;
|
|
|
|
|
|
|
|
/** position of how far output is ahead of input */
|
|
|
|
/** Holds what would have been opos-ipos */
|
|
|
|
long opos;
|
|
|
|
|
|
|
|
/** fractional position increment in the output stream */
|
|
|
|
long opos_inc;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SimpleRateConverter(st_rate_t inrate, st_rate_t outrate);
|
2021-11-13 20:26:42 +00:00
|
|
|
int flow(AudioStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol_l, st_volume_t vol_r) override;
|
|
|
|
int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) override {
|
2007-06-16 23:41:37 +00:00
|
|
|
return ST_SUCCESS;
|
2007-06-16 17:09:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare processing.
|
|
|
|
*/
|
|
|
|
template<bool stereo, bool reverseStereo>
|
|
|
|
SimpleRateConverter<stereo, reverseStereo>::SimpleRateConverter(st_rate_t inrate, st_rate_t outrate) {
|
|
|
|
if ((inrate % outrate) != 0) {
|
2007-06-28 19:35:48 +00:00
|
|
|
error("Input rate must be a multiple of output rate to use rate effect");
|
2007-06-16 17:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inrate >= 65536 || outrate >= 65536) {
|
|
|
|
error("rate effect can only handle rates < 65536");
|
|
|
|
}
|
|
|
|
|
|
|
|
opos = 1;
|
|
|
|
|
|
|
|
/* increment */
|
|
|
|
opos_inc = inrate / outrate;
|
|
|
|
|
|
|
|
inLen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Processed signed long samples from ibuf to obuf.
|
2010-01-05 02:42:35 +00:00
|
|
|
* Return number of sample pairs processed.
|
2007-06-16 17:09:54 +00:00
|
|
|
*/
|
|
|
|
template<bool stereo, bool reverseStereo>
|
|
|
|
int SimpleRateConverter<stereo, reverseStereo>::flow(AudioStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol_l, st_volume_t vol_r) {
|
|
|
|
st_sample_t *ostart, *oend;
|
|
|
|
|
|
|
|
ostart = obuf;
|
|
|
|
oend = obuf + osamp * 2;
|
|
|
|
|
|
|
|
while (obuf < oend) {
|
|
|
|
|
|
|
|
// read enough input samples so that opos >= 0
|
|
|
|
do {
|
|
|
|
// Check if we have to refill the buffer
|
|
|
|
if (inLen == 0) {
|
|
|
|
inPtr = inBuf;
|
|
|
|
inLen = input.readBuffer(inBuf, ARRAYSIZE(inBuf));
|
|
|
|
if (inLen <= 0)
|
2010-01-05 02:42:35 +00:00
|
|
|
return (obuf - ostart) / 2;
|
2007-06-16 17:09:54 +00:00
|
|
|
}
|
|
|
|
inLen -= (stereo ? 2 : 1);
|
|
|
|
opos--;
|
|
|
|
if (opos >= 0) {
|
|
|
|
inPtr += (stereo ? 2 : 1);
|
|
|
|
}
|
|
|
|
} while (opos >= 0);
|
2007-06-16 17:12:08 +00:00
|
|
|
|
2007-06-16 23:07:25 +00:00
|
|
|
st_sample_t out0, out1;
|
|
|
|
out0 = *inPtr++;
|
|
|
|
out1 = (stereo ? *inPtr++ : out0);
|
2007-06-16 17:09:54 +00:00
|
|
|
|
|
|
|
// Increment output position
|
|
|
|
opos += opos_inc;
|
|
|
|
|
|
|
|
// output left channel
|
2007-06-16 23:07:25 +00:00
|
|
|
clampedAdd(obuf[reverseStereo ], (out0 * (int)vol_l) / Audio::Mixer::kMaxMixerVolume);
|
2007-06-16 17:09:54 +00:00
|
|
|
|
|
|
|
// output right channel
|
2007-06-16 23:07:25 +00:00
|
|
|
clampedAdd(obuf[reverseStereo ^ 1], (out1 * (int)vol_r) / Audio::Mixer::kMaxMixerVolume);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-16 23:07:25 +00:00
|
|
|
obuf += 2;
|
2007-06-16 17:09:54 +00:00
|
|
|
}
|
2010-01-05 02:42:35 +00:00
|
|
|
return (obuf - ostart) / 2;
|
2007-06-16 17:09:54 +00:00
|
|
|
}
|
|
|
|
|
2003-08-02 16:31:31 +00:00
|
|
|
/**
|
|
|
|
* Audio rate converter based on simple linear Interpolation.
|
2003-07-24 17:46:38 +00:00
|
|
|
*
|
|
|
|
* The use of fractional increment allows us to use no buffer. It
|
|
|
|
* avoid the problems at the end of the buffer we had with the old
|
|
|
|
* method which stored a possibly big buffer of size
|
|
|
|
* lcm(in_rate,out_rate).
|
|
|
|
*
|
2003-08-02 16:31:31 +00:00
|
|
|
* Limited to sampling frequency <= 65535 Hz.
|
2003-07-24 17:46:38 +00:00
|
|
|
*/
|
2003-08-02 17:22:52 +00:00
|
|
|
|
|
|
|
template<bool stereo, bool reverseStereo>
|
2003-08-02 16:31:31 +00:00
|
|
|
class LinearRateConverter : public RateConverter {
|
|
|
|
protected:
|
2003-08-04 22:15:16 +00:00
|
|
|
st_sample_t inBuf[INTERMEDIATE_BUFFER_SIZE];
|
|
|
|
const st_sample_t *inPtr;
|
|
|
|
int inLen;
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2003-07-31 19:08:57 +00:00
|
|
|
/** fractional position of the output stream in input stream unit */
|
2007-06-28 19:35:48 +00:00
|
|
|
frac_t opos;
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2003-07-31 19:08:57 +00:00
|
|
|
/** fractional position increment in the output stream */
|
2007-06-28 19:35:48 +00:00
|
|
|
frac_t opos_inc;
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2003-07-31 19:08:57 +00:00
|
|
|
/** last sample(s) in the input stream (left/right channel) */
|
2007-06-16 17:12:08 +00:00
|
|
|
st_sample_t ilast0, ilast1;
|
2003-07-31 19:08:57 +00:00
|
|
|
/** current sample(s) in the input stream (left/right channel) */
|
2007-06-16 17:12:08 +00:00
|
|
|
st_sample_t icur0, icur1;
|
2003-08-02 16:31:31 +00:00
|
|
|
|
|
|
|
public:
|
2003-08-02 17:22:52 +00:00
|
|
|
LinearRateConverter(st_rate_t inrate, st_rate_t outrate);
|
2021-11-13 20:26:42 +00:00
|
|
|
int flow(AudioStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol_l, st_volume_t vol_r) override;
|
|
|
|
int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) override {
|
2007-06-16 23:41:37 +00:00
|
|
|
return ST_SUCCESS;
|
2003-08-02 16:31:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-07-24 17:46:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare processing.
|
|
|
|
*/
|
2003-08-02 17:22:52 +00:00
|
|
|
template<bool stereo, bool reverseStereo>
|
|
|
|
LinearRateConverter<stereo, reverseStereo>::LinearRateConverter(st_rate_t inrate, st_rate_t outrate) {
|
2013-07-02 21:04:17 +00:00
|
|
|
if (inrate >= 131072 || outrate >= 131072) {
|
|
|
|
error("rate effect can only handle rates < 131072");
|
2003-07-24 17:46:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 21:04:17 +00:00
|
|
|
opos = FRAC_ONE_LOW;
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2007-06-29 23:33:16 +00:00
|
|
|
// Compute the linear interpolation increment.
|
2013-07-02 21:04:17 +00:00
|
|
|
// This will overflow if inrate >= 2^17, and underflow if outrate >= 2^17.
|
2007-06-29 23:33:16 +00:00
|
|
|
// Also, if the quotient of the two rate becomes too small / too big, that
|
|
|
|
// would cause problems, but since we rarely scale from 1 to 65536 Hz or vice
|
2010-03-12 00:37:25 +00:00
|
|
|
// versa, I think we can live with that limitation ;-).
|
2013-07-02 21:04:17 +00:00
|
|
|
opos_inc = (inrate << FRAC_BITS_LOW) / outrate;
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2007-06-16 17:12:08 +00:00
|
|
|
ilast0 = ilast1 = 0;
|
|
|
|
icur0 = icur1 = 0;
|
2003-11-08 23:05:04 +00:00
|
|
|
|
2003-08-04 22:15:16 +00:00
|
|
|
inLen = 0;
|
2003-07-24 17:46:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Processed signed long samples from ibuf to obuf.
|
2010-01-05 02:42:35 +00:00
|
|
|
* Return number of sample pairs processed.
|
2003-07-24 17:46:38 +00:00
|
|
|
*/
|
2003-08-02 17:22:52 +00:00
|
|
|
template<bool stereo, bool reverseStereo>
|
2004-01-03 14:10:13 +00:00
|
|
|
int LinearRateConverter<stereo, reverseStereo>::flow(AudioStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol_l, st_volume_t vol_r) {
|
2003-07-24 17:46:38 +00:00
|
|
|
st_sample_t *ostart, *oend;
|
2003-11-08 23:05:04 +00:00
|
|
|
|
2003-07-24 17:46:38 +00:00
|
|
|
ostart = obuf;
|
2003-08-02 19:09:52 +00:00
|
|
|
oend = obuf + osamp * 2;
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2003-08-02 18:29:52 +00:00
|
|
|
while (obuf < oend) {
|
2003-07-24 17:46:38 +00:00
|
|
|
|
2007-06-28 19:35:48 +00:00
|
|
|
// read enough input samples so that opos < 0
|
2013-07-02 21:04:17 +00:00
|
|
|
while ((frac_t)FRAC_ONE_LOW <= opos) {
|
2003-08-04 22:15:16 +00:00
|
|
|
// Check if we have to refill the buffer
|
|
|
|
if (inLen == 0) {
|
|
|
|
inPtr = inBuf;
|
|
|
|
inLen = input.readBuffer(inBuf, ARRAYSIZE(inBuf));
|
|
|
|
if (inLen <= 0)
|
2010-01-05 02:42:35 +00:00
|
|
|
return (obuf - ostart) / 2;
|
2003-08-04 22:15:16 +00:00
|
|
|
}
|
2007-06-16 17:09:54 +00:00
|
|
|
inLen -= (stereo ? 2 : 1);
|
2007-06-16 17:12:08 +00:00
|
|
|
ilast0 = icur0;
|
|
|
|
icur0 = *inPtr++;
|
2007-06-16 17:09:54 +00:00
|
|
|
if (stereo) {
|
2007-06-16 17:12:08 +00:00
|
|
|
ilast1 = icur1;
|
|
|
|
icur1 = *inPtr++;
|
2003-08-02 14:48:11 +00:00
|
|
|
}
|
2013-07-02 21:04:17 +00:00
|
|
|
opos -= FRAC_ONE_LOW;
|
2003-07-24 17:46:38 +00:00
|
|
|
}
|
|
|
|
|
2003-07-28 11:13:01 +00:00
|
|
|
// Loop as long as the outpos trails behind, and as long as there is
|
|
|
|
// still space in the output buffer.
|
2013-07-02 21:04:17 +00:00
|
|
|
while (opos < (frac_t)FRAC_ONE_LOW && obuf < oend) {
|
2003-07-28 11:13:01 +00:00
|
|
|
// interpolate
|
2007-06-16 23:07:25 +00:00
|
|
|
st_sample_t out0, out1;
|
2013-07-02 21:04:17 +00:00
|
|
|
out0 = (st_sample_t)(ilast0 + (((icur0 - ilast0) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW));
|
2007-06-16 23:07:25 +00:00
|
|
|
out1 = (stereo ?
|
2013-07-02 21:04:17 +00:00
|
|
|
(st_sample_t)(ilast1 + (((icur1 - ilast1) * opos + FRAC_HALF_LOW) >> FRAC_BITS_LOW)) :
|
2007-06-16 23:07:25 +00:00
|
|
|
out0);
|
2003-09-02 20:34:22 +00:00
|
|
|
|
2003-08-02 19:09:52 +00:00
|
|
|
// output left channel
|
2007-06-16 23:07:25 +00:00
|
|
|
clampedAdd(obuf[reverseStereo ], (out0 * (int)vol_l) / Audio::Mixer::kMaxMixerVolume);
|
2003-09-05 23:27:11 +00:00
|
|
|
|
2003-08-02 19:09:52 +00:00
|
|
|
// output right channel
|
2007-06-16 23:07:25 +00:00
|
|
|
clampedAdd(obuf[reverseStereo ^ 1], (out1 * (int)vol_r) / Audio::Mixer::kMaxMixerVolume);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-16 23:07:25 +00:00
|
|
|
obuf += 2;
|
2003-09-05 23:27:11 +00:00
|
|
|
|
2003-07-28 01:13:31 +00:00
|
|
|
// Increment output position
|
2007-06-28 19:35:48 +00:00
|
|
|
opos += opos_inc;
|
2003-07-28 01:13:31 +00:00
|
|
|
}
|
2003-07-24 17:46:38 +00:00
|
|
|
}
|
2010-01-05 02:42:35 +00:00
|
|
|
return (obuf - ostart) / 2;
|
2003-07-28 01:13:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-02 16:31:31 +00:00
|
|
|
#pragma mark -
|
2003-07-28 01:13:31 +00:00
|
|
|
|
2003-08-02 16:31:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple audio rate converter for the case that the inrate equals the outrate.
|
|
|
|
*/
|
|
|
|
template<bool stereo, bool reverseStereo>
|
|
|
|
class CopyRateConverter : public RateConverter {
|
2004-01-03 02:29:48 +00:00
|
|
|
st_sample_t *_buffer;
|
|
|
|
st_size_t _bufferSize;
|
2003-08-02 16:31:31 +00:00
|
|
|
public:
|
2021-11-13 19:23:55 +00:00
|
|
|
CopyRateConverter() : _buffer(nullptr), _bufferSize(0) {}
|
2004-01-03 02:29:48 +00:00
|
|
|
~CopyRateConverter() {
|
|
|
|
free(_buffer);
|
|
|
|
}
|
|
|
|
|
2021-11-13 20:26:42 +00:00
|
|
|
int flow(AudioStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol_l, st_volume_t vol_r) override {
|
2003-08-02 16:31:31 +00:00
|
|
|
assert(input.isStereo() == stereo);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-01-03 02:29:48 +00:00
|
|
|
st_sample_t *ptr;
|
|
|
|
st_size_t len;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2010-01-05 02:48:38 +00:00
|
|
|
st_sample_t *ostart = obuf;
|
|
|
|
|
2004-01-03 02:29:48 +00:00
|
|
|
if (stereo)
|
|
|
|
osamp *= 2;
|
|
|
|
|
|
|
|
// Reallocate temp buffer, if necessary
|
|
|
|
if (osamp > _bufferSize) {
|
|
|
|
free(_buffer);
|
|
|
|
_buffer = (st_sample_t *)malloc(osamp * 2);
|
|
|
|
_bufferSize = osamp;
|
|
|
|
}
|
|
|
|
|
2011-06-03 22:46:40 +00:00
|
|
|
if (!_buffer)
|
|
|
|
error("[CopyRateConverter::flow] Cannot allocate memory for temp buffer");
|
|
|
|
|
2004-01-03 02:29:48 +00:00
|
|
|
// Read up to 'osamp' samples into our temporary buffer
|
|
|
|
len = input.readBuffer(_buffer, osamp);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-01-03 02:29:48 +00:00
|
|
|
// Mix the data into the output buffer
|
|
|
|
ptr = _buffer;
|
2007-06-16 17:09:54 +00:00
|
|
|
for (; len > 0; len -= (stereo ? 2 : 1)) {
|
2007-06-16 23:07:25 +00:00
|
|
|
st_sample_t out0, out1;
|
|
|
|
out0 = *ptr++;
|
|
|
|
out1 = (stereo ? *ptr++ : out0);
|
2003-09-05 23:27:11 +00:00
|
|
|
|
|
|
|
// output left channel
|
2007-06-16 23:07:25 +00:00
|
|
|
clampedAdd(obuf[reverseStereo ], (out0 * (int)vol_l) / Audio::Mixer::kMaxMixerVolume);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-09-05 23:27:11 +00:00
|
|
|
// output right channel
|
2007-06-16 23:07:25 +00:00
|
|
|
clampedAdd(obuf[reverseStereo ^ 1], (out1 * (int)vol_r) / Audio::Mixer::kMaxMixerVolume);
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-06-16 23:07:25 +00:00
|
|
|
obuf += 2;
|
2003-08-02 16:31:31 +00:00
|
|
|
}
|
2010-01-05 02:48:38 +00:00
|
|
|
return (obuf - ostart) / 2;
|
2003-08-02 16:31:31 +00:00
|
|
|
}
|
2007-06-16 17:09:54 +00:00
|
|
|
|
2021-11-13 20:26:42 +00:00
|
|
|
int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) override {
|
2007-06-16 23:41:37 +00:00
|
|
|
return ST_SUCCESS;
|
2003-08-02 16:31:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2007-06-28 19:35:48 +00:00
|
|
|
template<bool stereo, bool reverseStereo>
|
|
|
|
RateConverter *makeRateConverter(st_rate_t inrate, st_rate_t outrate) {
|
2003-08-02 16:31:31 +00:00
|
|
|
if (inrate != outrate) {
|
2013-07-02 21:04:17 +00:00
|
|
|
if ((inrate % outrate) == 0 && (inrate < 65536)) {
|
2007-06-28 19:35:48 +00:00
|
|
|
return new SimpleRateConverter<stereo, reverseStereo>(inrate, outrate);
|
2007-06-16 17:09:54 +00:00
|
|
|
} else {
|
2007-06-28 19:35:48 +00:00
|
|
|
return new LinearRateConverter<stereo, reverseStereo>(inrate, outrate);
|
|
|
|
}
|
2003-08-02 16:31:31 +00:00
|
|
|
} else {
|
2007-06-28 19:35:48 +00:00
|
|
|
return new CopyRateConverter<stereo, reverseStereo>();
|
2003-08-02 16:31:31 +00:00
|
|
|
}
|
2003-07-24 17:46:38 +00:00
|
|
|
}
|
2005-05-11 00:01:44 +00:00
|
|
|
|
2007-06-28 19:35:48 +00:00
|
|
|
/**
|
|
|
|
* Create and return a RateConverter object for the specified input and output rates.
|
|
|
|
*/
|
|
|
|
RateConverter *makeRateConverter(st_rate_t inrate, st_rate_t outrate, bool stereo, bool reverseStereo) {
|
|
|
|
if (stereo) {
|
|
|
|
if (reverseStereo)
|
|
|
|
return makeRateConverter<true, true>(inrate, outrate);
|
|
|
|
else
|
|
|
|
return makeRateConverter<true, false>(inrate, outrate);
|
|
|
|
} else
|
|
|
|
return makeRateConverter<false, false>(inrate, outrate);
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
} // End of namespace Audio
|