Csound Csound-dev Csound-tekno Search About

Math tricks to round floats

Date2017-07-30 10:34
FromHlöðver Sigurðsson
SubjectMath tricks to round floats
Hey list, I'm trying out the new Ableton Link opcodes and I'm having problem rounding the metro phase values, so that I can fire events on specific times.

On ksmps=10 then for example, I never get 1.0000 rather

0.99509
0.99512
0.99514
1.00077
1.00092
1.00098

and for 0.25

0.02310
0.02312
0.02314
0.02990
0.02996
0.03003

I guess I need to round it to the lowest resolution, so that every number is divivdeable by 1/64. 
Tried someting like
    k_trigger, gk_beat, k_phase, k_time link_metro gi_peer, 4
    kphase = int(k_phase) + frac(k_phase)
Where I multiplied the frac, roudned it and divided again. But I'm just not "getting" this.

Also another challenge here is that an increase in ksmps quickly increases the chances of missing timestamps, wouldn't it make more sense to give the values of link_metro an audio-rate, or recommend setksmps=1?
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

Date2017-07-30 12:34
FromMichael Gogins
SubjectRe: Math tricks to round floats
Thanks for the information. I'll look into this and maybe make some changes.

Regards,
Mike

On Jul 30, 2017 5:34 AM, "Hlöðver Sigurðsson" <hlolli@gmail.com> wrote:
Hey list, I'm trying out the new Ableton Link opcodes and I'm having problem rounding the metro phase values, so that I can fire events on specific times.

On ksmps=10 then for example, I never get 1.0000 rather

0.99509
0.99512
0.99514
1.00077
1.00092
1.00098

and for 0.25

0.02310
0.02312
0.02314
0.02990
0.02996
0.03003

I guess I need to round it to the lowest resolution, so that every number is divivdeable by 1/64. 
Tried someting like
    k_trigger, gk_beat, k_phase, k_time link_metro gi_peer, 4
    kphase = int(k_phase) + frac(k_phase)
Where I multiplied the frac, roudned it and divided again. But I'm just not "getting" this.

Also another challenge here is that an increase in ksmps quickly increases the chances of missing timestamps, wouldn't it make more sense to give the values of link_metro an audio-rate, or recommend setksmps=1?
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

Date2017-07-30 12:48
FromHlöðver Sigurðsson
SubjectRe: Math tricks to round floats
Nice, thinking about this more, I think if one is cleaver with this tool, it would be possible to achieve relieable network triggering. Using phaseor and greater than operator for triggering, within csound just make sure the event isn't fired twice. In that case, audio rate isn't so important, but lower ksmps would just make it more accurate but never cause a miss.

2017-07-30 13:34 GMT+02:00 Michael Gogins <michael.gogins@gmail.com>:
Thanks for the information. I'll look into this and maybe make some changes.

Regards,
Mike

On Jul 30, 2017 5:34 AM, "Hlöðver Sigurðsson" <hlolli@gmail.com> wrote:
Hey list, I'm trying out the new Ableton Link opcodes and I'm having problem rounding the metro phase values, so that I can fire events on specific times.

On ksmps=10 then for example, I never get 1.0000 rather

0.99509
0.99512
0.99514
1.00077
1.00092
1.00098

and for 0.25

0.02310
0.02312
0.02314
0.02990
0.02996
0.03003

I guess I need to round it to the lowest resolution, so that every number is divivdeable by 1/64. 
Tried someting like
    k_trigger, gk_beat, k_phase, k_time link_metro gi_peer, 4
    kphase = int(k_phase) + frac(k_phase)
Where I multiplied the frac, roudned it and divided again. But I'm just not "getting" this.

Also another challenge here is that an increase in ksmps quickly increases the chances of missing timestamps, wouldn't it make more sense to give the values of link_metro an audio-rate, or recommend setksmps=1?
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

Date2017-07-30 15:03
FromSteven Yi
SubjectRe: Math tricks to round floats

Rather than search for an exact number you might try using a modulus and check the crossover by checking whether the current value is less than the previous value.


On Sun, Jul 30, 2017, 6:48 AM Hlöðver Sigurðsson <hlolli@gmail.com> wrote:
Nice, thinking about this more, I think if one is cleaver with this tool, it would be possible to achieve relieable network triggering. Using phaseor and greater than operator for triggering, within csound just make sure the event isn't fired twice. In that case, audio rate isn't so important, but lower ksmps would just make it more accurate but never cause a miss.

2017-07-30 13:34 GMT+02:00 Michael Gogins <michael.gogins@gmail.com>:
Thanks for the information. I'll look into this and maybe make some changes.

Regards,
Mike

On Jul 30, 2017 5:34 AM, "Hlöðver Sigurðsson" <hlolli@gmail.com> wrote:
Hey list, I'm trying out the new Ableton Link opcodes and I'm having problem rounding the metro phase values, so that I can fire events on specific times.

On ksmps=10 then for example, I never get 1.0000 rather

0.99509
0.99512
0.99514
1.00077
1.00092
1.00098

