added haiku-mixer-cvs

added float to 20bits convert method
fix the 24 bits one
clean up Resampler.h


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16478 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2006-02-20 16:28:56 +00:00
parent 16c5a6248e
commit ebc67dde4a
3 changed files with 85 additions and 13 deletions

View File

@ -17,3 +17,8 @@ Addon mixer.media_addon : media :
: false
: be media
;
Package haiku-mixer-cvs
: mixer.media_addon
: boot home config add-ons media ;

View File

@ -46,8 +46,8 @@ Resampler::Resampler(uint32 src_format, uint32 dst_format, int16 dst_valid_bits)
fFunc = &Resampler::float_to_int32_32;
if (dst_valid_bits == 24)
fFunc = &Resampler::float_to_int32_24;
//if (dst_valid_bits == 20)
// fFunc = &Resampler::float_to_int32_20;
else if (dst_valid_bits == 20)
fFunc = &Resampler::float_to_int32_20;
return;
case media_raw_audio_format::B_AUDIO_SHORT:
fFunc = &Resampler::float_to_int16;
@ -387,7 +387,7 @@ Resampler::float_to_int32_24(const void *_src, int32 src_sample_offset, int32 sr
register float sample = *(const float *)src * gain;
if (sample > 8388607.0f)
*(int32 *)dst = 8388607L;
else if (sample < -2147483647.0f)
else if (sample < -8388607.0f)
*(int32 *)dst = -8388607L;
else
*(int32 *)dst = (int32)sample;
@ -437,6 +437,71 @@ Resampler::float_to_int32_24(const void *_src, int32 src_sample_offset, int32 sr
}
void
Resampler::float_to_int32_20(const void *_src, int32 src_sample_offset, int32 src_sample_count,
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)
{
register const char * src = (const char *) _src;
register char * dst = (char *) _dst;
register int32 count = dst_sample_count;
register float gain = _gain * 524287.0;
if (src_sample_count == dst_sample_count) {
// optimized case for no resampling
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 524287.0f)
*(int32 *)dst = 524287L;
else if (sample < -524287.0f)
*(int32 *)dst = -524287L;
else
*(int32 *)dst = (int32)sample;
src += src_sample_offset;
dst += dst_sample_offset;
}
return;
}
register float delta = float(src_sample_count) / float(dst_sample_count);
register float current = 0.0f;
if (delta < 1.0) {
// upsample
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 524287.0f)
*(int32 *)dst = 524287L;
else if (sample < -524287.0f)
*(int32 *)dst = -524287L;
else
*(int32 *)dst = (int32)sample;
dst += dst_sample_offset;
current += delta;
if (current >= 1.0f) {
current -= 1.0f;
src += src_sample_offset;
}
}
} else {
// downsample
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 524287.0f)
*(int32 *)dst = 524287L;
else if (sample < -524287.0f)
*(int32 *)dst = -524287L;
else
*(int32 *)dst = (int32)sample;
dst += dst_sample_offset;
current += delta;
register int32 skipcount = (int32)current;
current -= skipcount;
src += skipcount * src_sample_offset;
}
}
}
void
Resampler::float_to_int16(const void *_src, int32 src_sample_offset, int32 src_sample_count,
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)

View File

@ -24,25 +24,27 @@ public:
protected:
virtual void float_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void int32_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void int16_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void int8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void uint8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int32_32 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int32_24 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int32_20 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int16 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int8 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_uint8 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
private:
void (Resampler::*fFunc) (const void *, int32, int32, void *, int32, int32, float);
};