Csound Csound-dev Csound-tekno Search About

[Csnd] Csound websocket increasingly slow

Date2018-04-08 17:31
FromRichard
Subject[Csnd] Csound websocket increasingly slow

I'm trying the csound websocket example (http://www.csounds.com/manual/html/websocket.html) with p5js. 3 simple sliders for R,G,B control. Only the Red slider is used to connect to Csound.
The output of

printk2 kinput

gets slower each time I move the slider, as if something is filling a buffer or so.
I have included the source files. (I run a node.js server), but any http server could be used.

Could not send the files. Try to paste them in the mail.

Here is sketch.js:


var rSlider, gSlider, bSlider;
//var websocketIn = new WebSocket("ws://127.0.0.1:8888", "klfo");
//var websocketOut = new WebSocket("ws://127.0.0.1:8888", "kinput");

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connected = false;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection established!");
    connected = true;
}

function setup() {
  // create canvas
  createCanvas(710, 400);
  textSize(15);
  noStroke();

  // create sliders
  rSlider = createSlider(0, 255, 100);
  rSlider.position(20, 20);
  gSlider = createSlider(0, 255, 0);
  gSlider.position(20, 50);
  bSlider = createSlider(0, 255, 255);
  bSlider.position(20, 80);
}

function draw() {
  //var prevR = 0;
  var r = rSlider.value();
  var g = gSlider.value();
  var b = bSlider.value();
  background(r, g, b);
  text("red", rSlider.x * 2 + rSlider.width, 35);
  //if (connected && prevR!=r) {
  //    connOut.send(new Float64Array([r]));
  //    prevR  = r;
  //}
  if (connected) connOut.send(new Float64Array([r]));
  text("green", gSlider.x * 2 + gSlider.width, 65);
  text("blue", bSlider.x * 2 + bSlider.width, 95);
}

Here is index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>boxes</title>
    <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>

    <script src="libraries/p5.js" type="text/javascript"></script>

    <script src="libraries/p5.dom.js" type="text/javascript"></script>
    <script src="libraries/p5.sound.js" type="text/javascript"></script>

    <script src="sketch.js" type="text/javascript"></script>

    <style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
  </head>
  <body>
  </body>
</html>



Richard


Date2018-04-08 18:17
Fromzappfinger
SubjectRe: [Csnd] Csound websocket increasingly slow
BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2018-04-12 18:02
FromEdward Costello
SubjectRe: [Csnd] Csound websocket increasingly slow
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

> On 8 Apr 2018, at 18:17, zappfinger  wrote:
> 
> BTW, more or less the same behaviour with the original csd and html file from
> the example. After a few changes to the slider it stops updating the csd...
> 
> 
> 
> 
> --
> Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2018-04-12 18:59
FromRichard
SubjectRe: [Csnd] Csound websocket increasingly slow

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here


Date2018-04-12 19:05
FromEdward Costello
SubjectRe: [Csnd] Csound websocket increasingly slow
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2018-04-12 20:54
FromRichard
SubjectRe: [Csnd] Csound websocket increasingly slow

I would have to give that a try.


On 12/04/18 20:05, Edward Costello wrote:
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2018-04-15 10:58
FromRichard
SubjectRe: [Csnd] Csound websocket increasingly slow

Sorry for the confusion, but I WAS using websocket already in my code. The problem is solved when I only send the changes, see the comments in the code below.
BTW, I understand that socket.io is a wrapper for websocket, so that should not make a difference.

One thing I do not understand: the second argument in creating a websocket is reserved for the protocol, but in your websocket.html example it is used for the channel, how can this work?

var websocketIn = new WebSocket("ws://127.0.0.1:8888", "klfo");
var websocketOut = new WebSocket("ws://127.0.0.1:8888", "kinput");


Here is my code that works (sketch.js):


var rSlider, gSlider, bSlider;

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connected = false;
var prevR = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection established!");
    connected = true;
}

function setup() {
  // create canvas
  createCanvas(710, 400);
  textSize(15);
  noStroke();

  // create sliders
  rSlider = createSlider(0, 255, 100);
  rSlider.position(20, 20);
  gSlider = createSlider(0, 255, 0);
  gSlider.position(20, 50);
  bSlider = createSlider(0, 255, 255);
  bSlider.position(20, 80);
}

function draw() {
  //var prevR = 0;
  var r = rSlider.value();
  var g = gSlider.value();
  var b = bSlider.value();
  background(r, g, b);
  text("red", rSlider.x * 2 + rSlider.width, 35);
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  //
  // commenting the above if and uncommenting the next if will show the 'problem'
  //
  //if (connected) connOut.send(new Float64Array([r]));
 
 
  text("green", gSlider.x * 2 + gSlider.width, 65);
  text("blue", bSlider.x * 2 + bSlider.width, 95);
}