and for 0.25

0.02310
0.02312
0.02314
0.02990
0.02996
0.03003

I guess I need to round it to the lowest resolution, so that every number is divivdeable by 1/64. 
Tried someting like
    k_trigger, gk_beat, k_phase, k_time link_metro gi_peer, 4
    kphase = int(k_phase) + frac(k_phase)
Where I multiplied the frac, roudned it and divided again. But I'm just not "getting" this.

Also another challenge here is that an increase in ksmps quickly increases the chances of missing timestamps, wouldn't it make more sense to give the values of link_metro an audio-rate, or recommend setksmps=1?
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

Date2017-07-30 15:23
FromHlöðver Sigurðsson
SubjectRe: Math tricks to round floats
Yes, I think the crossover is the solution here. Different way to approach this than I'm used to from the past. And add some lock so make sure that an event isn't sent on every k-rate after the crossover returnes true. 

2017-07-30 16:03 GMT+02:00 Steven Yi <stevenyi@gmail.com>:

Rather than search for an exact number you might try using a modulus and check the crossover by checking whether the current value is less than the previous value.


On Sun, Jul 30, 2017, 6:48 AM Hlöðver Sigurðsson <hlolli@gmail.com> wrote:
Nice, thinking about this more, I think if one is cleaver with this tool, it would be possible to achieve relieable network triggering. Using phaseor and greater than operator for triggering, within csound just make sure the event isn't fired twice. In that case, audio rate isn't so important, but lower ksmps would just make it more accurate but never cause a miss.

2017-07-30 13:34 GMT+02:00 Michael Gogins <michael.gogins@gmail.com>:
Thanks for the information. I'll look into this and maybe make some changes.

Regards,
Mike

On Jul 30, 2017 5:34 AM, "Hlöðver Sigurðsson" <hlolli@gmail.com> wrote:
Hey list, I'm trying out the new Ableton Link opcodes and I'm having problem rounding the metro phase values, so that I can fire events on specific times.

On ksmps=10 then for example, I never get 1.0000 rather

0.99509
0.99512
0.99514
1.00077
1.00092
1.00098

and for 0.25

0.02310
0.02312
0.02314
0.02990
0.02996
0.03003

I guess I need to round it to the lowest resolution, so that every number is divivdeable by 1/64. 
Tried someting like
    k_trigger, gk_beat, k_phase, k_time link_metro gi_peer, 4
    kphase = int(k_phase) + frac(k_phase)
Where I multiplied the frac, roudned it and divided again. But I'm just not "getting" this.

Also another challenge here is that an increase in ksmps quickly increases the chances of missing timestamps, wouldn't it make more sense to give the values of link_metro an audio-rate, or recommend setksmps=1?
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

Date2017-07-30 15:43
FromTarmo Johannes
SubjectRe: Math tricks to round floats
 trigger opcode perhsps would be the easiest?

Tarmo

30.07.2017 17:23 kirjutas kuupäeval "Hlöðver Sigurðsson" <hlolli@gmail.com>:
Yes, I think the crossover is the solution here. Different way to approach this than I'm used to from the past. And add some lock so make sure that an event isn't sent on every k-rate after the crossover returnes true. 

2017-07-30 16:03 GMT+02:00 Steven Yi <stevenyi@gmail.com>:

Rather than search for an exact number you might try using a modulus and check the crossover by checking whether the current value is less than the previous value.


On Sun, Jul 30, 2017, 6:48 AM Hlöðver Sigurðsson <hlolli@gmail.com> wrote:
Nice, thinking about this more, I think if one is cleaver with this tool, it would be possible to achieve relieable network triggering. Using phaseor and greater than operator for triggering, within csound just make sure the event isn't fired twice. In that case, audio rate isn't so important, but lower ksmps would just make it more accurate but never cause a miss.

2017-07-30 13:34 GMT+02:00 Michael Gogins <michael.gogins@gmail.com>:
Thanks for the information. I'll look into this and maybe make some changes.

Regards,
Mike

On Jul 30, 2017 5:34 AM, "Hlöðver Sigurðsson" <hlolli@gmail.com> wrote:
Hey list, I'm trying out the new Ableton Link opcodes and I'm having problem rounding the metro phase values, so that I can fire events on specific times.

On ksmps=10 then for example, I never get 1.0000 rather

0.99509
0.99512
0.99514
1.00077
1.00092
1.00098

and for 0.25

0.02310
0.02312
0.02314
0.02990
0.02996
0.03003

I guess I need to round it to the lowest resolution, so that every number is divivdeable by 1/64. 
Tried someting like
    k_trigger, gk_beat, k_phase, k_time link_metro gi_peer, 4
    kphase = int(k_phase) + frac(k_phase)
Where I multiplied the frac, roudned it and divided again. But I'm just not "getting" this.

Also another challenge here is that an increase in ksmps quickly increases the chances of missing timestamps, wouldn't it make more sense to give the values of link_metro an audio-rate, or recommend setksmps=1?
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