aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--net/udpreceive~.c124
-rw-r--r--net/udpsend~-help.pd82
-rw-r--r--net/udpsend~.h2
3 files changed, 105 insertions, 103 deletions
diff --git a/net/udpreceive~.c b/net/udpreceive~.c
index 3a5aac8..5b88088 100644
--- a/net/udpreceive~.c
+++ b/net/udpreceive~.c
@@ -74,40 +74,41 @@
typedef struct _udpreceive_tilde
{
- t_object x_obj;
- t_outlet *x_outlet1;
- t_outlet *x_outlet2;
- t_outlet *x_addrout;
- t_atom x_addrbytes[5];
- int x_socket;
- int x_connectsocket;
- int x_nconnections;
- int x_ndrops;
- int x_tcp;
- t_symbol *x_hostname;
+ t_object x_obj;
+ t_outlet *x_outlet1;
+ t_outlet *x_outlet2;
+ t_outlet *x_addrout;
+ t_outlet *x_validout;
+ t_atom x_addrbytes[5];
+ int x_socket;
+ int x_connectsocket;
+ int x_nconnections;
+ long x_addr;
+ unsigned short x_port;
+ t_symbol *x_hostname;
/* buffering */
- int x_framein;// index of next empty frame in x_frames[]
- int x_frameout;// index of next frame to play back from x_frames[]
- t_frame x_frames[DEFAULT_AUDIO_BUFFER_FRAMES];
- int x_maxframes;
- long x_tag_errors;
- int x_sync;// zero if we didn't receive a tag when we expected one
- int x_blocksize;
- int x_blocksperrecv;
- int x_blockssincerecv;
-
- int x_nbytes;
- int x_counter;// count of received frames
- int x_average[DEFAULT_AVERAGE_NUMBER];
- int x_averagecur;
- int x_underflow;
- int x_overflow;
-
- long x_samplerate;
- int x_noutlets;
- int x_vecsize;
- t_int **x_myvec; /* vector we pass on to the DSP routine */
+ int x_framein;// index of next empty frame in x_frames[]
+ int x_frameout;// index of next frame to play back from x_frames[]
+ t_frame x_frames[DEFAULT_AUDIO_BUFFER_FRAMES];
+ int x_maxframes;
+ long x_tag_errors;
+ int x_sync;// zero if we didn't receive a tag when we expected one
+ int x_blocksize;
+ int x_blocksperrecv;
+ int x_blockssincerecv;
+
+ int x_nbytes;
+ int x_counter;// count of received frames
+ int x_average[DEFAULT_AVERAGE_NUMBER];
+ int x_averagecur;
+ int x_underflow;
+ int x_overflow;
+ int x_valid;
+ long x_samplerate;
+ int x_noutlets;
+ int x_vecsize;
+ t_int **x_myvec; /* vector we pass on to the DSP routine */
} t_udpreceive_tilde;
/* function prototypes */
@@ -140,6 +141,7 @@ 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;
}
@@ -178,10 +180,10 @@ static void udpreceive_tilde_datapoll(t_udpreceive_tilde *x)
{
int ret;
int n;
- struct sockaddr_in from;
- socklen_t fromlen = sizeof(from);
long addr;
unsigned short port;
+ struct sockaddr_in from;
+ socklen_t fromlen = sizeof(from);
t_tag *tag_ptr;
n = x->x_nbytes;
@@ -195,15 +197,19 @@ static void udpreceive_tilde_datapoll(t_udpreceive_tilde *x)
/* get the sender's ip */
addr = ntohl(from.sin_addr.s_addr);
port = ntohs(from.sin_port);
-
- x->x_addrbytes[0].a_w.w_float = (addr & 0xFF000000)>>24;
- x->x_addrbytes[1].a_w.w_float = (addr & 0x0FF0000)>>16;
- x->x_addrbytes[2].a_w.w_float = (addr & 0x0FF00)>>8;
- x->x_addrbytes[3].a_w.w_float = (addr & 0x0FF);
- x->x_addrbytes[4].a_w.w_float = port;
- outlet_list(x->x_addrout, &s_list, 5L, x->x_addrbytes);
-
- if (ret <= 0) /* error */
+ /* output addr/port only if changed */
+ if (!((addr == x->x_addr)&&(port == x->x_port)))
+ {
+ x->x_addr = addr;
+ x->x_port = port;
+ x->x_addrbytes[0].a_w.w_float = (x->x_addr & 0xFF000000)>>24;
+ x->x_addrbytes[1].a_w.w_float = (x->x_addr & 0x0FF0000)>>16;
+ x->x_addrbytes[2].a_w.w_float = (x->x_addr & 0x0FF00)>>8;
+ x->x_addrbytes[3].a_w.w_float = (x->x_addr & 0x0FF);
+ x->x_addrbytes[4].a_w.w_float = x->x_port;
+ outlet_list(x->x_addrout, &s_list, 5L, x->x_addrbytes);
+ }
+ if (ret <= 0) /* error */
{
if (0 == udpreceive_tilde_sockerror("recv tag")) return;
udpreceive_tilde_reset(x, 0);
@@ -468,22 +474,15 @@ static t_int *udpreceive_tilde_perform(t_int *w)
x->x_frameout++;
x->x_frameout %= DEFAULT_AUDIO_BUFFER_FRAMES;
}
- else
- {
- x->x_blockssincerecv++;
- }
+ else x->x_blockssincerecv++;
+ if (x->x_valid != 1) outlet_float(x->x_validout, 1);
return (w + offset + x->x_noutlets);
bail:
/* set output to zero */
- while (n--)
- {
- for (i = 0; i < x->x_noutlets; i++)
- {
- *(out[i]++) = 0.;
- }
- }
+ while (n--) for (i = 0; i < x->x_noutlets; i++) *(out[i]++) = 0.;
+ if (x->x_valid != 0) outlet_float(x->x_validout, 0);
return (w + offset + x->x_noutlets);
}
@@ -599,6 +598,7 @@ static void udpreceive_tilde_info(t_udpreceive_tilde *x)
SETFLOAT(list, (t_float)x->x_tag_errors);
outlet_anything(x->x_outlet2, ps_tag_errors, 1, list);
+ outlet_list(x->x_addrout, &s_list, 5L, x->x_addrbytes);
}
static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floatarg blocksize)
@@ -630,6 +630,9 @@ static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floa
x->x_addrbytes[i].a_type = A_FLOAT;
x->x_addrbytes[i].a_w.w_float = 0;
}
+ 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)
{
@@ -637,22 +640,17 @@ static void *udpreceive_tilde_new(t_floatarg fportno, t_floatarg outlets, t_floa
return NULL;
}
- x->x_connectsocket = -1;
- x->x_socket = -1;
- x->x_nconnections = 0;
- x->x_ndrops = 0;
- x->x_underflow = 0;
- x->x_overflow = 0;
+ x->x_connectsocket = x->x_socket = -1;
+ x->x_nconnections = x->x_underflow = x->x_overflow = 0;
x->x_hostname = ps_nothing;
/* 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_tag_errors = 0;
+
x->x_sync = 1;
- x->x_framein = 0;
- x->x_frameout = 0;
+ x->x_tag_errors = x->x_framein = x->x_frameout = x->x_valid = 0;
x->x_maxframes = DEFAULT_QUEUE_LENGTH;
x->x_vecsize = 64; /* we'll update this later */
if (blocksize == 0) x->x_blocksize = DEFAULT_AUDIO_BUFFER_SIZE;
diff --git a/net/udpsend~-help.pd b/net/udpsend~-help.pd
index e290928..d08675d 100644
--- a/net/udpsend~-help.pd
+++ b/net/udpsend~-help.pd
@@ -1,4 +1,4 @@
-#N canvas 415 49 838 769 10;
+#N canvas 415 49 859 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 34 650 print udpreceive~;
+#X obj 12 668 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 0
+#X obj -178 320 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 1
1;
#X symbolatom -97 435 10 0 0 0 - - -;
#X floatatom -44 369 5 0 0 0 - - -;
@@ -25,23 +25,23 @@
#X text -51 391 framesize:;
#X text 98 389 to:;
#X msg -216 242 info;
-#X symbolatom -311 717 10 0 0 0 - - -;
-#X floatatom -277 671 5 0 0 0 - - -;
-#X floatatom -242 650 7 0 0 0 - - -;
-#X floatatom -208 737 9 0 0 0 - - -;
-#X obj -311 693 prepend set;
-#X text -341 670 channels:;
-#X text -357 716 format:;
-#X text -257 736 bitrate:;
-#X text -306 649 framesize:;
-#X floatatom -173 672 9 0 0 0 - - -;
-#X floatatom -139 650 9 0 0 0 - - -;
-#X floatatom -104 693 5 0 0 0 - - -;
-#X floatatom -70 672 5 0 0 0 - - -;
-#X text -230 671 overflow:;
-#X text -199 649 underflow:;
-#X text -165 692 queuesize:;
-#X text -118 671 average:;
+#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 text -237 34 broadcast to everybody on your local subnet listening
on the specified port;
@@ -49,16 +49,16 @@ on the specified port;
#X text -410 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 -268 591 3 0 0 0 - - -;
-#X floatatom -245 591 3 0 0 0 - - -;
-#X floatatom -222 591 3 0 0 0 - - -;
-#X floatatom -199 591 3 0 0 0 - - -;
-#X floatatom -175 591 5 0 0 0 - - -;
-#X obj -268 565 unpack 0 0 0 0 0;
-#X text -305 590 from:;
+#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 obj -179 268 *~;
#X floatatom -164 150 5 0 0 0 - - -;
-#X text -19 178 Framesize = (blocksize) X (number of channels) X (bytes
+#X text -66 148 Framesize = (blocksize) X (number of channels) X (bytes
per sample);
#X obj -97 339 route format channels framesize bitrate ipaddr vecsize
;
@@ -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 0;
+-1 1;
#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 602 dac~ 1 2;
+#X obj -398 570 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 -35 715 9 0 0 0 - - -;
-#X text -87 714 packets:;
-#X text -20 204 Default blocksize is 2048 The number of samples per
+#X floatatom -57 733 9 0 0 0 - - -;
+#X text -109 732 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 -23 248 Arguments: (1st required \, 2nd optional) 1:number
+#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 -98 558 To communicate \, a [udpreceive~] and [udpsend~] pair
+#X text -43 560 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.
;
@@ -107,11 +107,14 @@ 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 -311 613 route format channels framesize bitrate overflow underflow
+#X obj -333 631 route format channels framesize bitrate overflow underflow
queuesize average packets tag_errors;
-#X floatatom -1 693 9 0 0 0 - - -;
-#X text -67 692 tag errors:;
-#X text -455 326 Author: Martin Peach 2010/03/11;
+#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 connect 0 0 54 0;
#X connect 1 0 62 0;
#X connect 2 0 62 0;
@@ -148,6 +151,7 @@ queuesize average packets tag_errors;
#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 68 0 69 0;
#X connect 69 0 62 1;
#X connect 70 0 54 1;
diff --git a/net/udpsend~.h b/net/udpsend~.h
index 99df7ee..43fa561 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.32"
+#define VERSION "0.33"
#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 */