question about SerialWrite
Date | 2016-12-11 15:16 |
From | Richard |
Subject | question about SerialWrite |
I do not understand the example given with SerialWrite:
aSig in ;get our audio input and get its rms kRms rms aSig*kGain kRms = kRms*kRms*255 ;scale the rms to a good value for the LED and send it out serialWrite iPort, (kRms < 255 ? kRms : 255) ;must be in range: 0-255 |
Date | 2016-12-11 15:24 |
From | John ff |
Subject | Re: question about SerialWrite |
I do not understand. kRms could be anything so checking that it is in range seems sane. Or have I misunderstood?
Sent from TypeApp
On 11 Dec 2016, at 15:17, Richard <zappfinger@GMAIL.COM> wrote:
|
Date | 2016-12-11 15:31 |
From | Richard |
Subject | Re: question about SerialWrite |
As I print kRms, it is a float. I understood that all csound k
and a variables are a float. Csound always works with numbers which are not integers (to represent a 1, Csound actually uses 1.0). On 11/12/16 16:24, John ff wrote:
|
Date | 2016-12-11 15:33 |
From | Dave Seidel |
Subject | Re: question about SerialWrite |
I think the point here is not the data type as much as scaling the value to fall within a reasonable range. On Sun, Dec 11, 2016 at 10:31 AM, Richard <zappfinger@gmail.com> wrote:
|
Date | 2016-12-11 15:36 |
From | Richard |
Subject | Re: question about SerialWrite |
I understand that, but a float between 0 and 255 is not the same
as an integer (or byte) within that range. On 11/12/16 16:33, Dave Seidel wrote:
|
Date | 2016-12-11 15:49 |
From | Richard |
Subject | Re: question about SerialWrite |
Or to put it differently: how and where does the kRms value (a float as far as I can see) get converted to a byte? On 11/12/16 16:33, Dave Seidel wrote:
|
Date | 2016-12-11 15:52 |
From | Victor Lazzarini |
Subject | Re: question about SerialWrite |
inside the opcode, I would guess. A simple cast.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2016-12-11 15:59 |
From | Steven Yi |
Subject | Re: question about SerialWrite |
I think there's a disconect here. Within Csound, the values are floats/doubles. When serialWrite operates, it casts the value to a byte (unsigned char), then writes the byte to the serial out. serialRead also reads a byte from the port, then converts it to a float/double. On Sun, Dec 11, 2016 at 10:36 AM, Richard |
Date | 2016-12-11 16:13 |
From | Richard |
Subject | Re: question about SerialWrite |
Ok, makes sense, but then the documentation is confusing, it says serialWrite iPort, iByte
serialWrite iPort, kByte
serialWrite iPort, SBytes
And as far as I know Csound has no byte type. What it should say he second argument a 'i' or 'k' type, knowing that it is a float that gets converted internally. Richard On 11/12/16 16:59, Steven Yi wrote:
I think there's a disconect here. Within Csound, the values are floats/doubles. When serialWrite operates, it casts the value to a byte (unsigned char), then writes the byte to the serial out. serialRead also reads a byte from the port, then converts it to a float/double. On Sun, Dec 11, 2016 at 10:36 AM, Richard <zappfinger@gmail.com> wrote:I understand that, but a float between 0 and 255 is not the same as an integer (or byte) within that range. On 11/12/16 16:33, Dave Seidel wrote: I think the point here is not the data type as much as scaling the value to fall within a reasonable range. On Sun, Dec 11, 2016 at 10:31 AM, Richard <zappfinger@gmail.com> wrote:As I print kRms, it is a float. I understood that all csound k and a variables are a float. So it says in the floss article about python inside csound: Csound always works with numbers which are not integers (to represent a 1, Csound actually uses 1.0). On 11/12/16 16:24, John ff wrote: I do not understand. kRms could be anything so checking that it is in range seems sane. Or have I misunderstood? Sent from TypeApp On 11 Dec 2016, at 15:17, Richard <zappfinger@GMAIL.COM> wrote:I do not understand the example given with SerialWrite: Since all csound variables are floats (if I understand correctly), how can kRms ever be different from a float? The corresponding Arduino code Serial.Read() returns a byte.. aSig in ;get our audio input and get its rms kRms rms aSig*kGain kRms = kRms*kRms*255 ;scale the rms to a good value for the LED and send it out serialWrite iPort, (kRms < 255 ? kRms : 255) ;must be in range: 0-255 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 hereCsound 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 hereCsound 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 hereCsound 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 |
Date | 2016-12-11 16:15 |
From | Victor Lazzarini |
Subject | Re: question about SerialWrite |
it is just the variable name, not a type.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
Date | 2016-12-11 16:26 |
From | Richard |
Subject | Re: question about SerialWrite |
Yes, I know, but it suggests a type... On 11/12/16 17:15, Victor Lazzarini
wrote:
|
Date | 2016-12-11 17:00 |
From | Steven Yi |
Subject | Re: question about SerialWrite |
For what it's worth, I don't think the documentation is confusing nor suggests a type. All of csound's variables (prior to CS7) use the first letter to denote type, which is what the documentation shows. Are you suggesting something else, like the documentation should say "ival, kval, Sval" instead? On Sun, Dec 11, 2016 at 11:26 AM, Richard |
Date | 2016-12-11 17:01 |
From | jpff |
Subject | Re: question about SerialWrite |
Yes but what is your point? All i, k, a, f variables are floating point. Cannot see how your example relates On Sun, 11 Dec 2016, Richard wrote: > > As I print kRms, it is a float. I understood that all csound k and a variables > are a float. > So it says in the floss article about python inside csound: > > Csound always works with numbers which are not integers (to represent a 1, > Csound actually uses 1.0). > > > On 11/12/16 16:24, John ff wrote: > I do not understand. kRms could be anything so checking that it > is in range seems sane. Or have I misunderstood? > > Sent from TypeApp > On 11 Dec 2016, at 15:17, Richard |
Date | 2016-12-11 17:37 |
From | Richard |
Subject | Re: question about SerialWrite |
Never mind, I was just confused by the kByte variable name... On 11/12/16 18:01, jpff wrote: > Yes but what is your point? All i, k, a, f variables are floating > point. Cannot see how your example relates > > > On Sun, 11 Dec 2016, Richard wrote: > >> >> As I print kRms, it is a float. I understood that all csound k and a >> variables >> are a float. >> So it says in the floss article about python inside csound: >> >> Csound always works with numbers which are not integers (to represent >> a 1, >> Csound actually uses 1.0). >> >> >> On 11/12/16 16:24, John ff wrote: >> I do not understand. kRms could be anything so checking that it >> is in range seems sane. Or have I misunderstood? >> >> Sent from TypeApp >> On 11 Dec 2016, at 15:17, Richard |
Date | 2016-12-11 17:44 |
From | Rory Walsh |
Subject | Re: question about SerialWrite |
I believe you have a point. On 11 December 2016 at 17:37, Richard <zappfinger@gmail.com> wrote: Never mind, I was just confused by the kByte variable name... |
Date | 2016-12-11 20:15 |
From | Paul Batchelor |
Subject | Re: question about SerialWrite |
I've recently glanced at the source code for this, and it does provide clarification (yay open source). This is the actual line that does the writing, which is just a standard write call for anything non-windows: The "kByte" variable name refers to the fact that you are writing a serial message one byte at a time, which would imply the 0-255 range. By the way, this opcode is an amazing reference for anyone interested in reading/writing serial from C on Linux. Really really glad it existed for me this quarter! Cheers, -P On Sun, Dec 11, 2016 at 9:44 AM, Rory Walsh <rorywalsh@ear.ie> wrote:
|