Update of /cvsroot/alsa/alsa-lib/src/pcm
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28393
Modified Files:
pcm_rate.c
Log Message:
Preparation for more rate conversion types
Index: pcm_rate.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_rate.c,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- pcm_rate.c 10 Sep 2003 11:02:57 -0000 1.74
+++ pcm_rate.c 24 Jan 2004 16:23:11 -0000 1.75
@@ -40,11 +40,21 @@
#define DIV (1<<16)
+enum rate_type {
+ RATE_TYPE_LINEAR, /* linear interpolation */
+ RATE_TYPE_BANDLIMIT, /* bandlimited interpolation */
+ RATE_TYPE_POLYPHASE, /* polyphase resampling */
+};
+
typedef struct {
- int init;
- int16_t old_sample, new_sample;
- int sum;
- unsigned int pos;
+ union {
+ struct {
+ int init;
+ int16_t old_sample, new_sample;
+ int sum;
+ unsigned int pos;
+ } linear;
+ } u;
} snd_pcm_rate_state_t;
typedef snd_pcm_uframes_t (*rate_f)(const snd_pcm_channel_area_t *dst_areas,
@@ -61,6 +71,7 @@
typedef struct {
/* This field need to be the first */
snd_pcm_plugin_t plug;
+ enum rate_type type;
unsigned int get_idx;
unsigned int put_idx;
unsigned int pitch;
@@ -117,24 +128,24 @@
const char *src;
char *dst;
int src_step, dst_step;
- int16_t old_sample = states->old_sample;
- int16_t new_sample = states->new_sample;
- unsigned int pos = states->pos;
+ int16_t old_sample = states->u.linear.old_sample;
+ int16_t new_sample = states->u.linear.new_sample;
+ unsigned int pos = states->u.linear.pos;
src = snd_pcm_channel_area_addr(src_area, src_offset);
dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
src_step = snd_pcm_channel_area_step(src_area);
dst_step = snd_pcm_channel_area_step(dst_area);
src_frames1 = 0;
dst_frames1 = 0;
- if (! states->init) {
+ if (! states->u.linear.init) {
sample = initial_sample(src, getidx);
old_sample = new_sample = sample;
src += src_step;
src_frames1++;
- states->init = 2; /* get a new sample */
+ states->u.linear.init = 2; /* get a new sample */
}
while (dst_frames1 < dst_frames) {
- if (states->init == 2) {
+ if (states->u.linear.init == 2) {
old_sample = new_sample;
goto *get;
#define GET16_END after_get
@@ -142,7 +153,7 @@
#undef GET16_END
after_get:
new_sample = sample;
- states->init = 1;
+ states->u.linear.init = 1;
}
sample = (((int64_t)old_sample * (int64_t)(get_threshold -
pos)) + ((int64_t)new_sample * pos)) / get_threshold;
goto *put;
@@ -157,14 +168,14 @@
pos -= get_threshold;
src += src_step;
src_frames1++;
- states->init = 2; /* get a new sample */
+ states->u.linear.init = 2; /* get a new sample */
if (src_frames1 >= src_frames)
break;
}
}
- states->old_sample = old_sample;
- states->new_sample = new_sample;
- states->pos = pos;
+ states->u.linear.old_sample = old_sample;
+ states->u.linear.new_sample = new_sample;
+ states->u.linear.pos = pos;
states++;
}
*dst_framesp = dst_frames1;
@@ -204,9 +215,9 @@
const char *src;
char *dst;
int src_step, dst_step;
- sum = states->sum;
- pos = states->pos;
- states->init = 0;
+ sum = states->u.linear.sum;
+ pos = states->u.linear.pos;
+ states->u.linear.init = 0;
src = snd_pcm_channel_area_addr(src_area, src_offset);
dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
src_step = snd_pcm_channel_area_step(src_area);
@@ -242,8 +253,8 @@
} else
sum += sample * get_increment;
}
- states->sum = sum;
- states->pos = pos;
+ states->u.linear.sum = sum;
+ states->u.linear.pos = pos;
states++;
}
*dst_framesp = dst_frames1;
@@ -488,12 +499,17 @@
{
snd_pcm_rate_t *rate = pcm->private_data;
unsigned int k;
- for (k = 0; k < pcm->channels; ++k) {
- rate->states[k].sum = 0;
- rate->states[k].old_sample = 0;
- rate->states[k].new_sample = 0;
- rate->states[k].pos = 0;
- rate->states[k].init = 0;
+ switch (rate->type) {
+ case RATE_TYPE_LINEAR:
+ for (k = 0; k < pcm->channels; ++k) {
+ rate->states[k].u.linear.sum = 0;
+ rate->states[k].u.linear.old_sample = 0;
+ rate->states[k].u.linear.new_sample = 0;
+ rate->states[k].u.linear.pos = 0;
+ rate->states[k].u.linear.init = 0;
+ }
+ default:
+ assert(0);
}
return 0;
}
@@ -617,6 +633,7 @@
return -ENOMEM;
}
snd_pcm_plugin_init(&rate->plug);
+ rate->type = RATE_TYPE_LINEAR;
rate->srate = srate;
rate->sformat = sformat;
rate->plug.read = snd_pcm_rate_read_areas;
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog