[PD-cvs] pd/src d_ugen.c,1.3.4.1.2.5.2.9,1.3.4.1.2.5.2.10
Mathieu Bouchard
matju at users.sourceforge.net
Thu Jun 28 18:36:00 CEST 2007
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24075
Modified Files:
Tag: desiredata
d_ugen.c
Log Message:
more cleanup (resample)
Index: d_ugen.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/d_ugen.c,v
retrieving revision 1.3.4.1.2.5.2.9
retrieving revision 1.3.4.1.2.5.2.10
diff -C2 -d -r1.3.4.1.2.5.2.9 -r1.3.4.1.2.5.2.10
*** d_ugen.c 28 Jun 2007 15:58:10 -0000 1.3.4.1.2.5.2.9
--- d_ugen.c 28 Jun 2007 16:35:58 -0000 1.3.4.1.2.5.2.10
***************
*** 910,991 ****
/* resampling code originally by Johannes Zmölnig in 2001 */
/* also "block-resampling" added by Johannes in 2004.09 */
-
- #include "m_pd.h"
-
/* --------------------- up/down-sampling --------------------- */
-
/* LATER: add some downsampling-filters for HOLD and LINEAR */
! t_int *downsampling_perform_0(t_int *w)
! {
t_float *in = (t_float *)(w[1]); /* original signal */
t_float *out = (t_float *)(w[2]); /* downsampled signal */
int down = (int)(w[3]); /* downsampling factor */
int parent = (int)(w[4]); /* original vectorsize */
-
int n=parent/down;
!
! while(n--){
*out++=*in;
in+=down;
}
!
! return (w+5);
}
! t_int *downsampling_perform_block(t_int *w)
! {
/* the downsampled vector is exactly the first part of the parent vector
* the rest of the parent is just skipped
* cool for FFT-data, where you only want to process the significant (1st) part of the vector
*/
! t_float *in = (t_float *)(w[1]); /* original signal */
! t_float *out = (t_float *)(w[2]); /* downsampled signal */
! int down = (int)(w[3]); /* downsampling factor */
! int parent = (int)(w[4]); /* original vectorsize */
!
int n=parent/down;
!
! while(n--){
! *out++=*in++;
! }
!
! return (w+5);
}
! t_int *upsampling_perform_0(t_int *w)
! {
! t_float *in = (t_float *)(w[1]); /* original signal */
! t_float *out = (t_float *)(w[2]); /* upsampled signal */
! int up = (int)(w[3]); /* upsampling factor */
! int parent = (int)(w[4]); /* original vectorsize */
!
int n=parent*up;
t_float *dummy = out;
!
! while(n--)*out++=0;
!
n = parent;
out = dummy;
! while(n--){
*out=*in++;
out+=up;
}
!
! return (w+5);
}
! t_int *upsampling_perform_hold(t_int *w)
! {
! t_float *in = (t_float *)(w[1]); /* original signal */
! t_float *out = (t_float *)(w[2]); /* upsampled signal */
! int up = (int)(w[3]); /* upsampling factor */
! int parent = (int)(w[4]); /* original vectorsize */
int i=up;
-
int n=parent;
t_float *dum_out = out;
t_float *dum_in = in;
-
while (i--) {
n = parent;
--- 910,969 ----
/* resampling code originally by Johannes Zmölnig in 2001 */
/* also "block-resampling" added by Johannes in 2004.09 */
/* --------------------- up/down-sampling --------------------- */
/* LATER: add some downsampling-filters for HOLD and LINEAR */
! t_int *downsampling_perform_0(t_int *w) {
t_float *in = (t_float *)(w[1]); /* original signal */
t_float *out = (t_float *)(w[2]); /* downsampled signal */
int down = (int)(w[3]); /* downsampling factor */
int parent = (int)(w[4]); /* original vectorsize */
int n=parent/down;
! while(n--) {
*out++=*in;
in+=down;
}
! return w+5;
}
! t_int *downsampling_perform_block(t_int *w) {
/* the downsampled vector is exactly the first part of the parent vector
* the rest of the parent is just skipped
* cool for FFT-data, where you only want to process the significant (1st) part of the vector
*/
! t_float *in = (t_float *)w[1]; /* original signal */
! t_float *out = (t_float *)w[2]; /* downsampled signal */
! int down = int(w[3]); /* downsampling factor */
! int parent = int(w[4]); /* original vectorsize */
int n=parent/down;
! while(n--) *out++=*in++;
! return w+5;
}
! t_int *upsampling_perform_0(t_int *w) {
! t_float *in = (t_float *)w[1]; /* original signal */
! t_float *out = (t_float *)w[2]; /* upsampled signal */
! int up = int(w[3]); /* upsampling factor */
! int parent = int(w[4]); /* original vectorsize */
int n=parent*up;
t_float *dummy = out;
! while(n--) *out++=0;
n = parent;
out = dummy;
! while(n--) {
*out=*in++;
out+=up;
}
! return w+5;
}
! t_int *upsampling_perform_hold(t_int *w) {
! t_float *in = (t_float *)w[1]; /* original signal */
! t_float *out = (t_float *)w[2]; /* upsampled signal */
! int up = int(w[3]); /* upsampling factor */
! int parent = int(w[4]); /* original vectorsize */
int i=up;
int n=parent;
t_float *dum_out = out;
t_float *dum_in = in;
while (i--) {
n = parent;
***************
*** 997,1015 ****
}
}
! return (w+5);
}
! t_int *upsampling_perform_linear(t_int *w)
! {
! t_resample *x= (t_resample *)(w[1]);
! t_float *in = (t_float *)(w[2]); /* original signal */
! t_float *out = (t_float *)(w[3]); /* upsampled signal */
! const int up = (int)(w[4]); /* upsampling factor */
! const int parent = (int)(w[5]); /* original vectorsize */
const int length = parent*up;
int n;
t_float *fp;
! t_float a=*x->buffer, b=*in;
!
const t_float up_inv = (t_float)1.0/up;
t_float findex = 0.f;
--- 975,991 ----
}
}
! return w+5;
}
! t_int *upsampling_perform_linear(t_int *w) {
! t_resample *x= (t_resample *)w[1];
! t_float *in = (t_float *)w[2]; /* original signal */
! t_float *out = (t_float *)w[3]; /* upsampled signal */
! const int up = int(w[4]); /* upsampling factor */
! const int parent = int(w[5]); /* original vectorsize */
const int length = parent*up;
int n;
t_float *fp;
! t_float a=*x->buffer, b=*in;
const t_float up_inv = (t_float)1.0/up;
t_float findex = 0.f;
***************
*** 1024,1034 ****
a=(index)?*(fp-1):a;
}
-
*x->buffer = a;
! return (w+6);
}
! t_int *upsampling_perform_block(t_int *w)
! {
/* 1st part of the upsampled signal-vector will be the original one
* 2nd part of the upsampled signal-vector is just 0
--- 1000,1008 ----
a=(index)?*(fp-1):a;
}
*x->buffer = a;
! return w+6;
}
! t_int *upsampling_perform_block(t_int *w) {
/* 1st part of the upsampled signal-vector will be the original one
* 2nd part of the upsampled signal-vector is just 0
***************
*** 1040,1093 ****
int parent = (int)(w[4]); /* original vectorsize */
int i=parent;
-
int n=parent*(up-1);
!
! while (i--) {
! *out++=*in++;
! }
! while(n--) {
! *out++=0.f;
! }
! return (w+5);
}
-
/* ----------------------- public -------------------------------- */
-
/* utils */
! void resample_init(t_resample *x)
! {
x->method=0;
-
x->downsample=x->upsample=1;
-
x->s_n = x->coefsize = x->bufsize = 0;
x->s_vec = x->coeffs = x->buffer = 0;
}
! void resample_free(t_resample *x)
! {
if (x->s_n) t_freebytes(x->s_vec, x->s_n*sizeof(*x->s_vec));
if (x->coefsize) t_freebytes(x->coeffs, x->coefsize*sizeof(*x->coeffs));
if (x->bufsize) t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer));
-
x->s_n = x->coefsize = x->bufsize = 0;
x->s_vec = x->coeffs = x->buffer = 0;
}
-
/* dsp-adding */
-
void resample_dsp(t_resample *x,
! t_sample* in, int insize,
! t_sample* out, int outsize,
! int method)
! {
! if (insize == outsize){
bug("nothing to be done");
return;
}
-
if (insize > outsize) { /* downsampling */
if (insize % outsize) {
--- 1014,1050 ----
int parent = (int)(w[4]); /* original vectorsize */
int i=parent;
int n=parent*(up-1);
! while (i--) *out++=*in++;
! while(n--) *out++=0.f;
! return w+5;
}
/* ----------------------- public -------------------------------- */
/* utils */
! void resample_init(t_resample *x) {
x->method=0;
x->downsample=x->upsample=1;
x->s_n = x->coefsize = x->bufsize = 0;
x->s_vec = x->coeffs = x->buffer = 0;
}
! void resample_free(t_resample *x) {
if (x->s_n) t_freebytes(x->s_vec, x->s_n*sizeof(*x->s_vec));
if (x->coefsize) t_freebytes(x->coeffs, x->coefsize*sizeof(*x->coeffs));
if (x->bufsize) t_freebytes(x->buffer, x->bufsize*sizeof(*x->buffer));
x->s_n = x->coefsize = x->bufsize = 0;
x->s_vec = x->coeffs = x->buffer = 0;
}
/* dsp-adding */
void resample_dsp(t_resample *x,
! t_sample* in, int insize,
! t_sample* out, int outsize,
! int method) {
! if (insize == outsize) {
bug("nothing to be done");
return;
}
if (insize > outsize) { /* downsampling */
if (insize % outsize) {
***************
*** 1102,1106 ****
dsp_add(downsampling_perform_0, 4, in, out, insize/outsize, insize);
}
-
} else { /* upsampling */
if (outsize % insize) {
--- 1059,1062 ----
***************
*** 1129,1143 ****
}
! void resamplefrom_dsp(t_resample *x,
! t_sample *in,
! int insize, int outsize, int method)
! {
if (insize==outsize) {
! t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
x->s_n = 0;
x->s_vec = in;
return;
}
-
if (x->s_n != outsize) {
t_float *buf=x->s_vec;
--- 1085,1095 ----
}
! void resamplefrom_dsp(t_resample *x, t_sample *in, int insize, int outsize, int method) {
if (insize==outsize) {
! t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
x->s_n = 0;
x->s_vec = in;
return;
}
if (x->s_n != outsize) {
t_float *buf=x->s_vec;
***************
*** 1151,1158 ****
}
! void resampleto_dsp(t_resample *x,
! t_sample *out,
! int insize, int outsize, int method)
! {
if (insize==outsize) {
if (x->s_n)t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
--- 1103,1107 ----
}
! void resampleto_dsp(t_resample *x, t_sample *out, int insize, int outsize, int method) {
if (insize==outsize) {
if (x->s_n)t_freebytes(x->s_vec, x->s_n * sizeof(*x->s_vec));
***************
*** 1161,1165 ****
return;
}
-
if (x->s_n != insize) {
t_float *buf=x->s_vec;
--- 1110,1113 ----
***************
*** 1169,1175 ****
x->s_n = insize;
}
-
resample_dsp(x, x->s_vec, x->s_n, out, outsize, method);
-
return;
}
--- 1117,1121 ----
More information about the Pd-cvs
mailing list