Richard



On 12/04/18 20:05, Edward Costello wrote:
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2018-04-16 10:57
FromEdward Costello
SubjectRe: [Csnd] Csound websocket increasingly slow
I think I’m making a different protocol for each variable which in retrospect might be the problem. How is it with just one variable?
Ed

On 15 Apr 2018, at 10:58, Richard <zappfinger@GMAIL.COM> wrote:

Sorry for the confusion, but I WAS using websocket already in my code. The problem is solved when I only send the changes, see the comments in the code below.
BTW, I understand that socket.io is a wrapper for websocket, so that should not make a difference.

One thing I do not understand: the second argument in creating a websocket is reserved for the protocol, but in your websocket.html example it is used for the channel, how can this work?

var websocketIn = new WebSocket("ws://127.0.0.1:8888", "klfo");
var websocketOut = new WebSocket("ws://127.0.0.1:8888", "kinput");


Here is my code that works (sketch.js):


var rSlider, gSlider, bSlider;

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connected = false;
var prevR = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection established!");
    connected = true;
}

function setup() {
  // create canvas
  createCanvas(710, 400);
  textSize(15);
  noStroke();

  // create sliders
  rSlider = createSlider(0, 255, 100);
  rSlider.position(20, 20);
  gSlider = createSlider(0, 255, 0);
  gSlider.position(20, 50);
  bSlider = createSlider(0, 255, 255);
  bSlider.position(20, 80);
}

function draw() {
  //var prevR = 0;
  var r = rSlider.value();
  var g = gSlider.value();
  var b = bSlider.value();
  background(r, g, b);
  text("red", rSlider.x * 2 + rSlider.width, 35);
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  //
  // commenting the above if and uncommenting the next if will show the 'problem'
  //
  //if (connected) connOut.send(new Float64Array([r]));
 
 
  text("green", gSlider.x * 2 + gSlider.width, 65);
  text("blue", bSlider.x * 2 + bSlider.width, 95);
}


Richard



On 12/04/18 20:05, Edward Costello wrote:
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2018-04-21 08:26
FromRichard
SubjectRe: [Csnd] Csound websocket increasingly slow

I was just using one variable, but as I said the problem is gone when I only send data when the slider changes. It goes wrong when I send (the same) data too fast.

BTW, I tried it with 2 variables now, works fine. In my javascript I use 2 connections like this:

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connOut2 = new WebSocket("ws://127.0.0.1:8888", "kinput2");
var connected = false;
var connected2 = false;
var prevR = 0;
var prevG = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection to connOut established!");
    connected = true;
}
connOut2.onmessage = function(e) { console.log(e.data); };
connOut2.onopen = function(e) {
    console.log("Connection to connOut2 established!");
    connected2 = true;
}

Then, in order not to overflow the data, I have to use the following:

function draw() {
  var r = vslids[0].value();
  var g = vslids[1].value();
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  if (connected2 && prevG!=g) {
      connOut2.send(new Float64Array([g]));
      prevG  = g;
  }

BTW2, the websocket example is a bit confusing, since the syntax is:

xout1[, xout2, xout3, ..., xoutN] websocket iport, xin1[, xin2, xin3, ..., xinN]

But in the example csd you use:
    kinput websocket iport, klfo
    printk2 kinput

kinput is actually an output?

On 16/04/18 11:57, Edward Costello wrote:
I think I’m making a different protocol for each variable which in retrospect might be the problem. How is it with just one variable?
Ed

On 15 Apr 2018, at 10:58, Richard <zappfinger@GMAIL.COM> wrote:

Sorry for the confusion, but I WAS using websocket already in my code. The problem is solved when I only send the changes, see the comments in the code below.
BTW, I understand that socket.io is a wrapper for websocket, so that should not make a difference.

One thing I do not understand: the second argument in creating a websocket is reserved for the protocol, but in your websocket.html example it is used for the channel, how can this work?

var websocketIn = new WebSocket("ws://127.0.0.1:8888", "klfo");
var websocketOut = new WebSocket("ws://127.0.0.1:8888", "kinput");


Here is my code that works (sketch.js):


var rSlider, gSlider, bSlider;

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connected = false;
var prevR = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection established!");
    connected = true;
}

function setup() {
  // create canvas
  createCanvas(710, 400);
  textSize(15);
  noStroke();

  // create sliders
  rSlider = createSlider(0, 255, 100);
  rSlider.position(20, 20);
  gSlider = createSlider(0, 255, 0);
  gSlider.position(20, 50);
  bSlider = createSlider(0, 255, 255);
  bSlider.position(20, 80);
}

