mirror of
https://github.com/libretro/scummvm.git
synced 2024-11-27 11:20:40 +00:00
some more tweaks
svn-id: r9424
This commit is contained in:
parent
20ba086511
commit
7ec38f5f02
@ -716,8 +716,7 @@ void ChannelRaw::mix(int16 *data, uint len) {
|
||||
}
|
||||
|
||||
const int volume = _mixer->getVolume();
|
||||
st_size_t tmpLen = len;
|
||||
_converter->flow(*_input, data, &tmpLen, volume);
|
||||
_converter->flow(*_input, data, len, volume);
|
||||
#else
|
||||
byte *s, *end;
|
||||
|
||||
@ -837,8 +836,7 @@ void ChannelStream::mix(int16 *data, uint len) {
|
||||
}
|
||||
|
||||
const int volume = _mixer->getVolume();
|
||||
st_size_t tmpLen = len;
|
||||
_converter->flow(*_input, data, &tmpLen, volume);
|
||||
_converter->flow(*_input, data, len, volume);
|
||||
#else
|
||||
if (_pos == _endOfData) {
|
||||
// Normally, the stream stays around even if all its data is used up.
|
||||
@ -960,8 +958,7 @@ void ChannelMP3::mix(int16 *data, uint len) {
|
||||
}
|
||||
|
||||
const int volume = _mixer->getVolume();
|
||||
st_size_t tmpLen = len;
|
||||
_converter->flow(*_input, data, &tmpLen, volume);
|
||||
_converter->flow(*_input, data, len, volume);
|
||||
#else
|
||||
const int volume = _mixer->getVolume();
|
||||
|
||||
@ -1044,8 +1041,7 @@ void ChannelMP3CDMusic::mix(int16 *data, uint len) {
|
||||
}
|
||||
|
||||
const int volume = _mixer->getMusicVolume();
|
||||
st_size_t tmpLen = len;
|
||||
_converter->flow(*_input, data, &tmpLen, volume);
|
||||
_converter->flow(*_input, data, len, volume);
|
||||
#else
|
||||
mad_timer_t frame_duration;
|
||||
const int volume = _mixer->getMusicVolume();
|
||||
@ -1198,8 +1194,7 @@ void ChannelVorbis::mix(int16 *data, uint len) {
|
||||
}
|
||||
|
||||
const int volume = isMusicChannel() ? _mixer->getMusicVolume() : _mixer->getVolume();
|
||||
st_size_t tmpLen = len;
|
||||
_converter->flow(*_input, data, &tmpLen, volume);
|
||||
_converter->flow(*_input, data, len, volume);
|
||||
#else
|
||||
if (_end_pos > 0 && ov_pcm_tell(_ov_file) >= _end_pos) {
|
||||
destroy();
|
||||
|
@ -66,8 +66,8 @@ protected:
|
||||
|
||||
public:
|
||||
LinearRateConverter(st_rate_t inrate, st_rate_t outrate);
|
||||
int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol);
|
||||
int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) {
|
||||
int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol);
|
||||
int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) {
|
||||
return (ST_SUCCESS);
|
||||
}
|
||||
};
|
||||
@ -108,14 +108,13 @@ LinearRateConverter<stereo, reverseStereo>::LinearRateConverter(st_rate_t inrate
|
||||
* Return number of samples processed.
|
||||
*/
|
||||
template<bool stereo, bool reverseStereo>
|
||||
int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol)
|
||||
int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol)
|
||||
{
|
||||
st_sample_t *ostart, *oend;
|
||||
st_sample_t out;
|
||||
unsigned long tmp;
|
||||
st_sample_t out[2], tmpOut;
|
||||
|
||||
ostart = obuf;
|
||||
oend = obuf + *osamp * 2;
|
||||
oend = obuf + osamp * 2;
|
||||
|
||||
while (obuf < oend) {
|
||||
|
||||
@ -140,25 +139,25 @@ int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st
|
||||
while (ipos > opos + 1) {
|
||||
|
||||
// interpolate
|
||||
out = (st_sample_t) (ilast[reverseStereo ? 1 : 0] + (((icur[reverseStereo ? 1 : 0] - ilast[reverseStereo ? 1 : 0]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS));
|
||||
tmpOut = (st_sample_t)(ilast[0] + (((icur[0] - ilast[0]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS));
|
||||
// adjust volume
|
||||
out = out * vol / 256;
|
||||
|
||||
// output left channel sample
|
||||
clampedAdd(*obuf++, out);
|
||||
out[0] = out[1] = (st_sample_t)((tmpOut * vol) >> 8);
|
||||
|
||||
if (stereo) {
|
||||
// interpolate
|
||||
out = (st_sample_t) (ilast[reverseStereo ? 0 : 1] + (((icur[reverseStereo ? 0 : 1] - ilast[reverseStereo ? 0 : 1]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS));
|
||||
tmpOut = (st_sample_t)(ilast[1] + (((icur[1] - ilast[1]) * opos_frac + (1UL << (FRAC_BITS-1))) >> FRAC_BITS));
|
||||
// adjust volume
|
||||
out = out * vol / 256;
|
||||
out[reverseStereo ? 0 : 1] = (st_sample_t)((tmpOut * vol) >> 8);
|
||||
}
|
||||
|
||||
// output right channel sample
|
||||
clampedAdd(*obuf++, out);
|
||||
// output left channel
|
||||
clampedAdd(*obuf++, out[0]);
|
||||
|
||||
// output right channel
|
||||
clampedAdd(*obuf++, out[1]);
|
||||
|
||||
// Increment output position
|
||||
tmp = opos_frac + opos_inc_frac;
|
||||
unsigned long tmp = opos_frac + opos_inc_frac;
|
||||
opos += opos_inc + (tmp >> FRAC_BITS);
|
||||
opos_frac = tmp & ((1UL << FRAC_BITS) - 1);
|
||||
|
||||
@ -169,7 +168,6 @@ int LinearRateConverter<stereo, reverseStereo>::flow(AudioInputStream &input, st
|
||||
}
|
||||
|
||||
the_end:
|
||||
*osamp = (obuf - ostart) / 2;
|
||||
return (ST_SUCCESS);
|
||||
}
|
||||
|
||||
@ -183,20 +181,20 @@ the_end:
|
||||
template<bool stereo, bool reverseStereo>
|
||||
class CopyRateConverter : public RateConverter {
|
||||
public:
|
||||
virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) {
|
||||
virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol) {
|
||||
int16 tmp[2];
|
||||
st_size_t len = *osamp;
|
||||
st_size_t len = osamp;
|
||||
assert(input.isStereo() == stereo);
|
||||
while (!input.eof() && len--) {
|
||||
tmp[0] = tmp[1] = input.read() * vol / 256;
|
||||
tmp[0] = tmp[1] = (input.read() * vol) >> 8;
|
||||
if (stereo)
|
||||
tmp[reverseStereo ? 0 : 1] = input.read() * vol / 256;
|
||||
tmp[reverseStereo ? 0 : 1] = (input.read() * vol) >> 8;
|
||||
clampedAdd(*obuf++, tmp[0]);
|
||||
clampedAdd(*obuf++, tmp[1]);
|
||||
}
|
||||
return (ST_SUCCESS);
|
||||
}
|
||||
virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) {
|
||||
virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) {
|
||||
return (ST_SUCCESS);
|
||||
}
|
||||
};
|
||||
|
20
sound/rate.h
20
sound/rate.h
@ -48,14 +48,14 @@ typedef eff_struct *eff_t;
|
||||
#define ST_SUCCESS (0)
|
||||
|
||||
static inline void clampedAdd(int16& a, int b) {
|
||||
int val = a + b;
|
||||
register int val = a + b;
|
||||
|
||||
if (val > ST_SAMPLE_MAX)
|
||||
a = ST_SAMPLE_MAX;
|
||||
val = ST_SAMPLE_MAX;
|
||||
else if (val < ST_SAMPLE_MIN)
|
||||
a = ST_SAMPLE_MIN;
|
||||
else
|
||||
a = val;
|
||||
val = ST_SAMPLE_MIN;
|
||||
|
||||
a = val;
|
||||
}
|
||||
|
||||
// Q&D hack to get this SOX stuff to work
|
||||
@ -68,19 +68,21 @@ class RateConverter {
|
||||
public:
|
||||
RateConverter() {}
|
||||
virtual ~RateConverter() {}
|
||||
virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) = 0;
|
||||
virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol) = 0;
|
||||
virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol) = 0;
|
||||
virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol) = 0;
|
||||
};
|
||||
|
||||
/*
|
||||
class ResampleRateConverter : public RateConverter {
|
||||
protected:
|
||||
eff_struct effp;
|
||||
public:
|
||||
ResampleRateConverter(st_rate_t inrate, st_rate_t outrate, int quality);
|
||||
~ResampleRateConverter();
|
||||
virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t *osamp, st_volume_t vol);
|
||||
virtual int drain(st_sample_t *obuf, st_size_t *osamp, st_volume_t vol);
|
||||
virtual int flow(AudioInputStream &input, st_sample_t *obuf, st_size_t osamp, st_volume_t vol);
|
||||
virtual int drain(st_sample_t *obuf, st_size_t osamp, st_volume_t vol);
|
||||
};
|
||||
*/
|
||||
|
||||
RateConverter *makeRateConverter(st_rate_t inrate, st_rate_t outrate, bool stereo, bool reverseStereo = false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user