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:
parent
16c5a6248e
commit
ebc67dde4a
@ -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 ;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -37,6 +37,8 @@ protected:
|
||||
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);
|
||||
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);
|
||||
virtual void float_to_int8 (const void *src, int32 src_sample_offset, int32 src_sample_count,
|
||||
|
Loading…
Reference in New Issue
Block a user