diff options
author | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-22 20:12:17 +0000 |
---|---|---|
committer | Martin Peach <mrpeach@users.sourceforge.net> | 2010-03-22 20:12:17 +0000 |
commit | 5380a5b7e62aa57289b877d8b67403dda1be5b7b (patch) | |
tree | 960c68184d427871122074e26767d719d51df594 | |
parent | 37d1ba3860502e9105084a17405d67f0ed7e13d6 (diff) |
Changed valid-stream output to be a signal output. Moved all post()s out of the perform routine. Updated help patch and version.
svn path=/trunk/externals/mrpeach/; revision=13239
-rw-r--r-- | net/udpreceive~.c | 76 | ||||
-rw-r--r-- | net/udpsend~-help.pd | 104 | ||||
-rw-r--r-- | net/udpsend~.h | 2 |
3 files changed, 105 insertions, 77 deletions
diff --git a/net/udpreceive~.c b/net/udpreceive~.c index 74d49fc..42bf7c7 100644 --- a/net/udpreceive~.c +++ b/net/udpreceive~.c @@ -78,7 +78,7 @@ typedef struct _udpreceive_tilde t_outlet *x_outlet1; t_outlet *x_outlet2; t_outlet *x_addrout; - t_outlet *x_validout; + t_clock *x_clock; t_atom x_addrbytes[5]; int x_socket; int x_connectsocket; @@ -86,6 +86,9 @@ typedef struct _udpreceive_tilde long x_addr; unsigned short x_port; t_symbol *x_hostname; + int x_error; + int x_buffering; + char x_msg[256]; /* buffering */ int x_framein;// index of next empty frame in x_frames[] @@ -102,7 +105,7 @@ typedef struct _udpreceive_tilde int x_counter;// count of received frames int x_average[DEFAULT_AVERAGE_NUMBER]; int x_averagecur; - int x_underflow; + int x_underflow; int x_overflow; int x_valid; long x_samplerate; @@ -120,6 +123,7 @@ static int udpreceive_tilde_createsocket(t_udpreceive_tilde* x, int portno); static t_int *udpreceive_tilde_perform(t_int *w); static void udpreceive_tilde_dsp(t_udpreceive_tilde *x, t_signal **sp); static void udpreceive_tilde_info(t_udpreceive_tilde *x); +static void udpreceive_tilde_tick(t_udpreceive_tilde *x); static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floatarg blocksize); static void udpreceive_tilde_free(t_udpreceive_tilde *x); void udpreceive_tilde_setup(void); @@ -141,7 +145,6 @@ static void udpreceive_tilde_closesocket(t_udpreceive_tilde* x) { sys_rmpollfn(x->x_socket); outlet_float(x->x_outlet1, 0); - outlet_float(x->x_validout, 0); CLOSESOCKET(x->x_socket); x->x_socket = -1; } @@ -174,6 +177,7 @@ static void udpreceive_tilde_reset(t_udpreceive_tilde* x, t_floatarg buffer) } x->x_underflow = 0; x->x_overflow = 0; + x->x_buffering = 1; } static void udpreceive_tilde_datapoll(t_udpreceive_tilde *x) @@ -236,7 +240,7 @@ static void udpreceive_tilde_datapoll(t_udpreceive_tilde *x) tag_ptr->framesize = ntohl(tag_ptr->framesize); /* get info from header tag */ - if (tag_ptr->channels > x->x_noutlets) + if (tag_ptr->channels > (x->x_noutlets-1)) { error("udpreceive~: incoming stream has too many channels (%d)", tag_ptr->channels); x->x_counter = 0; @@ -366,6 +370,7 @@ static t_int *udpreceive_tilde_perform(t_int *w) const int channels = x->x_frames[x->x_frameout].tag.channels; int i = 0; + x->x_valid = 0; for (i = 0; i < x->x_noutlets; i++) { out[i] = (t_float *)(w[offset + i]); @@ -380,10 +385,11 @@ static t_int *udpreceive_tilde_perform(t_int *w) } /* check whether there is enough data in buffer */ - if (x->x_counter < x->x_maxframes) + if (x->x_buffering && (x->x_counter < x->x_maxframes)) { goto bail; } + x->x_buffering = 0; /* check for buffer underflow */ if (x->x_framein == x->x_frameout) @@ -392,6 +398,7 @@ static t_int *udpreceive_tilde_perform(t_int *w) goto bail; } + x->x_valid = 1; /* queue balancing */ x->x_average[x->x_averagecur] = QUEUESIZE; if (++x->x_averagecur >= DEFAULT_AVERAGE_NUMBER) @@ -412,11 +419,13 @@ static t_int *udpreceive_tilde_perform(t_int *w) fl.i32 = ntohl(*buf++); *out[i]++ = fl.f32; } - for (i = channels; i < x->x_noutlets; i++) + for (i = channels; i < (x->x_noutlets-1); i++) { *out[i]++ = 0.; } + *out[i]++ = x->x_valid; } + x->x_error = 0; break; } case SF_16BIT: @@ -429,11 +438,13 @@ static t_int *udpreceive_tilde_perform(t_int *w) { *out[i]++ = (t_float)((short)(ntohs(*buf++)) * 3.051850e-05); } - for (i = channels; i < x->x_noutlets; i++) + for (i = channels; i < (x->x_noutlets-1); i++) { *out[i]++ = 0.; } + *out[i]++ = x->x_valid; } + x->x_error = 0; break; } case SF_8BIT: @@ -446,25 +457,42 @@ static t_int *udpreceive_tilde_perform(t_int *w) { *out[i]++ = (t_float)((0.0078125 * (*buf++)) - 1.0); } - for (i = channels; i < x->x_noutlets; i++) + for (i = channels; i < (x->x_noutlets-1); i++) { *out[i]++ = 0.; } + *out[i]++ = x->x_valid; } + x->x_error = 0; break; } case SF_MP3: { - post("udpreceive~: mp3 format not supported"); + if (x->x_error != 1) + { + x->x_error = 1; + sprintf(x->x_msg, "udpreceive~: mp3 format not supported"); + clock_delay(x->x_clock, 0); + } break; } case SF_AAC: { - post("udpreceive~: aac format not supported"); + if (x->x_error != 2) + { + x->x_error = 2; + sprintf(x->x_msg, "udpreceive~: aac format not supported"); + clock_delay(x->x_clock, 0); + } break; } default: - post("udpreceive~: unknown format (%d)",x->x_frames[x->x_frameout].tag.format); + if (x->x_error != 3) + { + x->x_error = 3; + sprintf(x->x_msg, "udpreceive~: unknown format (%d)",x->x_frames[x->x_frameout].tag.format); + clock_delay(x->x_clock, 0); + } break; } @@ -476,21 +504,11 @@ static t_int *udpreceive_tilde_perform(t_int *w) } else x->x_blockssincerecv++; - if (x->x_valid != 1) - { - x->x_valid = 1; - outlet_float(x->x_validout, x->x_valid); - } return (w + offset + x->x_noutlets); bail: /* set output to zero */ while (n--) for (i = 0; i < x->x_noutlets; i++) *(out[i]++) = 0.; - if (x->x_valid != 0) - { - x->x_valid = 0; - outlet_float(x->x_validout, x->x_valid); - } return (w + offset + x->x_noutlets); } @@ -609,6 +627,12 @@ static void udpreceive_tilde_info(t_udpreceive_tilde *x) outlet_list(x->x_addrout, &s_list, 5L, x->x_addrbytes); } +static void udpreceive_tilde_tick(t_udpreceive_tilde *x) +{ +/* post a message once, outside of perform routine */ + post("%s", x->x_msg); +} + static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floatarg blocksize) { t_udpreceive_tilde *x; @@ -628,7 +652,7 @@ static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floa return NULL; } - x->x_noutlets = (int)outlets; + x->x_noutlets = (int)outlets + 1; // extra outlet for valid flag for (i = 0; i < x->x_noutlets; i++) outlet_new(&x->x_obj, &s_signal); x->x_outlet2 = outlet_new(&x->x_obj, &s_anything); @@ -640,7 +664,6 @@ static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floa } x->x_addr = 0; x->x_port = 0; - x->x_validout = outlet_new(&x->x_obj, &s_float); x->x_myvec = (t_int **)t_getbytes(sizeof(t_int *) * (x->x_noutlets + 3)); if (!x->x_myvec) { @@ -654,8 +677,9 @@ static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floa /* allocate space for 16 frames of 1024 X numchannels floats*/ for (i = 0; i < DEFAULT_AUDIO_BUFFER_FRAMES; i++) { - x->x_frames[i].data = (char *)t_getbytes(DEFAULT_AUDIO_BUFFER_SIZE * x->x_noutlets * sizeof(t_float)); + x->x_frames[i].data = (char *)t_getbytes(DEFAULT_AUDIO_BUFFER_SIZE * (x->x_noutlets-1) * sizeof(t_float)); } + x->x_clock = clock_new(&x->x_obj.ob_pd, (t_method)udpreceive_tilde_tick); x->x_sync = 1; x->x_tag_errors = x->x_framein = x->x_frameout = x->x_valid = 0; @@ -670,6 +694,7 @@ static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floa else x->x_blocksize = (int)blocksize; //DEFAULT_AUDIO_BUFFER_SIZE; /* <-- the only place blocksize is set */ x->x_blockssincerecv = 0; x->x_blocksperrecv = x->x_blocksize / x->x_vecsize; + x->x_buffering = 1; if (!udpreceive_tilde_createsocket(x, (int)fportno)) { @@ -699,8 +724,9 @@ static void udpreceive_tilde_free(t_udpreceive_tilde *x) t_freebytes(x->x_myvec, sizeof(t_int *) * (x->x_noutlets + 3)); for (i = 0; i < DEFAULT_AUDIO_BUFFER_FRAMES; i++) { - t_freebytes(x->x_frames[i].data, DEFAULT_AUDIO_BUFFER_SIZE * x->x_noutlets * sizeof(t_float)); + t_freebytes(x->x_frames[i].data, DEFAULT_AUDIO_BUFFER_SIZE * (x->x_noutlets-1) * sizeof(t_float)); } + clock_free(x->x_clock); } void udpreceive_tilde_setup(void) diff --git a/net/udpsend~-help.pd b/net/udpsend~-help.pd index d08675d..bd03c81 100644 --- a/net/udpsend~-help.pd +++ b/net/udpsend~-help.pd @@ -1,4 +1,4 @@ -#N canvas 415 49 859 803 10; +#N canvas 197 27 785 803 10; #X obj -178 225 osc~ 440; #X msg -398 60 disconnect; #X msg -353 105 format float; @@ -8,9 +8,9 @@ #X text -244 103 float is the most expensive with the best resolution (32bit) \, default is 16bit; #X msg -419 39 connect 255.255.255.255 8008; -#X obj 12 668 print udpreceive~; +#X obj 52 687 print udpreceive~; #X obj 224 369 print udpsend~; -#X obj -178 320 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 1 +#X obj -178 320 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1; #X symbolatom -97 435 10 0 0 0 - - -; #X floatatom -44 369 5 0 0 0 - - -; @@ -20,42 +20,42 @@ #X obj -97 411 prepend set; #X obj 117 367 prepend set; #X text -102 368 channels:; -#X text -152 442 format:; +#X text -144 442 format:; #X text 13 411 bitrate:; #X text -51 391 framesize:; #X text 98 389 to:; #X msg -216 242 info; -#X symbolatom -333 755 10 0 0 0 - - -; -#X floatatom -299 689 5 0 0 0 - - -; -#X floatatom -264 668 7 0 0 0 - - -; -#X floatatom -230 733 9 0 0 0 - - -; -#X obj -333 714 prepend set; -#X text -363 688 channels:; -#X text -379 754 format:; -#X text -279 732 bitrate:; -#X text -328 667 framesize:; -#X floatatom -195 690 9 0 0 0 - - -; -#X floatatom -161 668 9 0 0 0 - - -; -#X floatatom -126 711 5 0 0 0 - - -; -#X floatatom -92 690 5 0 0 0 - - -; -#X text -252 689 overflow:; -#X text -221 667 underflow:; -#X text -187 710 queuesize:; -#X text -140 689 average:; -#X msg -443 478 info; +#X symbolatom -293 774 10 0 0 0 - - -; +#X floatatom -259 708 5 0 0 0 - - -; +#X floatatom -224 687 7 0 0 0 - - -; +#X floatatom -190 752 9 0 0 0 - - -; +#X obj -293 733 prepend set; +#X text -323 707 channels:; +#X text -339 773 format:; +#X text -239 751 bitrate:; +#X text -288 686 framesize:; +#X floatatom -155 709 9 0 0 0 - - -; +#X floatatom -121 687 9 0 0 0 - - -; +#X floatatom -86 730 5 0 0 0 - - -; +#X floatatom -52 709 5 0 0 0 - - -; +#X text -212 708 overflow:; +#X text -181 686 underflow:; +#X text -147 729 queuesize:; +#X text -100 708 average:; +#X msg -435 478 info; #X text -237 34 broadcast to everybody on your local subnet listening on the specified port; -#X msg -463 458 reset; -#X text -410 477 status info to rightmost outlet; +#X msg -455 458 reset; +#X text -402 477 status info to rightmost outlet; #X text -415 241 status info to rightmost outlet; -#X text -425 457 reset underflow & overflow counters; -#X floatatom -301 608 3 0 0 0 - - -; -#X floatatom -278 608 3 0 0 0 - - -; -#X floatatom -255 608 3 0 0 0 - - -; -#X floatatom -232 608 3 0 0 0 - - -; -#X floatatom -208 608 5 0 0 0 - - -; -#X obj -301 582 unpack 0 0 0 0 0; -#X text -338 607 from:; +#X text -417 457 reset underflow & overflow counters; +#X floatatom -260 589 3 0 0 0 - - -; +#X floatatom -237 589 3 0 0 0 - - -; +#X floatatom -214 589 3 0 0 0 - - -; +#X floatatom -191 589 3 0 0 0 - - -; +#X floatatom -167 589 5 0 0 0 - - -; +#X obj -260 563 unpack 0 0 0 0 0; +#X text -297 588 from:; #X obj -179 268 *~; #X floatatom -164 150 5 0 0 0 - - -; #X text -66 148 Framesize = (blocksize) X (number of channels) X (bytes @@ -66,11 +66,11 @@ per sample); #X text 70 430 dsp vector size:; #X msg -258 200 channels \$1; #X obj -412 185 hradio 15 1 0 4 empty empty empty 0 -8 0 10 -4034 -1 --1 1; +-1 0; #X obj -178 297 udpsend~ 2 512; #X text -88 296 sends 2 dsp-channels using 512-sample blocks; -#X obj -397 541 udpreceive~ 8008 2 512; -#X obj -398 570 dac~ 1 2; +#X obj -389 541 udpreceive~ 8008 2 512; +#X obj -388 572 dac~ 1 2; #X text 68 448 (blocksize must be a multiple of this); #X text -160 318 1 = transmitting; #X obj -97 246 noise~; @@ -78,15 +78,15 @@ per sample); #X obj -164 170 / 100; #X text -455 338 Based on: [netreceive~] and [netsend~]by Olaf Matthes ; -#X floatatom -57 733 9 0 0 0 - - -; -#X text -109 732 packets:; +#X floatatom -17 752 9 0 0 0 - - -; +#X text -69 751 packets:; #X text -50 177 Default blocksize is 2048 The number of samples per block must be an integer multiple of the number of samples in one signal vector.; #X text -28 225 Arguments: (1st required \, 2nd optional) 1:number of channels to send. 2:blocksize = number of samples per channel per frame. (Blocksize of sender and receiver must be the same.); -#X text -43 560 To communicate \, a [udpreceive~] and [udpsend~] pair +#X text -127 554 To communicate \, a [udpreceive~] and [udpsend~] pair must have the same number of channels and the same blocksize. Also [udpsend~] must [connect( to the port on which [udpreceive~] is listening. ; @@ -94,27 +94,28 @@ must have the same number of channels and the same blocksize. Also #X text -355 76 format defines the resolution of the sent signal and may be changed on-the-fly; #X text -450 200 number of channels to transmit; -#X msg -422 499 buffer 2; -#X text -360 498 set number of frames to buffer before playback; +#X msg -414 499 buffer 2; +#X text -352 498 set number of frames to buffer before playback; #X text -458 365 [udpsend~] transmits dsp vectors ("audio") via UDP. UDP is a connectionless protocol \, so [udpsend~] will transmit even if nothing is receiving.; #X text -299 18 connect to <hostname> <port> and begin transmitting ; #X text -456 313 [udpreceive~] and [udpsend~]; -#X text -256 540 receives 2 channels on port 8008 Same blocksize as +#X text -248 540 receives 2 channels on port 8008 Same blocksize as udpsend~; #X floatatom -412 216 5 0 0 0 - - -; #X obj -288 172 tgl 15 0 empty empty toggle_connection 17 7 0 10 -4034 -1 -1 0 1; -#X obj -333 631 route format channels framesize bitrate overflow underflow +#X obj -293 650 route format channels framesize bitrate overflow underflow queuesize average packets tag_errors; -#X floatatom -23 711 9 0 0 0 - - -; -#X text -89 710 tag errors:; -#X obj -268 562 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 1 -1; -#X text -455 326 Author: Martin Peach 2010/03/16; -#X text -250 560 1 = valid audio; +#X floatatom 17 730 9 0 0 0 - - -; +#X text -49 729 tag errors:; +#X obj -326 601 env~; +#X floatatom -326 624 9 0 0 0 - - -; +#X text -266 613 The rightmost signal outlet outputs 1 if the stream +is valid \, else 0; +#X text -455 326 Author: Martin Peach 2010/03/22; #X connect 0 0 54 0; #X connect 1 0 62 0; #X connect 2 0 62 0; @@ -149,9 +150,9 @@ queuesize average packets tag_errors; #X connect 62 1 57 0; #X connect 64 0 65 0; #X connect 64 1 65 1; -#X connect 64 2 88 0; -#X connect 64 3 52 0; -#X connect 64 4 91 0; +#X connect 64 2 91 0; +#X connect 64 3 88 0; +#X connect 64 4 52 0; #X connect 68 0 69 0; #X connect 69 0 62 1; #X connect 70 0 54 1; @@ -169,3 +170,4 @@ queuesize average packets tag_errors; #X connect 88 8 72 0; #X connect 88 9 89 0; #X connect 88 10 8 0; +#X connect 91 0 92 0; diff --git a/net/udpsend~.h b/net/udpsend~.h index 43fa561..386b363 100644 --- a/net/udpsend~.h +++ b/net/udpsend~.h @@ -34,7 +34,7 @@ /* Some enhancements have been made with the goal of keeping compatibility */ /* between the stream formats of streamout~/in~ and netsend~/receive~. */ -#define VERSION "0.33" +#define VERSION "0.34" #define DEFAULT_AUDIO_CHANNELS 32 /* nax. number of audio channels we support */ #define DEFAULT_AUDIO_BUFFER_SIZE 2048 /*1024*/ /* number of samples in one audio block */ |