Added support for mono streams

Original commit message from CVS:
Added support for mono streams
This commit is contained in:
David Schleef 2001-11-07 00:45:29 +00:00
parent 764560631c
commit 2ad92e2c16
4 changed files with 123 additions and 12 deletions

View file

@ -95,6 +95,7 @@ void conv_double_short_ref(double *dest, short *src, int n)
}
#ifdef HAVE_CPU_PPC
#if 0
static union { int i[4]; float f[4]; } av_tmp __attribute__ ((__aligned__ (16)));
void conv_double_short_altivec(double *dest, short *src, int n)
@ -123,6 +124,7 @@ void conv_double_short_altivec(double *dest, short *src, int n)
}
}
#endif
#endif
@ -172,3 +174,28 @@ void conv_short_double_ppcasm(short *dest, double *src, int n)
#endif
void conv_double_short_dstr(double *dest, short *src, int n, int dstr)
{
int i;
void *d = dest;
for(i=0;i<n;i++){
(*(double *)d)=*src++;
d += dstr;
}
}
void conv_short_double_sstr(short *dest, double *src, int n, int sstr)
{
int i;
double x;
void *s = src;
for(i=0;i<n;i++){
x = *(double *)s;
if(x<-32768.0)x=-32768.0;
if(x>32767.0)x=32767.0;
*dest++ = rint(x);
s += sstr;
}
}

View file

@ -145,9 +145,8 @@ void resample_scale(resample_t * r, void *i_buf, unsigned int i_size)
r->i_start, r->i_end, r->o_start);
}
if ((r->filter_length + r->i_samples)*2*r->channels > r->buffer_len) {
//int size = taps * 2 * r->channels;
int size = (r->filter_length + r->i_samples) * sizeof(double) * r->channels;
if ((r->filter_length + r->i_samples)*2*2 > r->buffer_len) {
int size = (r->filter_length + r->i_samples) * sizeof(double) * 2;
if(r->verbose){
printf("resample temp buffer size=%d\n",size);
@ -158,15 +157,21 @@ void resample_scale(resample_t * r, void *i_buf, unsigned int i_size)
memset(r->buffer, 0, size);
}
conv_double_short(
r->buffer + r->filter_length * sizeof(double) * r->channels,
r->i_buf, r->i_samples * r->channels);
if(r->channels==2){
conv_double_short(
r->buffer + r->filter_length * sizeof(double) * 2,
r->i_buf, r->i_samples * 2);
}else{
conv_double_short_dstr(
r->buffer + r->filter_length * sizeof(double) * 2,
r->i_buf, r->i_samples, sizeof(double) * 2);
}
r->scale(r);
memcpy(r->buffer,
r->buffer + r->i_samples * sizeof(double) * r->channels,
r->filter_length * sizeof(double) * r->channels);
r->buffer + r->i_samples * sizeof(double) * 2,
r->filter_length * sizeof(double) * 2);
/* updating times */
r->i_start += r->i_samples * r->i_inc;
@ -516,8 +521,10 @@ static void resample_sinc_ft(resample_t * r)
}
}
conv_short_double(r->o_buf,out_tmp,2 * r->o_samples);
//o_ptr[0] = double_to_s16(c0);
//o_ptr[1] = double_to_s16(c1);
if(r->channels==2){
conv_short_double(r->o_buf,out_tmp,2 * r->o_samples);
}else{
conv_short_double_sstr(r->o_buf,out_tmp,r->o_samples,2 * sizeof(double));
}
}

View file

@ -21,6 +21,8 @@
#ifndef __RESAMPLE_H__
#define __RESAMPLE_H__
#include <config.h>
typedef struct resample_s resample_t;
struct resample_s {
@ -150,5 +152,8 @@ void conv_short_double_ppcasm(short *dest, double *src, int n);
#define conv_short_double conv_short_double_ref
#endif
void conv_double_short_dstr(double *dest, short *src, int n, int dstr);
void conv_short_double_sstr(short *dest, double *src, int n, int dstr);
#endif /* __RESAMPLE_H__ */

View file

@ -30,12 +30,13 @@ void test_res3(void);
void test_res4(void);
void test_res5(void);
void test_res6(void);
void test_res7(void);
int main(int argc,char *argv[])
{
out = fopen("out","w");
test_res1();
test_res7();
return 0;
}
@ -278,3 +279,74 @@ void test_res6(void)
}
}
void test_res7(void)
{
resample_t *r;
int i;
double sum10k,sum22k;
double f;
int n10k,n22k;
double x;
for(i=0;i<I_RATE;i++){
i_buf[i] = rint(AMP * test_func((double)i/I_RATE));
}
r = malloc(sizeof(resample_t));
memset(r,0,sizeof(resample_t));
r->i_rate = I_RATE;
r->o_rate = O_RATE;
//r->method = RESAMPLE_SINC_SLOW;
r->method = RESAMPLE_SINC;
r->channels = 1;
//r->verbose = 1;
r->filter_length = 64;
r->get_buffer = get_buffer;
resample_init(r);
start_timer();
#define blocked
#ifdef blocked
for(i=0;i+256<I_RATE;i+=256){
resample_scale(r,i_buf+i,256*2);
}
if(I_RATE-i){
resample_scale(r,i_buf+i,(I_RATE-i)*2);
}
#else
resample_scale(r,i_buf,I_RATE*2);
#endif
end_timer();
for(i=0;i<O_RATE;i++){
f = AMP*test_func((double)i/O_RATE);
//f = rint(AMP*test_func((double)i/O_RATE));
fprintf(out,"%d %d %d %g %g\n",i,
o_buf[i],0,
f,o_buf[i]-f);
}
sum10k=0;
sum22k=0;
n10k=0;
n22k=0;
for(i=0;i<O_RATE;i++){
f = AMP*test_func((double)i/O_RATE);
//f = rint(AMP*test_func((double)i/O_RATE));
x = o_buf[i]-f;
if(((0.5*i)/O_RATE*I_RATE)<10000){
sum10k += x*x;
n10k++;
}
if(((0.5*i)/O_RATE*I_RATE)<22050){
sum22k += x*x;
n22k++;
}
}
printf("average error 10k=%g 22k=%g\n",
sqrt(sum10k/n10k),
sqrt(sum22k/n22k));
}