[Csnd] maparray with UDO

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd] maparray with UDO

Oeyvind Brandtsegg-3
Hi,
I'm trying to limit the values in an array to a specific range (0 to 1 in my case).
I thought maybe I could use maparray, and since I can only use functions with one argument I thought I could try making a UDO of limit with preset values for the uper and lower limit.
It seems maparray won't accept UDOs as functions.
Is there another way to limit the range of values in an array (and otherwise not changing the values inside the allowed range.

Here's my UDO based attempt, which gives
INIT ERROR in instr 2: lim not found
kArr1   maparray.k      kArr    "lim"

***
opcode lim,k,k
        k1 xin 
        xout limit(k1,0,1)
        endop
        
instr 2
kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
kArr1[] maparray kArr, "lim"
kmax maxarray kArr1
printk2 kmax
endin
***

I also tried using "tanh" which sort of could work, but of course it warps the values inside the allowed range and I would prefer to have the option of keeping them linear up to the selected limit.

Is there another approach that I could use?
Any formulas based on the allowed operations on arrays that could make the trick?

--
Csound mailing list [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

rorywalsh
Can you not create a UDO that simply takes one array as input and outputs another, limiting values between 0 and 1? 

On 20 April 2017 at 07:14, Oeyvind Brandtsegg <[hidden email]> wrote:
Hi,
I'm trying to limit the values in an array to a specific range (0 to 1 in my case).
I thought maybe I could use maparray, and since I can only use functions with one argument I thought I could try making a UDO of limit with preset values for the uper and lower limit.
It seems maparray won't accept UDOs as functions.
Is there another way to limit the range of values in an array (and otherwise not changing the values inside the allowed range.

Here's my UDO based attempt, which gives
INIT ERROR in instr 2: lim not found
kArr1   maparray.k      kArr    "lim"

***
opcode lim,k,k
        k1 xin 
        xout limit(k1,0,1)
        endop
        
instr 2
kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
kArr1[] maparray kArr, "lim"
kmax maxarray kArr1
printk2 kmax
endin
***

I also tried using "tanh" which sort of could work, but of course it warps the values inside the allowed range and I would prefer to have the option of keeping them linear up to the selected limit.

Is there another approach that I could use?
Any formulas based on the allowed operations on arrays that could make the trick?

--
Csound mailing list [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

gsenna
Don't UDOs pass by value? Wouldn't that be copying the entire array
twice with that strategy?


On 20/04/17 06:15, Rory Walsh wrote:

> Can you not create a UDO that simply takes one array as input and outputs
> another, limiting values between 0 and 1?
>
> On 20 April 2017 at 07:14, Oeyvind Brandtsegg <[hidden email]>
> wrote:
>
>> Hi,
>> I'm trying to limit the values in an array to a specific range (0 to 1 in
>> my case).
>> I thought maybe I could use maparray, and since I can only use functions
>> with one argument I thought I could try making a UDO of limit with preset
>> values for the uper and lower limit.
>> It seems maparray won't accept UDOs as functions.
>> Is there another way to limit the range of values in an array (and
>> otherwise not changing the values inside the allowed range.
>>
>> Here's my UDO based attempt, which gives
>> INIT ERROR in instr 2: lim not found
>> kArr1   maparray.k      kArr    "lim"
>>
>> ***
>> opcode lim,k,k
>>         k1 xin
>>         xout limit(k1,0,1)
>>         endop
>>
>> instr 2
>> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> kArr1[] maparray kArr, "lim"
>> kmax maxarray kArr1
>> printk2 kmax
>> endin
>> ***
>>
>> I also tried using "tanh" which sort of could work, but of course it warps
>> the values inside the allowed range and I would prefer to have the option
>> of keeping them linear up to the selected limit.
>>
>> Is there another approach that I could use?
>> Any formulas based on the allowed operations on arrays that could make the
>> trick?
>>
>> --
>>
>> Oeyvind Brandtsegg
>> Professor of Music Technology
>> NTNU
>> 7491 Trondheim
>> Norway
>> Cell: +47 92 203 205
>>
>> http://www.partikkelaudio.com/
>> http://crossadaptive.hf.ntnu.no
>> http://gdsp.hf.ntnu.no/
>> http://soundcloud.com/brandtsegg
>> http://flyndresang.no/
>> http://soundcloud.com/t-emp
>>
>> Csound mailing list [hidden email] 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
> [hidden email]
> 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
[hidden email]
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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

rorywalsh
And it would also be doing a value by value copy on each k-pass, which is probably something Oeyvind is trying to avoid I guess..

On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
Don't UDOs pass by value? Wouldn't that be copying the entire array
twice with that strategy?


On 20/04/17 06:15, Rory Walsh wrote:
> Can you not create a UDO that simply takes one array as input and outputs
> another, limiting values between 0 and 1?
>
> On 20 April 2017 at 07:14, Oeyvind Brandtsegg <[hidden email]>
> wrote:
>
>> Hi,
>> I'm trying to limit the values in an array to a specific range (0 to 1 in
>> my case).
>> I thought maybe I could use maparray, and since I can only use functions
>> with one argument I thought I could try making a UDO of limit with preset
>> values for the uper and lower limit.
>> It seems maparray won't accept UDOs as functions.
>> Is there another way to limit the range of values in an array (and
>> otherwise not changing the values inside the allowed range.
>>
>> Here's my UDO based attempt, which gives
>> INIT ERROR in instr 2: lim not found
>> kArr1   maparray.k      kArr    "lim"
>>
>> ***
>> opcode lim,k,k
>>         k1 xin
>>         xout limit(k1,0,1)
>>         endop
>>
>> instr 2
>> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> kArr1[] maparray kArr, "lim"
>> kmax maxarray kArr1
>> printk2 kmax
>> endin
>> ***
>>
>> I also tried using "tanh" which sort of could work, but of course it warps
>> the values inside the allowed range and I would prefer to have the option
>> of keeping them linear up to the selected limit.
>>
>> Is there another approach that I could use?
>> Any formulas based on the allowed operations on arrays that could make the
>> trick?
>>
>> --
>>
>> Oeyvind Brandtsegg
>> Professor of Music Technology
>> NTNU
>> 7491 Trondheim
>> Norway
>> Cell: +47 92 203 205
>>
>> http://www.partikkelaudio.com/
>> http://crossadaptive.hf.ntnu.no
>> http://gdsp.hf.ntnu.no/
>> http://soundcloud.com/brandtsegg
>> http://flyndresang.no/
>> http://soundcloud.com/t-emp
>>
>> Csound mailing list [hidden email] 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
> [hidden email]
> 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
[hidden email]
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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

thorin kerr
vlimit works on tables.... so... here's an approach. 
I have no idea how expensve this is.

instr 2
kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
ilen lenarray kArr
i_farr ftgentmp 0,0,-ilen,-2,0
copya2ftab kArr, i_farr
vlimit i_farr, 0,1,ilen
kresult[] init ilen
copyf2array kresult, i_farr
kmax maxarray kresult
printk2 kmax
endin


On 20 Apr 2017 11:47 PM, "Rory Walsh" <[hidden email]> wrote:
And it would also be doing a value by value copy on each k-pass, which is probably something Oeyvind is trying to avoid I guess..

On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
Don't UDOs pass by value? Wouldn't that be copying the entire array
twice with that strategy?


On 20/04/17 06:15, Rory Walsh wrote:
> Can you not create a UDO that simply takes one array as input and outputs
> another, limiting values between 0 and 1?
>
> On 20 April 2017 at 07:14, Oeyvind Brandtsegg <[hidden email]>
> wrote:
>
>> Hi,
>> I'm trying to limit the values in an array to a specific range (0 to 1 in
>> my case).
>> I thought maybe I could use maparray, and since I can only use functions
>> with one argument I thought I could try making a UDO of limit with preset
>> values for the uper and lower limit.
>> It seems maparray won't accept UDOs as functions.
>> Is there another way to limit the range of values in an array (and
>> otherwise not changing the values inside the allowed range.
>>
>> Here's my UDO based attempt, which gives
>> INIT ERROR in instr 2: lim not found
>> kArr1   maparray.k      kArr    "lim"
>>
>> ***
>> opcode lim,k,k
>>         k1 xin
>>         xout limit(k1,0,1)
>>         endop
>>
>> instr 2
>> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> kArr1[] maparray kArr, "lim"
>> kmax maxarray kArr1
>> printk2 kmax
>> endin
>> ***
>>
>> I also tried using "tanh" which sort of could work, but of course it warps
>> the values inside the allowed range and I would prefer to have the option
>> of keeping them linear up to the selected limit.
>>
>> Is there another approach that I could use?
>> Any formulas based on the allowed operations on arrays that could make the
>> trick?
>>
>> --
>>
>> Oeyvind Brandtsegg
>> Professor of Music Technology
>> NTNU
>> 7491 Trondheim
>> Norway
>> Cell: +47 92 203 205
>>
>> http://www.partikkelaudio.com/
>> http://crossadaptive.hf.ntnu.no
>> http://gdsp.hf.ntnu.no/
>> http://soundcloud.com/brandtsegg
>> http://flyndresang.no/
>> http://soundcloud.com/t-emp
>>
>> Csound mailing list [hidden email] 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
> [hidden email]
> 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
[hidden email]
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 [hidden email] 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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

Steven Yi
I think a more robust map function would be great, but until then, the
issues raised about pass-by-value are correct and there would be a
cost there to memcpy() data back and forth.

I think with what's in Csound at the moment, the solution with the
balance of performance and ease is to use a loop to process and to use
to a macro to make it a one-liner. I tried the following and it seems
to work here:

<CsoundSynthesizer>
<CsInstruments>

sr=44100
ksmps=32
nchnls=2
0dbfs=1

#define LIMIT1(a) #
  klimindx = 0
  while (klimindx < lenarray:k($a)) do
    $a[klimindx] = limit($a[klimindx],0,1)
    klimindx += 1
  od
#


instr 1
  kArr[] fillarray -.2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0

  $LIMIT1(kArr)

  kindx = 0
  while (kindx < lenarray:k(kArr)) do
    printk2 kArr[kindx]
    kindx += 1
  od
  turnoff
endin

</CsInstruments>
<CsScore>
i1 0 1


</CsScore>
</CsoundSynthesizer>




On Thu, Apr 20, 2017 at 10:28 AM, thorin kerr <[hidden email]> wrote:

> vlimit works on tables.... so... here's an approach.
> I have no idea how expensve this is.
>
> instr 2
> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
> ilen lenarray kArr
> i_farr ftgentmp 0,0,-ilen,-2,0
> copya2ftab kArr, i_farr
> vlimit i_farr, 0,1,ilen
> kresult[] init ilen
> copyf2array kresult, i_farr
> kmax maxarray kresult
> printk2 kmax
> endin
>
>
> On 20 Apr 2017 11:47 PM, "Rory Walsh" <[hidden email]> wrote:
>
> And it would also be doing a value by value copy on each k-pass, which is
> probably something Oeyvind is trying to avoid I guess..
>
> On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
>>
>> Don't UDOs pass by value? Wouldn't that be copying the entire array
>> twice with that strategy?
>>
>>
>> On 20/04/17 06:15, Rory Walsh wrote:
>> > Can you not create a UDO that simply takes one array as input and
>> > outputs
>> > another, limiting values between 0 and 1?
>> >
>> > On 20 April 2017 at 07:14, Oeyvind Brandtsegg
>> > <[hidden email]>
>> > wrote:
>> >
>> >> Hi,
>> >> I'm trying to limit the values in an array to a specific range (0 to 1
>> >> in
>> >> my case).
>> >> I thought maybe I could use maparray, and since I can only use
>> >> functions
>> >> with one argument I thought I could try making a UDO of limit with
>> >> preset
>> >> values for the uper and lower limit.
>> >> It seems maparray won't accept UDOs as functions.
>> >> Is there another way to limit the range of values in an array (and
>> >> otherwise not changing the values inside the allowed range.
>> >>
>> >> Here's my UDO based attempt, which gives
>> >> INIT ERROR in instr 2: lim not found
>> >> kArr1   maparray.k      kArr    "lim"
>> >>
>> >> ***
>> >> opcode lim,k,k
>> >>         k1 xin
>> >>         xout limit(k1,0,1)
>> >>         endop
>> >>
>> >> instr 2
>> >> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> >> kArr1[] maparray kArr, "lim"
>> >> kmax maxarray kArr1
>> >> printk2 kmax
>> >> endin
>> >> ***
>> >>
>> >> I also tried using "tanh" which sort of could work, but of course it
>> >> warps
>> >> the values inside the allowed range and I would prefer to have the
>> >> option
>> >> of keeping them linear up to the selected limit.
>> >>
>> >> Is there another approach that I could use?
>> >> Any formulas based on the allowed operations on arrays that could make
>> >> the
>> >> trick?
>> >>
>> >> --
>> >>
>> >> Oeyvind Brandtsegg
>> >> Professor of Music Technology
>> >> NTNU
>> >> 7491 Trondheim
>> >> Norway
>> >> Cell: +47 92 203 205
>> >>
>> >> http://www.partikkelaudio.com/
>> >> http://crossadaptive.hf.ntnu.no
>> >> http://gdsp.hf.ntnu.no/
>> >> http://soundcloud.com/brandtsegg
>> >> http://flyndresang.no/
>> >> http://soundcloud.com/t-emp
>> >>
>> >> Csound mailing list [hidden email]
>> >> 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
>> > [hidden email]
>> > 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
>> [hidden email]
>> 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 [hidden email]
> 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 [hidden email]
> 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
[hidden email]
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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

Oeyvind Brandtsegg-3
Thanks all,
yes, the interation macro solution is nice, Steven, and as you say probably the cheapest for now.
I am trying to build a fuzzy histogram, and thought I'd make it more efficient by using array operations rather than iteration.

The vlimit suggestion is nice too, thanks Thorin, I had forgotten about that.
A limit function for arrays would be handy, and a more robust maparray as you say, Steven.

Perhaps a generic way of doing this (and a lot of other things) would be to allow the values of an array to be used as index to a table?
Like a "waveshape-array" operation, not shure what would be a good name for it..."transformarray"? "funcarray"?

best
Oeyvind

2017-04-20 8:01 GMT-07:00 Steven Yi <[hidden email]>:
I think a more robust map function would be great, but until then, the
issues raised about pass-by-value are correct and there would be a
cost there to memcpy() data back and forth.

I think with what's in Csound at the moment, the solution with the
balance of performance and ease is to use a loop to process and to use
to a macro to make it a one-liner. I tried the following and it seems
to work here:

<CsoundSynthesizer>
<CsInstruments>

sr=44100
ksmps=32
nchnls=2
0dbfs=1

#define LIMIT1(a) #
  klimindx = 0
  while (klimindx < lenarray:k($a)) do
    $a[klimindx] = limit($a[klimindx],0,1)
    klimindx += 1
  od
#


instr 1
  kArr[] fillarray -.2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0

  $LIMIT1(kArr)

  kindx = 0
  while (kindx < lenarray:k(kArr)) do
    printk2 kArr[kindx]
    kindx += 1
  od
  turnoff
endin

</CsInstruments>
<CsScore>
i1 0 1


</CsScore>
</CsoundSynthesizer>




On Thu, Apr 20, 2017 at 10:28 AM, thorin kerr <[hidden email]> wrote:
> vlimit works on tables.... so... here's an approach.
> I have no idea how expensve this is.
>
> instr 2
> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
> ilen lenarray kArr
> i_farr ftgentmp 0,0,-ilen,-2,0
> copya2ftab kArr, i_farr
> vlimit i_farr, 0,1,ilen
> kresult[] init ilen
> copyf2array kresult, i_farr
> kmax maxarray kresult
> printk2 kmax
> endin
>
>
> On 20 Apr 2017 11:47 PM, "Rory Walsh" <[hidden email]> wrote:
>
> And it would also be doing a value by value copy on each k-pass, which is
> probably something Oeyvind is trying to avoid I guess..
>
> On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
>>
>> Don't UDOs pass by value? Wouldn't that be copying the entire array
>> twice with that strategy?
>>
>>
>> On 20/04/17 06:15, Rory Walsh wrote:
>> > Can you not create a UDO that simply takes one array as input and
>> > outputs
>> > another, limiting values between 0 and 1?
>> >
>> > On 20 April 2017 at 07:14, Oeyvind Brandtsegg
>> > <[hidden email]>
>> > wrote:
>> >
>> >> Hi,
>> >> I'm trying to limit the values in an array to a specific range (0 to 1
>> >> in
>> >> my case).
>> >> I thought maybe I could use maparray, and since I can only use
>> >> functions
>> >> with one argument I thought I could try making a UDO of limit with
>> >> preset
>> >> values for the uper and lower limit.
>> >> It seems maparray won't accept UDOs as functions.
>> >> Is there another way to limit the range of values in an array (and
>> >> otherwise not changing the values inside the allowed range.
>> >>
>> >> Here's my UDO based attempt, which gives
>> >> INIT ERROR in instr 2: lim not found
>> >> kArr1   maparray.k      kArr    "lim"
>> >>
>> >> ***
>> >> opcode lim,k,k
>> >>         k1 xin
>> >>         xout limit(k1,0,1)
>> >>         endop
>> >>
>> >> instr 2
>> >> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> >> kArr1[] maparray kArr, "lim"
>> >> kmax maxarray kArr1
>> >> printk2 kmax
>> >> endin
>> >> ***
>> >>
>> >> I also tried using "tanh" which sort of could work, but of course it
>> >> warps
>> >> the values inside the allowed range and I would prefer to have the
>> >> option
>> >> of keeping them linear up to the selected limit.
>> >>
>> >> Is there another approach that I could use?
>> >> Any formulas based on the allowed operations on arrays that could make
>> >> the
>> >> trick?
>> >>
>> >> --
>> >>
>> >> Oeyvind Brandtsegg
>> >> Professor of Music Technology
>> >> NTNU
>> >> 7491 Trondheim
>> >> Norway
>> >> Cell: +47 92 203 205
>> >>
>> >> http://www.partikkelaudio.com/
>> >> http://crossadaptive.hf.ntnu.no
>> >> http://gdsp.hf.ntnu.no/
>> >> http://soundcloud.com/brandtsegg
>> >> http://flyndresang.no/
>> >> http://soundcloud.com/t-emp
>> >>
>> >> Csound mailing list [hidden email]
>> >> 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
>> > [hidden email]
>> > 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
>> [hidden email]
>> 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 [hidden email]
> 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 [hidden email]
> 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
[hidden email]
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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

Steven Yi
Well, I think it's worth noting that "map" is a very common operation
for functional programming languages to apply an operation across
every item in a list or sequence.  Together with "reduce" and "apply"
(and perhaps "partial" for partial function application; currying
might not be possible integrate into the language we have today), we'd
have the tools necessary to do a lot of transformations with
arrays/lists and open up a lot of possibilities.  For example, instead
of having to create additional versions of opcodes to work with
arrays, we could have something like:

apply(linseg, [0, 0.5, 1, p3 - 1, 1, 0.5, 0])

to dynamically call linseg at run time with any number of points that
might come from an array.  (This would be extremely handy in use with
schedule/event, as users could create their own event and scheduling
systems in user code.)

I think there's a big value in getting these kinds of operations in
place rather to generically solve implementing a class of operations.
That said, these operations are going to have a runtime cost, so
having special overloaded versions of opcodes (like a limit opcode
that takes in arrays) will probably be useful too.



On Thu, Apr 20, 2017 at 11:31 AM, Oeyvind Brandtsegg
<[hidden email]> wrote:

> Thanks all,
> yes, the interation macro solution is nice, Steven, and as you say probably
> the cheapest for now.
> I am trying to build a fuzzy histogram, and thought I'd make it more
> efficient by using array operations rather than iteration.
>
> The vlimit suggestion is nice too, thanks Thorin, I had forgotten about
> that.
> A limit function for arrays would be handy, and a more robust maparray as
> you say, Steven.
>
> Perhaps a generic way of doing this (and a lot of other things) would be to
> allow the values of an array to be used as index to a table?
> Like a "waveshape-array" operation, not shure what would be a good name for
> it..."transformarray"? "funcarray"?
>
> best
> Oeyvind
>
> 2017-04-20 8:01 GMT-07:00 Steven Yi <[hidden email]>:
>>
>> I think a more robust map function would be great, but until then, the
>> issues raised about pass-by-value are correct and there would be a
>> cost there to memcpy() data back and forth.
>>
>> I think with what's in Csound at the moment, the solution with the
>> balance of performance and ease is to use a loop to process and to use
>> to a macro to make it a one-liner. I tried the following and it seems
>> to work here:
>>
>> <CsoundSynthesizer>
>> <CsInstruments>
>>
>> sr=44100
>> ksmps=32
>> nchnls=2
>> 0dbfs=1
>>
>> #define LIMIT1(a) #
>>   klimindx = 0
>>   while (klimindx < lenarray:k($a)) do
>>     $a[klimindx] = limit($a[klimindx],0,1)
>>     klimindx += 1
>>   od
>> #
>>
>>
>> instr 1
>>   kArr[] fillarray -.2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>>
>>   $LIMIT1(kArr)
>>
>>   kindx = 0
>>   while (kindx < lenarray:k(kArr)) do
>>     printk2 kArr[kindx]
>>     kindx += 1
>>   od
>>   turnoff
>> endin
>>
>> </CsInstruments>
>> <CsScore>
>> i1 0 1
>>
>>
>> </CsScore>
>> </CsoundSynthesizer>
>>
>>
>>
>>
>> On Thu, Apr 20, 2017 at 10:28 AM, thorin kerr <[hidden email]>
>> wrote:
>> > vlimit works on tables.... so... here's an approach.
>> > I have no idea how expensve this is.
>> >
>> > instr 2
>> > kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> > ilen lenarray kArr
>> > i_farr ftgentmp 0,0,-ilen,-2,0
>> > copya2ftab kArr, i_farr
>> > vlimit i_farr, 0,1,ilen
>> > kresult[] init ilen
>> > copyf2array kresult, i_farr
>> > kmax maxarray kresult
>> > printk2 kmax
>> > endin
>> >
>> >
>> > On 20 Apr 2017 11:47 PM, "Rory Walsh" <[hidden email]> wrote:
>> >
>> > And it would also be doing a value by value copy on each k-pass, which
>> > is
>> > probably something Oeyvind is trying to avoid I guess..
>> >
>> > On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
>> >>
>> >> Don't UDOs pass by value? Wouldn't that be copying the entire array
>> >> twice with that strategy?
>> >>
>> >>
>> >> On 20/04/17 06:15, Rory Walsh wrote:
>> >> > Can you not create a UDO that simply takes one array as input and
>> >> > outputs
>> >> > another, limiting values between 0 and 1?
>> >> >
>> >> > On 20 April 2017 at 07:14, Oeyvind Brandtsegg
>> >> > <[hidden email]>
>> >> > wrote:
>> >> >
>> >> >> Hi,
>> >> >> I'm trying to limit the values in an array to a specific range (0 to
>> >> >> 1
>> >> >> in
>> >> >> my case).
>> >> >> I thought maybe I could use maparray, and since I can only use
>> >> >> functions
>> >> >> with one argument I thought I could try making a UDO of limit with
>> >> >> preset
>> >> >> values for the uper and lower limit.
>> >> >> It seems maparray won't accept UDOs as functions.
>> >> >> Is there another way to limit the range of values in an array (and
>> >> >> otherwise not changing the values inside the allowed range.
>> >> >>
>> >> >> Here's my UDO based attempt, which gives
>> >> >> INIT ERROR in instr 2: lim not found
>> >> >> kArr1   maparray.k      kArr    "lim"
>> >> >>
>> >> >> ***
>> >> >> opcode lim,k,k
>> >> >>         k1 xin
>> >> >>         xout limit(k1,0,1)
>> >> >>         endop
>> >> >>
>> >> >> instr 2
>> >> >> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> >> >> kArr1[] maparray kArr, "lim"
>> >> >> kmax maxarray kArr1
>> >> >> printk2 kmax
>> >> >> endin
>> >> >> ***
>> >> >>
>> >> >> I also tried using "tanh" which sort of could work, but of course it
>> >> >> warps
>> >> >> the values inside the allowed range and I would prefer to have the
>> >> >> option
>> >> >> of keeping them linear up to the selected limit.
>> >> >>
>> >> >> Is there another approach that I could use?
>> >> >> Any formulas based on the allowed operations on arrays that could
>> >> >> make
>> >> >> the
>> >> >> trick?
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Oeyvind Brandtsegg
>> >> >> Professor of Music Technology
>> >> >> NTNU
>> >> >> 7491 Trondheim
>> >> >> Norway
>> >> >> Cell: +47 92 203 205
>> >> >>
>> >> >> http://www.partikkelaudio.com/
>> >> >> http://crossadaptive.hf.ntnu.no
>> >> >> http://gdsp.hf.ntnu.no/
>> >> >> http://soundcloud.com/brandtsegg
>> >> >> http://flyndresang.no/
>> >> >> http://soundcloud.com/t-emp
>> >> >>
>> >> >> Csound mailing list [hidden email]
>> >> >> 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
>> >> > [hidden email]
>> >> > 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
>> >> [hidden email]
>> >> 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 [hidden email]
>> > 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 [hidden email]
>> > 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
>> [hidden email]
>> 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
>
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://www.partikkelaudio.com/
> http://crossadaptive.hf.ntnu.no
> http://gdsp.hf.ntnu.no/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/
> http://soundcloud.com/t-emp
>
> Csound mailing list [hidden email]
> 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
[hidden email]
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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

Oeyvind Brandtsegg-3
I'm glad to see there is interest in developing these parts of Csound further, and as always, your suggestions are far better than mine.
I'm looking forward to see where it goes. 

I got around the histogram issue with the iteration approach for now.

2017-04-20 12:45 GMT-07:00 Steven Yi <[hidden email]>:
Well, I think it's worth noting that "map" is a very common operation
for functional programming languages to apply an operation across
every item in a list or sequence.  Together with "reduce" and "apply"
(and perhaps "partial" for partial function application; currying
might not be possible integrate into the language we have today), we'd
have the tools necessary to do a lot of transformations with
arrays/lists and open up a lot of possibilities.  For example, instead
of having to create additional versions of opcodes to work with
arrays, we could have something like:

apply(linseg, [0, 0.5, 1, p3 - 1, 1, 0.5, 0])

to dynamically call linseg at run time with any number of points that
might come from an array.  (This would be extremely handy in use with
schedule/event, as users could create their own event and scheduling
systems in user code.)

I think there's a big value in getting these kinds of operations in
place rather to generically solve implementing a class of operations.
That said, these operations are going to have a runtime cost, so
having special overloaded versions of opcodes (like a limit opcode
that takes in arrays) will probably be useful too.



On Thu, Apr 20, 2017 at 11:31 AM, Oeyvind Brandtsegg
<[hidden email]> wrote:
> Thanks all,
> yes, the interation macro solution is nice, Steven, and as you say probably
> the cheapest for now.
> I am trying to build a fuzzy histogram, and thought I'd make it more
> efficient by using array operations rather than iteration.
>
> The vlimit suggestion is nice too, thanks Thorin, I had forgotten about
> that.
> A limit function for arrays would be handy, and a more robust maparray as
> you say, Steven.
>
> Perhaps a generic way of doing this (and a lot of other things) would be to
> allow the values of an array to be used as index to a table?
> Like a "waveshape-array" operation, not shure what would be a good name for
> it..."transformarray"? "funcarray"?
>
> best
> Oeyvind
>
> 2017-04-20 8:01 GMT-07:00 Steven Yi <[hidden email]>:
>>
>> I think a more robust map function would be great, but until then, the
>> issues raised about pass-by-value are correct and there would be a
>> cost there to memcpy() data back and forth.
>>
>> I think with what's in Csound at the moment, the solution with the
>> balance of performance and ease is to use a loop to process and to use
>> to a macro to make it a one-liner. I tried the following and it seems
>> to work here:
>>
>> <CsoundSynthesizer>
>> <CsInstruments>
>>
>> sr=44100
>> ksmps=32
>> nchnls=2
>> 0dbfs=1
>>
>> #define LIMIT1(a) #
>>   klimindx = 0
>>   while (klimindx < lenarray:k($a)) do
>>     $a[klimindx] = limit($a[klimindx],0,1)
>>     klimindx += 1
>>   od
>> #
>>
>>
>> instr 1
>>   kArr[] fillarray -.2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>>
>>   $LIMIT1(kArr)
>>
>>   kindx = 0
>>   while (kindx < lenarray:k(kArr)) do
>>     printk2 kArr[kindx]
>>     kindx += 1
>>   od
>>   turnoff
>> endin
>>
>> </CsInstruments>
>> <CsScore>
>> i1 0 1
>>
>>
>> </CsScore>
>> </CsoundSynthesizer>
>>
>>
>>
>>
>> On Thu, Apr 20, 2017 at 10:28 AM, thorin kerr <[hidden email]>
>> wrote:
>> > vlimit works on tables.... so... here's an approach.
>> > I have no idea how expensve this is.
>> >
>> > instr 2
>> > kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> > ilen lenarray kArr
>> > i_farr ftgentmp 0,0,-ilen,-2,0
>> > copya2ftab kArr, i_farr
>> > vlimit i_farr, 0,1,ilen
>> > kresult[] init ilen
>> > copyf2array kresult, i_farr
>> > kmax maxarray kresult
>> > printk2 kmax
>> > endin
>> >
>> >
>> > On 20 Apr 2017 11:47 PM, "Rory Walsh" <[hidden email]> wrote:
>> >
>> > And it would also be doing a value by value copy on each k-pass, which
>> > is
>> > probably something Oeyvind is trying to avoid I guess..
>> >
>> > On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
>> >>
>> >> Don't UDOs pass by value? Wouldn't that be copying the entire array
>> >> twice with that strategy?
>> >>
>> >>
>> >> On 20/04/17 06:15, Rory Walsh wrote:
>> >> > Can you not create a UDO that simply takes one array as input and
>> >> > outputs
>> >> > another, limiting values between 0 and 1?
>> >> >
>> >> > On 20 April 2017 at 07:14, Oeyvind Brandtsegg
>> >> > <[hidden email]>
>> >> > wrote:
>> >> >
>> >> >> Hi,
>> >> >> I'm trying to limit the values in an array to a specific range (0 to
>> >> >> 1
>> >> >> in
>> >> >> my case).
>> >> >> I thought maybe I could use maparray, and since I can only use
>> >> >> functions
>> >> >> with one argument I thought I could try making a UDO of limit with
>> >> >> preset
>> >> >> values for the uper and lower limit.
>> >> >> It seems maparray won't accept UDOs as functions.
>> >> >> Is there another way to limit the range of values in an array (and
>> >> >> otherwise not changing the values inside the allowed range.
>> >> >>
>> >> >> Here's my UDO based attempt, which gives
>> >> >> INIT ERROR in instr 2: lim not found
>> >> >> kArr1   maparray.k      kArr    "lim"
>> >> >>
>> >> >> ***
>> >> >> opcode lim,k,k
>> >> >>         k1 xin
>> >> >>         xout limit(k1,0,1)
>> >> >>         endop
>> >> >>
>> >> >> instr 2
>> >> >> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
>> >> >> kArr1[] maparray kArr, "lim"
>> >> >> kmax maxarray kArr1
>> >> >> printk2 kmax
>> >> >> endin
>> >> >> ***
>> >> >>
>> >> >> I also tried using "tanh" which sort of could work, but of course it
>> >> >> warps
>> >> >> the values inside the allowed range and I would prefer to have the
>> >> >> option
>> >> >> of keeping them linear up to the selected limit.
>> >> >>
>> >> >> Is there another approach that I could use?
>> >> >> Any formulas based on the allowed operations on arrays that could
>> >> >> make
>> >> >> the
>> >> >> trick?
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Oeyvind Brandtsegg
>> >> >> Professor of Music Technology
>> >> >> NTNU
>> >> >> 7491 Trondheim
>> >> >> Norway
>> >> >> Cell: +47 92 203 205
>> >> >>
>> >> >> http://www.partikkelaudio.com/
>> >> >> http://crossadaptive.hf.ntnu.no
>> >> >> http://gdsp.hf.ntnu.no/
>> >> >> http://soundcloud.com/brandtsegg
>> >> >> http://flyndresang.no/
>> >> >> http://soundcloud.com/t-emp
>> >> >>
>> >> >> Csound mailing list [hidden email]
>> >> >> 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
>> >> > [hidden email]
>> >> > 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
>> >> [hidden email]
>> >> 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 [hidden email]
>> > 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 [hidden email]
>> > 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
>> [hidden email]
>> 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
>
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: <a href="tel:%2B47%2092%20203%20205" value="+4792203205">+47 92 203 205
>
> http://www.partikkelaudio.com/
> http://crossadaptive.hf.ntnu.no
> http://gdsp.hf.ntnu.no/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/
> http://soundcloud.com/t-emp
>
> Csound mailing list [hidden email]
> 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
[hidden email]
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 [hidden email] 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
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] maparray with UDO

Victor Lazzarini
limit1 is so easy that I’ve just added it for i- and k- arrays.
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 20 Apr 2017, at 21:00, Oeyvind Brandtsegg <[hidden email]> wrote:
>
> I'm glad to see there is interest in developing these parts of Csound further, and as always, your suggestions are far better than mine.
> I'm looking forward to see where it goes.
>
> I got around the histogram issue with the iteration approach for now.
>
> 2017-04-20 12:45 GMT-07:00 Steven Yi <[hidden email]>:
> Well, I think it's worth noting that "map" is a very common operation
> for functional programming languages to apply an operation across
> every item in a list or sequence.  Together with "reduce" and "apply"
> (and perhaps "partial" for partial function application; currying
> might not be possible integrate into the language we have today), we'd
> have the tools necessary to do a lot of transformations with
> arrays/lists and open up a lot of possibilities.  For example, instead
> of having to create additional versions of opcodes to work with
> arrays, we could have something like:
>
> apply(linseg, [0, 0.5, 1, p3 - 1, 1, 0.5, 0])
>
> to dynamically call linseg at run time with any number of points that
> might come from an array.  (This would be extremely handy in use with
> schedule/event, as users could create their own event and scheduling
> systems in user code.)
>
> I think there's a big value in getting these kinds of operations in
> place rather to generically solve implementing a class of operations.
> That said, these operations are going to have a runtime cost, so
> having special overloaded versions of opcodes (like a limit opcode
> that takes in arrays) will probably be useful too.
>
>
>
> On Thu, Apr 20, 2017 at 11:31 AM, Oeyvind Brandtsegg
> <[hidden email]> wrote:
> > Thanks all,
> > yes, the interation macro solution is nice, Steven, and as you say probably
> > the cheapest for now.
> > I am trying to build a fuzzy histogram, and thought I'd make it more
> > efficient by using array operations rather than iteration.
> >
> > The vlimit suggestion is nice too, thanks Thorin, I had forgotten about
> > that.
> > A limit function for arrays would be handy, and a more robust maparray as
> > you say, Steven.
> >
> > Perhaps a generic way of doing this (and a lot of other things) would be to
> > allow the values of an array to be used as index to a table?
> > Like a "waveshape-array" operation, not shure what would be a good name for
> > it..."transformarray"? "funcarray"?
> >
> > best
> > Oeyvind
> >
> > 2017-04-20 8:01 GMT-07:00 Steven Yi <[hidden email]>:
> >>
> >> I think a more robust map function would be great, but until then, the
> >> issues raised about pass-by-value are correct and there would be a
> >> cost there to memcpy() data back and forth.
> >>
> >> I think with what's in Csound at the moment, the solution with the
> >> balance of performance and ease is to use a loop to process and to use
> >> to a macro to make it a one-liner. I tried the following and it seems
> >> to work here:
> >>
> >> <CsoundSynthesizer>
> >> <CsInstruments>
> >>
> >> sr=44100
> >> ksmps=32
> >> nchnls=2
> >> 0dbfs=1
> >>
> >> #define LIMIT1(a) #
> >>   klimindx = 0
> >>   while (klimindx < lenarray:k($a)) do
> >>     $a[klimindx] = limit($a[klimindx],0,1)
> >>     klimindx += 1
> >>   od
> >> #
> >>
> >>
> >> instr 1
> >>   kArr[] fillarray -.2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
> >>
> >>   $LIMIT1(kArr)
> >>
> >>   kindx = 0
> >>   while (kindx < lenarray:k(kArr)) do
> >>     printk2 kArr[kindx]
> >>     kindx += 1
> >>   od
> >>   turnoff
> >> endin
> >>
> >> </CsInstruments>
> >> <CsScore>
> >> i1 0 1
> >>
> >>
> >> </CsScore>
> >> </CsoundSynthesizer>
> >>
> >>
> >>
> >>
> >> On Thu, Apr 20, 2017 at 10:28 AM, thorin kerr <[hidden email]>
> >> wrote:
> >> > vlimit works on tables.... so... here's an approach.
> >> > I have no idea how expensve this is.
> >> >
> >> > instr 2
> >> > kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
> >> > ilen lenarray kArr
> >> > i_farr ftgentmp 0,0,-ilen,-2,0
> >> > copya2ftab kArr, i_farr
> >> > vlimit i_farr, 0,1,ilen
> >> > kresult[] init ilen
> >> > copyf2array kresult, i_farr
> >> > kmax maxarray kresult
> >> > printk2 kmax
> >> > endin
> >> >
> >> >
> >> > On 20 Apr 2017 11:47 PM, "Rory Walsh" <[hidden email]> wrote:
> >> >
> >> > And it would also be doing a value by value copy on each k-pass, which
> >> > is
> >> > probably something Oeyvind is trying to avoid I guess..
> >> >
> >> > On 20 April 2017 at 14:20, Guillermo Senna <[hidden email]> wrote:
> >> >>
> >> >> Don't UDOs pass by value? Wouldn't that be copying the entire array
> >> >> twice with that strategy?
> >> >>
> >> >>
> >> >> On 20/04/17 06:15, Rory Walsh wrote:
> >> >> > Can you not create a UDO that simply takes one array as input and
> >> >> > outputs
> >> >> > another, limiting values between 0 and 1?
> >> >> >
> >> >> > On 20 April 2017 at 07:14, Oeyvind Brandtsegg
> >> >> > <[hidden email]>
> >> >> > wrote:
> >> >> >
> >> >> >> Hi,
> >> >> >> I'm trying to limit the values in an array to a specific range (0 to
> >> >> >> 1
> >> >> >> in
> >> >> >> my case).
> >> >> >> I thought maybe I could use maparray, and since I can only use
> >> >> >> functions
> >> >> >> with one argument I thought I could try making a UDO of limit with
> >> >> >> preset
> >> >> >> values for the uper and lower limit.
> >> >> >> It seems maparray won't accept UDOs as functions.
> >> >> >> Is there another way to limit the range of values in an array (and
> >> >> >> otherwise not changing the values inside the allowed range.
> >> >> >>
> >> >> >> Here's my UDO based attempt, which gives
> >> >> >> INIT ERROR in instr 2: lim not found
> >> >> >> kArr1   maparray.k      kArr    "lim"
> >> >> >>
> >> >> >> ***
> >> >> >> opcode lim,k,k
> >> >> >>         k1 xin
> >> >> >>         xout limit(k1,0,1)
> >> >> >>         endop
> >> >> >>
> >> >> >> instr 2
> >> >> >> kArr[] fillarray .2,.4,.6,.8,1.0,1.2,1.4,1.6,1.8,2.0
> >> >> >> kArr1[] maparray kArr, "lim"
> >> >> >> kmax maxarray kArr1
> >> >> >> printk2 kmax
> >> >> >> endin
> >> >> >> ***
> >> >> >>
> >> >> >> I also tried using "tanh" which sort of could work, but of course it
> >> >> >> warps
> >> >> >> the values inside the allowed range and I would prefer to have the
> >> >> >> option
> >> >> >> of keeping them linear up to the selected limit.
> >> >> >>
> >> >> >> Is there another approach that I could use?
> >> >> >> Any formulas based on the allowed operations on arrays that could
> >> >> >> make
> >> >> >> the
> >> >> >> trick?
> >> >> >>
> >> >> >> --
> >> >> >>
> >> >> >> Oeyvind Brandtsegg
> >> >> >> Professor of Music Technology
> >> >> >> NTNU
> >> >> >> 7491 Trondheim
> >> >> >> Norway
> >> >> >> Cell: +47 92 203 205
> >> >> >>
> >> >> >> http://www.partikkelaudio.com/
> >> >> >> http://crossadaptive.hf.ntnu.no
> >> >> >> http://gdsp.hf.ntnu.no/
> >> >> >> http://soundcloud.com/brandtsegg
> >> >> >> http://flyndresang.no/
> >> >> >> http://soundcloud.com/t-emp
> >> >> >>
> >> >> >> Csound mailing list [hidden email]
> >> >> >> 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
> >> >> > [hidden email]
> >> >> > 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
> >> >> [hidden email]
> >> >> 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 [hidden email]
> >> > 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 [hidden email]
> >> > 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
> >> [hidden email]
> >> 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
> >
> >
> >
> >
> > --
> >
> > Oeyvind Brandtsegg
> > Professor of Music Technology
> > NTNU
> > 7491 Trondheim
> > Norway
> > Cell: +47 92 203 205
> >
> > http://www.partikkelaudio.com/
> > http://crossadaptive.hf.ntnu.no
> > http://gdsp.hf.ntnu.no/
> > http://soundcloud.com/brandtsegg
> > http://flyndresang.no/
> > http://soundcloud.com/t-emp
> >
> > Csound mailing list [hidden email]
> > 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
> [hidden email]
> 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
>
>
>
> --
>
> Oeyvind Brandtsegg
> Professor of Music Technology
> NTNU
> 7491 Trondheim
> Norway
> Cell: +47 92 203 205
>
> http://www.partikkelaudio.com/
> http://crossadaptive.hf.ntnu.no
> http://gdsp.hf.ntnu.no/
> http://soundcloud.com/brandtsegg
> http://flyndresang.no/
> http://soundcloud.com/t-emp
>  
> Csound mailing list [hidden email] 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
[hidden email]
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