most likely fixed downsampling bugs
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3720 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -101,7 +101,7 @@ Resampler::float_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(float *)dst = *(const float *)src * gain;
|
*(float *)dst = *(const float *)src * gain;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -110,16 +110,11 @@ Resampler::float_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
// downsample
|
// downsample
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*(float *)dst = *(const float *)src * gain;
|
*(float *)dst = *(const float *)src * gain;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,7 +147,7 @@ Resampler::int32_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(float *)dst = *(const int32 *)src * gain;
|
*(float *)dst = *(const int32 *)src * gain;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -161,16 +156,11 @@ Resampler::int32_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
// downsample
|
// downsample
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*(float *)dst = *(const int32 *)src * gain;
|
*(float *)dst = *(const int32 *)src * gain;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,7 +193,7 @@ Resampler::int16_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(float *)dst = *(const int16 *)src * gain;
|
*(float *)dst = *(const int16 *)src * gain;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -212,16 +202,11 @@ Resampler::int16_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
// downsample
|
// downsample
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*(float *)dst = *(const int16 *)src * gain;
|
*(float *)dst = *(const int16 *)src * gain;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +239,7 @@ Resampler::int8_to_float(const void *_src, int32 src_sample_offset, int32 src_sa
|
|||||||
*(float *)dst = *(const int8 *)src * gain;
|
*(float *)dst = *(const int8 *)src * gain;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -263,16 +248,11 @@ Resampler::int8_to_float(const void *_src, int32 src_sample_offset, int32 src_sa
|
|||||||
// downsample
|
// downsample
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*(float *)dst = *(const int8 *)src * gain;
|
*(float *)dst = *(const int8 *)src * gain;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,7 +285,7 @@ Resampler::uint8_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(float *)dst = (((int32) *(const uint8 *)src) - 128) * gain;
|
*(float *)dst = (((int32) *(const uint8 *)src) - 128) * gain;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -314,16 +294,11 @@ Resampler::uint8_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
// downsample
|
// downsample
|
||||||
while (count--) {
|
while (count--) {
|
||||||
*(float *)dst = (((int32) *(const uint8 *)src) - 128) * gain;
|
*(float *)dst = (((int32) *(const uint8 *)src) - 128) * gain;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +343,7 @@ Resampler::float_to_int32(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(int32 *)dst = (int32)sample;
|
*(int32 *)dst = (int32)sample;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -383,16 +358,11 @@ Resampler::float_to_int32(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(int32 *)dst = -2147483647L;
|
*(int32 *)dst = -2147483647L;
|
||||||
else
|
else
|
||||||
*(int32 *)dst = (int32)sample;
|
*(int32 *)dst = (int32)sample;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -437,7 +407,7 @@ Resampler::float_to_int16(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(int16 *)dst = (int16)sample;
|
*(int16 *)dst = (int16)sample;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -452,16 +422,11 @@ Resampler::float_to_int16(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(int16 *)dst = -32767;
|
*(int16 *)dst = -32767;
|
||||||
else
|
else
|
||||||
*(int16 *)dst = (int16)sample;
|
*(int16 *)dst = (int16)sample;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -506,7 +471,7 @@ Resampler::float_to_int8(const void *_src, int32 src_sample_offset, int32 src_sa
|
|||||||
*(int8 *)dst = (int8)sample;
|
*(int8 *)dst = (int8)sample;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -521,16 +486,11 @@ Resampler::float_to_int8(const void *_src, int32 src_sample_offset, int32 src_sa
|
|||||||
*(int8 *)dst = -127;
|
*(int8 *)dst = -127;
|
||||||
else
|
else
|
||||||
*(int8 *)dst = (int8)sample;
|
*(int8 *)dst = (int8)sample;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -575,7 +535,7 @@ Resampler::float_to_uint8(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(uint8 *)dst = (uint8)sample;
|
*(uint8 *)dst = (uint8)sample;
|
||||||
dst += dst_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta;
|
current += delta;
|
||||||
if (current > 1.0f) {
|
if (current >= 1.0f) {
|
||||||
current -= 1.0f;
|
current -= 1.0f;
|
||||||
src += src_sample_offset;
|
src += src_sample_offset;
|
||||||
}
|
}
|
||||||
@@ -590,18 +550,11 @@ Resampler::float_to_uint8(const void *_src, int32 src_sample_offset, int32 src_s
|
|||||||
*(uint8 *)dst = 1;
|
*(uint8 *)dst = 1;
|
||||||
else
|
else
|
||||||
*(uint8 *)dst = (uint8)sample;
|
*(uint8 *)dst = (uint8)sample;
|
||||||
src += src_sample_offset;
|
dst += dst_sample_offset;
|
||||||
current += delta; // delta is always > 1.0
|
current += delta;
|
||||||
if (current < 2.0f) {
|
register int32 skipcount = (int32)current;
|
||||||
current -= 1.0f;
|
current -= skipcount;
|
||||||
dst += dst_sample_offset;
|
src += skipcount * src_sample_offset;
|
||||||
} else {
|
|
||||||
int32 inc_count = (int32) current;
|
|
||||||
current -= (float) inc_count;
|
|
||||||
dst += inc_count * dst_sample_offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#ifndef _RESAMPLER_H
|
#ifndef _RESAMPLER_H
|
||||||
#define _RESAMPLER_H
|
#define _RESAMPLER_H
|
||||||
|
#include <stdio.h>
|
||||||
/* Copyright (C) 2003 Marcus Overhagen
|
/* Copyright (C) 2003 Marcus Overhagen
|
||||||
* Released under terms of the MIT license.
|
* Released under terms of the MIT license.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user