function draw() {
  //var prevR = 0;
  var r = rSlider.value();
  var g = gSlider.value();
  var b = bSlider.value();
  background(r, g, b);
  text("red", rSlider.x * 2 + rSlider.width, 35);
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  //
  // commenting the above if and uncommenting the next if will show the 'problem'
  //
  //if (connected) connOut.send(new Float64Array([r]));
 
 
  text("green", gSlider.x * 2 + gSlider.width, 65);
  text("blue", bSlider.x * 2 + bSlider.width, 95);
}


Richard



On 12/04/18 20:05, Edward Costello wrote:
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Date2018-04-21 11:54
FromMichael Gogins
SubjectRe: [Csnd] Csound websocket increasingly slow
Yes.

On Sat, Apr 21, 2018, 03:26 Richard <zappfinger@gmail.com> wrote:

I was just using one variable, but as I said the problem is gone when I only send data when the slider changes. It goes wrong when I send (the same) data too fast.

BTW, I tried it with 2 variables now, works fine. In my javascript I use 2 connections like this:

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connOut2 = new WebSocket("ws://127.0.0.1:8888", "kinput2");
var connected = false;
var connected2 = false;
var prevR = 0;
var prevG = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection to connOut established!");
    connected = true;
}
connOut2.onmessage = function(e) { console.log(e.data); };
connOut2.onopen = function(e) {
    console.log("Connection to connOut2 established!");
    connected2 = true;
}

Then, in order not to overflow the data, I have to use the following:

function draw() {
  var r = vslids[0].value();
  var g = vslids[1].value();
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  if (connected2 && prevG!=g) {
      connOut2.send(new Float64Array([g]));
      prevG  = g;
  }

BTW2, the websocket example is a bit confusing, since the syntax is:

xout1[, xout2, xout3, ..., xoutN] websocket iport, xin1[, xin2, xin3, ..., xinN]

But in the example csd you use:
    kinput websocket iport, klfo
    printk2 kinput

kinput is actually an output?

On 16/04/18 11:57, Edward Costello wrote:
I think I’m making a different protocol for each variable which in retrospect might be the problem. How is it with just one variable?
Ed

On 15 Apr 2018, at 10:58, Richard <zappfinger@GMAIL.COM> wrote:

Sorry for the confusion, but I WAS using websocket already in my code. The problem is solved when I only send the changes, see the comments in the code below.
BTW, I understand that socket.io is a wrapper for websocket, so that should not make a difference.

One thing I do not understand: the second argument in creating a websocket is reserved for the protocol, but in your websocket.html example it is used for the channel, how can this work?

var websocketIn = new WebSocket("ws://127.0.0.1:8888", "klfo");
var websocketOut = new WebSocket("ws://127.0.0.1:8888", "kinput");


Here is my code that works (sketch.js):


var rSlider, gSlider, bSlider;

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connected = false;
var prevR = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection established!");
    connected = true;
}

function setup() {
  // create canvas
  createCanvas(710, 400);
  textSize(15);
  noStroke();

  // create sliders
  rSlider = createSlider(0, 255, 100);
  rSlider.position(20, 20);
  gSlider = createSlider(0, 255, 0);
  gSlider.position(20, 50);
  bSlider = createSlider(0, 255, 255);
  bSlider.position(20, 80);
}

function draw() {
  //var prevR = 0;
  var r = rSlider.value();
  var g = gSlider.value();
  var b = bSlider.value();
  background(r, g, b);
  text("red", rSlider.x * 2 + rSlider.width, 35);
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  //
  // commenting the above if and uncommenting the next if will show the 'problem'
  //
  //if (connected) connOut.send(new Float64Array([r]));
 
 
  text("green", gSlider.x * 2 + gSlider.width, 65);
  text("blue", bSlider.x * 2 + bSlider.width, 95);
}


Richard



On 12/04/18 20:05, Edward Costello wrote:
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2018-04-21 12:39
FromRichard
SubjectRe: [Csnd] Csound websocket increasingly slow

I know, it was more a rhetorical question... ;-)

BTW, for anyone who's interested: I created a vertical slider from p5js horizontal slider by rotating and translating it.
This one also has a label underneath and the value showing above the slider:

function Vslider(x,y, txt, min,max,deft){
  this.slid = createSlider(min, max, deft);
  this.slid.position(x, y);
  this.slid.style('rotate', -90);
  this.slid.style('translate', -40, 80);
  //
  text(txt, x+15, y+170);
  fill(50);
  this.value = function() {
    fill(50);
    rect(x+10, y, 40, 20);
    fill(150);
    text(this.slid.value(), x+15, y+15);
    return this.slid.value();
  };
}

You can use it like this in setup():

  // create sliders
  vslids[0] = new Vslider(20,10, "att", 0, 100, 10);
  vslids[1] = new Vslider(60,10, "dec", 0, 255, 100);

