From 03c3eedf6c0804cb5aacdc06c0c38ea7141e37de Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Wed, 5 Mar 2003 21:14:24 +0000 Subject: small cleanup changes, multichannel for streamout started (how to do it in streamin ??) svn path=/trunk/externals/ggee/; revision=454 --- signal/streamout~.c | 68 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 17 deletions(-) (limited to 'signal/streamout~.c') diff --git a/signal/streamout~.c b/signal/streamout~.c index f691860..16150b7 100755 --- a/signal/streamout~.c +++ b/signal/streamout~.c @@ -72,11 +72,9 @@ typedef struct _streamout static void streamout_tempbuf(t_streamout *x,int size) { if (x->cbuf && x->tbufsize) freebytes(x->cbuf,x->tbufsize); - x->tbufsize=size; + x->tbufsize=size*sizeof(float)*x->x_tag.channels; if (!x->cbuf) - x->cbuf = getbytes(size*sizeof(short)); - else - x->cbuf = resizebytes(x->cbuf,x->nsamples*sizeof(short),size*sizeof(short)); + x->cbuf = getbytes(x->tbufsize); x->nsamples = size; } @@ -156,11 +154,19 @@ static void streamout_connect(t_streamout *x, t_symbol *hostname, t_floatarg fpo static t_int *streamout_perform(t_int *w) { t_streamout* x = (t_streamout*) (w[1]); - t_float *in = (t_float *)(w[2]); + t_float *in[4]; char* bp; - int n = (int)(w[3]); - int length = n*SF_SIZEOF(x->x_tag.format); + int n; + int length; int sent = 0; + int i; + int chans = x->x_tag.channels; + + + for (i=0;ix_tag.format)*chans; if (n != x->nsamples) streamout_tempbuf(x,n); @@ -168,20 +174,30 @@ static t_int *streamout_perform(t_int *w) x->x_tag.framesize=length; x->x_tag.count++; /* format the buffer */ - bp = (char*)in; + switch (x->x_tag.format) { + case SF_FLOAT: { + float* cibuf =(float*) x->cbuf; + bp = (char*) x->cbuf; + for (i=0;icbuf; bp = (char*) x->cbuf; - while (n--) - *cibuf++ = (short) 32767.0 * *in++; + for (i=0;icbuf; bp = (char*) x->cbuf; - while (n--) - *cbuf++ = (unsigned char)(128. * (1.0 + *in++)); + for (i=0;is_vec, sp[0]->s_n); + switch (x->x_tag.channels) { + case 1: + dsp_add(streamout_perform, 3, x,sp[0]->s_vec, sp[0]->s_n); + post("one channel mode"); + break; + case 2: + dsp_add(streamout_perform, 4, x,sp[0]->s_vec, sp[1]->s_vec,sp[0]->s_n); + post("two channel mode"); + break; + case 4: + dsp_add(streamout_perform, 6, x,sp[0]->s_vec, sp[1]->s_vec, + sp[2]->s_vec,sp[3]->s_vec,sp[0]->s_n); + post("four channel mode"); + break; + default: + post("streamout: %d channels not supported",x->x_tag.channels); + } } @@ -276,11 +308,13 @@ static void streamout_float(t_streamout* x,t_float arg) -static void *streamout_new(t_symbol* prot) +static void *streamout_new(t_symbol* prot,float channels) { t_streamout *x = (t_streamout *)pd_new(streamout_class); outlet_new(&x->x_obj, &s_float); + if (channels == 0) channels = 1; + x->hostname = gensym("localhost"); x->portno = 3000; x->x_fd = -1; @@ -291,7 +325,7 @@ static void *streamout_new(t_symbol* prot) x->x_protocol = SOCK_DGRAM; x->x_tag.format = SF_FLOAT; - x->x_tag.channels = 1; + x->x_tag.channels = channels; x->x_tag.version = 1; x->cbuf = NULL; streamout_tempbuf(x,64); @@ -310,7 +344,7 @@ static void streamout_free(t_streamout* x) void streamout_tilde_setup(void) { streamout_class = class_new(gensym("streamout~"), (t_newmethod) streamout_new, (t_method) streamout_free, - sizeof(t_streamout), 0, A_DEFSYM, 0); + sizeof(t_streamout), 0, A_DEFSYM,A_DEFFLOAT, 0); class_addmethod(streamout_class, (t_method) streamout_connect, gensym("connect"), A_SYMBOL, A_DEFFLOAT, 0); class_addmethod(streamout_class, (t_method) streamout_disconnect, -- cgit v1.2.1