Cleanups in expand()

This commit is contained in:
Jaroslav Kysela 2002-03-11 18:56:34 +00:00
parent ff5535a285
commit 76712fb46b

View file

@ -42,7 +42,7 @@ const char *_snd_module_pcm_rate = "";
typedef struct { typedef struct {
int init; int init;
int16_t sample; int16_t old_sample, new_sample;
int sum; int sum;
unsigned int pos; unsigned int pos;
} snd_pcm_rate_state_t; } snd_pcm_rate_state_t;
@ -117,7 +117,8 @@ static snd_pcm_uframes_t snd_pcm_rate_expand(const snd_pcm_channel_area_t *dst_a
const char *src; const char *src;
char *dst; char *dst;
int src_step, dst_step; int src_step, dst_step;
int16_t old_sample = states->sample; int16_t old_sample = states->old_sample;
int16_t new_sample = states->new_sample;
unsigned int pos = states->pos; unsigned int pos = states->pos;
src = snd_pcm_channel_area_addr(src_area, src_offset); src = snd_pcm_channel_area_addr(src_area, src_offset);
dst = snd_pcm_channel_area_addr(dst_area, dst_offset); dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
@ -126,27 +127,36 @@ static snd_pcm_uframes_t snd_pcm_rate_expand(const snd_pcm_channel_area_t *dst_a
src_frames1 = 0; src_frames1 = 0;
dst_frames1 = 0; dst_frames1 = 0;
if (states->init) { if (states->init) {
old_sample = initial_sample(src, getidx); new_sample = initial_sample(src, getidx);
src_frames1++;
states->init = 0; states->init = 0;
} }
while (dst_frames1 < dst_frames) { while (dst_frames1 < dst_frames) {
if (pos >= get_threshold) { if (pos >= get_threshold) {
int16_t new_sample;
if (src_frames1 == src_frames) if (src_frames1 == src_frames)
break; break;
old_sample = new_sample;
pos -= get_threshold; pos -= get_threshold;
goto *get; goto *get;
#define GET16_END after_get #define GET16_END after_get
#include "plugin_ops.h" #include "plugin_ops.h"
#undef GET16_END #undef GET16_END
after_get: after_get:
new_sample = sample;
src += src_step; src += src_step;
src_frames1++; src_frames1++;
new_sample = sample; #if 1 /* fast-change interpolation */
sample = (old_sample * (DIV - pos) + new_sample * pos) / DIV; /* this interpolation gives us better results especially for low-rate sources */
old_sample = new_sample; // sample = (((int)old_sample * (DIV - pos)) + ((int)new_sample * pos)) / DIV;
} else sample = ((int)old_sample + (int)new_sample) / 2;
sample = old_sample; } else {
sample = new_sample;
}
#else /* linear interpolation */
/* in some cases, a high-band filter is required to remove high noises */
}
sample = (((int)old_sample * (DIV - pos)) + ((int)new_sample * pos)) / DIV;
#endif
goto *put; goto *put;
#define PUT16_END after_put #define PUT16_END after_put
#include "plugin_ops.h" #include "plugin_ops.h"
@ -156,7 +166,8 @@ static snd_pcm_uframes_t snd_pcm_rate_expand(const snd_pcm_channel_area_t *dst_a
dst_frames1++; dst_frames1++;
pos += DIV; pos += DIV;
} }
states->sample = old_sample; states->old_sample = old_sample;
states->new_sample = new_sample;
states->pos = pos; states->pos = pos;
states++; states++;
} }
@ -447,7 +458,8 @@ static int snd_pcm_rate_init(snd_pcm_t *pcm)
unsigned int k; unsigned int k;
for (k = 0; k < pcm->channels; ++k) { for (k = 0; k < pcm->channels; ++k) {
rate->states[k].sum = 0; rate->states[k].sum = 0;
rate->states[k].sample = 0; rate->states[k].old_sample = 0;
rate->states[k].new_sample = 0;
rate->states[k].pos = 0; rate->states[k].pos = 0;
rate->states[k].init = 0; rate->states[k].init = 0;
} }