create a global vslids array outside of setup() or draw():
var vslids = [];

Richard

On 21/04/18 12:54, Michael Gogins wrote:
Yes.

On Sat, Apr 21, 2018, 03:26 Richard <zappfinger@gmail.com> wrote:

I was just using one variable, but as I said the problem is gone when I only send data when the slider changes. It goes wrong when I send (the same) data too fast.

BTW, I tried it with 2 variables now, works fine. In my javascript I use 2 connections like this:

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connOut2 = new WebSocket("ws://127.0.0.1:8888", "kinput2");
var connected = false;
var connected2 = false;
var prevR = 0;
var prevG = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection to connOut established!");
    connected = true;
}
connOut2.onmessage = function(e) { console.log(e.data); };
connOut2.onopen = function(e) {
    console.log("Connection to connOut2 established!");
    connected2 = true;
}

Then, in order not to overflow the data, I have to use the following:

function draw() {
  var r = vslids[0].value();
  var g = vslids[1].value();
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  if (connected2 && prevG!=g) {
      connOut2.send(new Float64Array([g]));
      prevG  = g;
  }

BTW2, the websocket example is a bit confusing, since the syntax is:

xout1[, xout2, xout3, ..., xoutN] websocket iport, xin1[, xin2, xin3, ..., xinN]

But in the example csd you use:
    kinput websocket iport, klfo
    printk2 kinput

kinput is actually an output?

On 16/04/18 11:57, Edward Costello wrote:
I think I’m making a different protocol for each variable which in retrospect might be the problem. How is it with just one variable?
Ed

On 15 Apr 2018, at 10:58, Richard <zappfinger@GMAIL.COM> wrote:

Sorry for the confusion, but I WAS using websocket already in my code. The problem is solved when I only send the changes, see the comments in the code below.
BTW, I understand that socket.io is a wrapper for websocket, so that should not make a difference.

One thing I do not understand: the second argument in creating a websocket is reserved for the protocol, but in your websocket.html example it is used for the channel, how can this work?

var websocketIn = new WebSocket("ws://127.0.0.1:8888", "klfo");
var websocketOut = new WebSocket("ws://127.0.0.1:8888", "kinput");


Here is my code that works (sketch.js):


var rSlider, gSlider, bSlider;

var connOut = new WebSocket("ws://127.0.0.1:8888", "kinput");
var connected = false;
var prevR = 0;
connOut.onmessage = function(e) { console.log(e.data); };
connOut.onopen = function(e) {
    console.log("Connection established!");
    connected = true;
}

function setup() {
  // create canvas
  createCanvas(710, 400);
  textSize(15);
  noStroke();

  // create sliders
  rSlider = createSlider(0, 255, 100);
  rSlider.position(20, 20);
  gSlider = createSlider(0, 255, 0);
  gSlider.position(20, 50);
  bSlider = createSlider(0, 255, 255);
  bSlider.position(20, 80);
}

function draw() {
  //var prevR = 0;
  var r = rSlider.value();
  var g = gSlider.value();
  var b = bSlider.value();
  background(r, g, b);
  text("red", rSlider.x * 2 + rSlider.width, 35);
  if (connected && prevR!=r) {
      connOut.send(new Float64Array([r]));
      prevR  = r;
  }
  //
  // commenting the above if and uncommenting the next if will show the 'problem'
  //
  //if (connected) connOut.send(new Float64Array([r]));
 
 
  text("green", gSlider.x * 2 + gSlider.width, 65);
  text("blue", bSlider.x * 2 + bSlider.width, 95);
}


Richard



On 12/04/18 20:05, Edward Costello wrote:
Do you need to use socket.io? Would it be possible to test just using the native javascript Websocket object like in the manual example? Might help isolate the problem.
Ed

On 12 Apr 2018, at 18:59, Richard <zappfinger@GMAIL.COM> wrote:

In retrospect, your example csd and html file seems to work. I only have a problem with the attached example in p5js.
That is using the following websocket version:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


I'm on Mac OS X 10.10.5 The problem occurs in Chrome Version 65.0.3325.181
and in Firefox 56.0.2

I thought maybe it was a flaw in my code (sending too much data), so I also tried sending only when the slider value changes, but the result is the same.

Richard

On 12/04/18 19:02, Edward Costello wrote:
I built Csound with libwebsocket 1.0.2o_1 and I’m not seeing any issues. I’ve tested with Chrome 65 on macOS 10.13.3. What system are you using?
Ed

On 8 Apr 2018, at 18:17, zappfinger <zappfinger@GMAIL.COM> wrote:

BTW, more or less the same behaviour with the original csd and html file from
the example. After a few changes to the slider it stops updating the csd...




--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
       https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here