Csound Csound-dev Csound-tekno Search About

[Csnd] rand with cubic interpolation?

Date2019-09-23 17:50
FromMauro Giubileo
Subject[Csnd] rand with cubic interpolation?

I'm playing with randomic sound generation. I noticed two useful opcodes that makes me set the frequency of the generation of the numbers: randh, randi. That's very nice.

The first (randh) generates some horizontal lines between the generated points, so you'll have a "step"-style random sequence.

The second opcode (randi) is similar but it produces straight-line interpolation between each new number and the next, instead of just holding the values.

Now I'm wondering: is it possible to make something similar to the two above opcodes but with a cubic interpolation between every two points instead of a linear interpolation? I would like to generate a smoothly interpolated curve from the generated random points, instead of a step-style curve or a linear-interpolated curve... How can I do that?

---
Mauro

 

Date2019-09-23 19:48
FromSteven Yi
SubjectRe: [Csnd] rand with cubic interpolation?
Hi Mauro,

I implemented a UDO for randcubic to generate bipolar cubically
interpolated random line with kamp and kfreq arguments.  The code,
example CSD, and audio example are available here:

https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-interpolation/

Just a note that cubic interpolation can overshoot boundaries.

Hope this helps!
steven


On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
 wrote:
>
> I'm playing with randomic sound generation. I noticed two useful opcodes that makes me set the frequency of the generation of the numbers: randh, randi. That's very nice.
>
> The first (randh) generates some horizontal lines between the generated points, so you'll have a "step"-style random sequence.
>
> The second opcode (randi) is similar but it produces straight-line interpolation between each new number and the next, instead of just holding the values.
>
> Now I'm wondering: is it possible to make something similar to the two above opcodes but with a cubic interpolation between every two points instead of a linear interpolation? I would like to generate a smoothly interpolated curve from the generated random points, instead of a step-style curve or a linear-interpolated curve... How can I do that?
>
> ---
> Mauro
>
>
> 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

Date2019-09-24 04:16
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] rand with cubic interpolation?
Cool.  Mauro...Thanks for asking and Steven... thanks for the UDO!

Dr. Richard Boulanger
Professor
Electronic Production and Design
Berklee College of Music

> On Sep 23, 2019, at 2:48 PM, Steven Yi  wrote:
> 
> Hi Mauro,
> 
> I implemented a UDO for randcubic to generate bipolar cubically
> interpolated random line with kamp and kfreq arguments.  The code,
> example CSD, and audio example are available here:
> 
> https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-interpolation/
> 
> Just a note that cubic interpolation can overshoot boundaries.
> 
> Hope this helps!
> steven
> 
> 
> On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
>  wrote:
>> 
>> I'm playing with randomic sound generation. I noticed two useful opcodes that makes me set the frequency of the generation of the numbers: randh, randi. That's very nice.
>> 
>> The first (randh) generates some horizontal lines between the generated points, so you'll have a "step"-style random sequence.
>> 
>> The second opcode (randi) is similar but it produces straight-line interpolation between each new number and the next, instead of just holding the values.
>> 
>> Now I'm wondering: is it possible to make something similar to the two above opcodes but with a cubic interpolation between every two points instead of a linear interpolation? I would like to generate a smoothly interpolated curve from the generated random points, instead of a step-style curve or a linear-interpolated curve... How can I do that?
>> 
>> ---
>> Mauro
>> 
>> 
>> 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

Date2019-09-24 04:18
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] rand with cubic interpolation?
Nice sound example too!

Dr. Richard Boulanger
Professor
Electronic Production and Design
Berklee College of Music

> On Sep 23, 2019, at 11:16 PM, Dr. Richard Boulanger  wrote:
> 
> Cool.  Mauro...Thanks for asking and Steven... thanks for the UDO!
> 
> Dr. Richard Boulanger
> Professor
> Electronic Production and Design
> Berklee College of Music
> 
>> On Sep 23, 2019, at 2:48 PM, Steven Yi  wrote:
>> 
>> Hi Mauro,
>> 
>> I implemented a UDO for randcubic to generate bipolar cubically
>> interpolated random line with kamp and kfreq arguments.  The code,
>> example CSD, and audio example are available here:
>> 
>> https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-interpolation/
>> 
>> Just a note that cubic interpolation can overshoot boundaries.
>> 
>> Hope this helps!
>> steven
>> 
>> 
>> On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
>>  wrote:
>>> 
>>> I'm playing with randomic sound generation. I noticed two useful opcodes that makes me set the frequency of the generation of the numbers: randh, randi. That's very nice.
>>> 
>>> The first (randh) generates some horizontal lines between the generated points, so you'll have a "step"-style random sequence.
>>> 
>>> The second opcode (randi) is similar but it produces straight-line interpolation between each new number and the next, instead of just holding the values.
>>> 
>>> Now I'm wondering: is it possible to make something similar to the two above opcodes but with a cubic interpolation between every two points instead of a linear interpolation? I would like to generate a smoothly interpolated curve from the generated random points, instead of a step-style curve or a linear-interpolated curve... How can I do that?
>>> 
>>> ---
>>> Mauro
>>> 
>>> 
>>> 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

Date2019-09-24 09:04
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

Wow, that's very nice, just what I wanted! Honestly I'm surprised that there isn't an internal opcode for this... It's the natural completition of rand, randh and randi. I noticed that your opcode doesn't have the seed parameter (that I like to use very much to change the pseudo-random generation in a repeatable way), so I made a very little mod to make it more similar to randh and randi (I added the iSeed parameter). I abbreviated the name to "randc" (so that we have randh, randi, randc):

opcode randc, a,kki
    kAmp,     \
    kfreq,    \
    iSeed     xin
 
    ky0       init    random:i(-1, 1)
    ky1       init    random:i(-1, 1)
    ky2       init    random:i(-1, 1)
    ky3       init    random:i(-1, 1)
 
    kcount    init    0
    asig      init    0
 
    kperiod   =       sr / kfreq
    kndx      =       0
 
    while (kndx < ksmps) do
        ka0         =   ky3 - ky2 - ky0 + ky1
        ka1         =   ky0 - ky1 - ka0
        ka2         =   ky2 - ky0
        ka3         =   ky1
    
        kmu         =   kcount / kperiod
        kmu2        =   kmu * kmu
    
        asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
        kcount      +=  1
    
        if (kcount > kperiod) then
            ky0       =   ky1
            ky1       =   ky2
            ky2       =   ky3       
            ky3       =   rand:k(kAmp, iSeed)  
            kcount    -=  kperiod
        endif
    
        kndx        +=  1
    od
    
    asig    *=      kAmp
            xout    asig
 
endop

 

Now, if someone made this in an internal opcode in Csound it would be great!

Thanks again, Steven!

---
Mauro


Il 2019-09-23 20:48 Steven Yi ha scritto:

Hi Mauro,

I implemented a UDO for randcubic to generate bipolar cubically
interpolated random line with kamp and kfreq arguments.  The code,
example CSD, and audio example are available here:

https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-interpolation/

Just a note that cubic interpolation can overshoot boundaries.

Hope this helps!
steven


On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
<mgiubileo@computeraltafed.it> wrote:

I'm playing with randomic sound generation. I noticed two useful opcodes that makes me set the frequency of the generation of the numbers: randh, randi. That's very nice.

The first (randh) generates some horizontal lines between the generated points, so you'll have a "step"-style random sequence.

The second opcode (randi) is similar but it produces straight-line interpolation between each new number and the next, instead of just holding the values.

Now I'm wondering: is it possible to make something similar to the two above opcodes but with a cubic interpolation between every two points instead of a linear interpolation? I would like to generate a smoothly interpolated curve from the generated random points, instead of a step-style curve or a linear-interpolated curve... How can I do that?

---
Mauro


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

Date2019-09-27 14:54
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
I di not understand your use of iseed.  Will it not reseed the PRNG on 
each

On Tue, 24 Sep 2019, Mauro Giubileo wrote:

> 
> Wow, that's very nice, just what I wanted! Honestly I'm surprised that there
> isn't an internal opcode for this... It's the natural completition of rand,
> randh and randi. I noticed that your opcode doesn't have the seed parameter
> (that I like to use very much to change the pseudo-random generation in a
> repeatable way), so I made a very little mod to make it more similar to randh
> and randi (I added the iSeed parameter). I abbreviated the name to "randc" (so
> that we have randh, randi, randc):
> 
> opcode randc, a,kki
>     kAmp,     \
>     kfreq,    \
>     iSeed     xin
>  
>     ky0       init    random:i(-1, 1)
>     ky1       init    random:i(-1, 1)
>     ky2       init    random:i(-1, 1)
>     ky3       init    random:i(-1, 1)
>  
>     kcount    init    0
>     asig      init    0
>  
>     kperiod   =       sr / kfreq
>     kndx      =       0
>  
>     while (kndx < ksmps) do
>         ka0         =   ky3 - ky2 - ky0 + ky1
>         ka1         =   ky0 - ky1 - ka0
>         ka2         =   ky2 - ky0
>         ka3         =   ky1
>     
>         kmu         =   kcount / kperiod
>         kmu2        =   kmu * kmu
>     
>         asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
>     
>         kcount      +=  1
>     
>         if (kcount > kperiod) then
>             ky0       =   ky1
>             ky1       =   ky2
>             ky2       =   ky3       
>             ky3       =   rand:k(kAmp, iSeed)  
>             kcount    -=  kperiod
>         endif
>     
>         kndx        +=  1
>     od
>     
>     asig    *=      kAmp
>             xout    asig
>  
> endop
> 
>  
> 
> Now, if someone made this in an internal opcode in Csound it would be great!
> 
> Thanks again, Steven!
> 
> ---
> Mauro
> 
> 
> Il 2019-09-23 20:48 Steven Yi ha scritto:
>
>       Hi Mauro,
>
>       I implemented a UDO for randcubic to generate bipolar cubically
>       interpolated random line with kamp and kfreq arguments.  The code,
>       example CSD, and audio example are available here:
> 
> https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-
>       interpolation/
>
>       Just a note that cubic interpolation can overshoot boundaries.
>
>       Hope this helps!
>       steven
> 
>
>       On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
>        wrote:
>
>             I'm playing with randomic sound generation. I noticed
>             two useful opcodes that makes me set the frequency of
>             the generation of the numbers: randh, randi. That's
>             very nice.
>
>             The first (randh) generates some horizontal lines
>             between the generated points, so you'll have a
>             "step"-style random sequence.
>
>             The second opcode (randi) is similar but it produces
>             straight-line interpolation between each new number
>             and the next, instead of just holding the values.
>
>             Now I'm wondering: is it possible to make something
>             similar to the two above opcodes but with a cubic
>             interpolation between every two points instead of a
>             linear interpolation? I would like to generate a
>             smoothly interpolated curve from the generated random
>             points, instead of a step-style curve or a
>             linear-interpolated curve... How can I do that?
>
>             ---
>             Mauro
> 
>
>             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

Date2019-09-27 16:15
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
Ignore this; I hit send rather than delete....

On Fri, 27 Sep 2019, john wrote:

> I di not understand your use of iseed.  Will it not reseed the PRNG on each
>

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

Date2019-09-27 18:25
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
On Tue, 24 Sep 2019, Mauro Giubileo wrote:

> 
> Wow, that's very nice, just what I wanted! Honestly I'm surprised that there
> isn't an internal opcode for this... It's the natural completition of rand,
> randh and randi.


I have a new opcode randc apparently working in the audio rate version. 
Seems to pprodue very simiar results to Steven's udo but I have only run 
one test so far.

Still need to do the k-rate version as well

==John

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

Date2019-09-27 18:43
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

John, you were right that my version has something wrong. It doesn't behave like randi and randh, because the "random" opcode doesn't work with a variable seed, so the first generated values are always different, after which it stabilizes according to the seed (because in the last lines I used "rand:k(kAmp, iSeed)", instead of the "random" opcode, so that I could use a seed parameter). And another difference with randi and randh is that those opcodes generates always "kAmp * iSeed" as the first value. Steven version doesn't do that, always because of the "random" opcode. I made some other changes to make it behave more like randi/randh opcodes:

opcode randc, a,kki
    kAmp,     \
    kfreq,    \
    iSeed     xin
 

    ky0       init    0
    ky1       init    i(kAmp) * iSeed ; <- THIS MAKES THE FIRST OUTPUT = kAmp*iSeed
    ky2       init    0
    ky3       init    0
   
    kcount    init    0
    asig      init    0
 
    kperiod   =       sr / kfreq
    kndx      =       0
 
    while (kndx < ksmps) do
        ka0         =   ky3 - ky2 - ky0 + ky1
        ka1         =   ky0 - ky1 - ka0
        ka2         =   ky2 - ky0
        ka3         =   ky1
    
        kmu         =   kcount / kperiod
        kmu2        =   kmu * kmu
    
        asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
        kcount      +=  1
    
        if (kcount > kperiod) then
            ky0       =   ky1
            ky1       =   ky2
            ky2       =   ky3       
            ky3       =   rand:k(1, iSeed)  
            kcount    -=  kperiod
        endif
    
        kndx        +=  1
    od
    
    asig    *=      kAmp
            xout    asig
 
endop

Now the first generated values are always the same, if the iSeed parameter is the same and the first output will always be kAmp*iSeed.

---
Mauro

 


Il 2019-09-27 15:54 john ha scritto:

I di not understand your use of iseed.  Will it not reseed the PRNG on each

On Tue, 24 Sep 2019, Mauro Giubileo wrote:


Wow, that's very nice, just what I wanted! Honestly I'm surprised that there
isn't an internal opcode for this... It's the natural completition of rand,
randh and randi. I noticed that your opcode doesn't have the seed parameter
(that I like to use very much to change the pseudo-random generation in a
repeatable way), so I made a very little mod to make it more similar to randh
and randi (I added the iSeed parameter). I abbreviated the name to "randc" (so
that we have randh, randi, randc):

opcode randc, a,kki
    kAmp,     \
    kfreq,    \
    iSeed     xin
 
    ky0       init    random:i(-1, 1)
    ky1       init    random:i(-1, 1)
    ky2       init    random:i(-1, 1)
    ky3       init    random:i(-1, 1)
 
    kcount    init    0
    asig      init    0
 
    kperiod   =       sr / kfreq
    kndx      =       0
 
    while (kndx < ksmps) do
        ka0         =   ky3 - ky2 - ky0 + ky1
        ka1         =   ky0 - ky1 - ka0
        ka2         =   ky2 - ky0
        ka3         =   ky1
    
        kmu         =   kcount / kperiod
        kmu2        =   kmu * kmu
    
        asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
        kcount      +=  1
    
        if (kcount > kperiod) then
            ky0       =   ky1
            ky1       =   ky2
            ky2       =   ky3       
            ky3       =   rand:k(kAmp, iSeed)  
            kcount    -=  kperiod
        endif
    
        kndx        +=  1
    od
    
    asig    *=      kAmp
            xout    asig
 
endop

 

Now, if someone made this in an internal opcode in Csound it would be great!

Thanks again, Steven!

---
Mauro


Il 2019-09-23 20:48 Steven Yi ha scritto:

      Hi Mauro,

      I implemented a UDO for randcubic to generate bipolar cubically
      interpolated random line with kamp and kfreq arguments.  The code,
      example CSD, and audio example are available here:

https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-
      interpolation/

      Just a note that cubic interpolation can overshoot boundaries.

      Hope this helps!
      steven


      On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
      <mgiubileo@computeraltafed.it> wrote:

            I'm playing with randomic sound generation. I noticed
            two useful opcodes that makes me set the frequency of
            the generation of the numbers: randh, randi. That's
            very nice.

            The first (randh) generates some horizontal lines
            between the generated points, so you'll have a
            "step"-style random sequence.

            The second opcode (randi) is similar but it produces
            straight-line interpolation between each new number
            and the next, instead of just holding the values.

            Now I'm wondering: is it possible to make something
            similar to the two above opcodes but with a cubic
            interpolation between every two points instead of a
            linear interpolation? I would like to generate a
            smoothly interpolated curve from the generated random
            points, instead of a step-style curve or a
            linear-interpolated curve... How can I do that?

            ---
            Mauro


            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

Date2019-09-27 19:57
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

I just made a better version. In the previous one the first point was kAmp*iSeed but the other 3 points were 0. Furthermore, with randi/h opcodes, when iSeed>1 the first returned value is always different at every run of the instrument (the seed is based on system time), but that didn't happen with my modded version, so I corrected this. I don't think it's perfect but it's more consistent than before:


opcode randc, a,kki
    kAmp,     \
    kfreq,    \
    iSeed     xin
    
    if (iSeed > 1) then
        iFirstVal = birnd:i(1) ; different random value at each run if iSeed>1
    else
        iFirstVal = i(kAmp) * iSeed ; first value = kAmp*iSeed if iSeed<=1
    endif
    
    iSeedInt  = ceil(iSeed * 999999 + 1) ; convert the seed from [0,1] to [1, 1000000] for the rnd31 opcode
    ky0       init    rnd31:i(1, 1, iSeedInt) ; I have to use rnd31 because rand doesn't have an i-time version...
    ky1       init    iFirstVal
    ky2       init    rnd31:i(1, 1, iSeedInt)
    ky3       init    rnd31:i(1, 1, iSeedInt)
    
    kcount    init    0
    asig      init    0
 
    kperiod   =       sr / kfreq
    kndx      =       0
    
    while (kndx < ksmps) do
        ka0         =   ky3 - ky2 - ky0 + ky1
        ka1         =   ky0 - ky1 - ka0
        ka2         =   ky2 - ky0
        ka3         =   ky1
    
        kmu         =   kcount / kperiod
        kmu2        =   kmu * kmu
    
        asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
        kcount      +=  1
    
        if (kcount > kperiod) then
            ky0       =   ky1
            ky1       =   ky2
            ky2       =   ky3       
            ky3       =   rand:k(1, iSeed)  
            kcount    -=  kperiod
        endif
    
        kndx        +=  1
    od
    
    asig    *=      kAmp
            xout    asig
 
endop


---
Mauro


Il 2019-09-27 19:43 Mauro Giubileo ha scritto:

John, you were right that my version has something wrong. It doesn't behave like randi and randh, because the "random" opcode doesn't work with a variable seed, so the first generated values are always different, after which it stabilizes according to the seed (because in the last lines I used "rand:k(kAmp, iSeed)", instead of the "random" opcode, so that I could use a seed parameter). And another difference with randi and randh is that those opcodes generates always "kAmp * iSeed" as the first value. Steven version doesn't do that, always because of the "random" opcode. I made some other changes to make it behave more like randi/randh opcodes:

opcode randc, a,kki
    kAmp,     \
    kfreq,    \
    iSeed     xin
 

    ky0       init    0
    ky1       init    i(kAmp) * iSeed ; <- THIS MAKES THE FIRST OUTPUT = kAmp*iSeed
    ky2       init    0
    ky3       init    0
   
    kcount    init    0
    asig      init    0
 
    kperiod   =       sr / kfreq
    kndx      =       0
 
    while (kndx < ksmps) do
        ka0         =   ky3 - ky2 - ky0 + ky1
        ka1         =   ky0 - ky1 - ka0
        ka2         =   ky2 - ky0
        ka3         =   ky1
    
        kmu         =   kcount / kperiod
        kmu2        =   kmu * kmu
    
        asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
        kcount      +=  1
    
        if (kcount > kperiod) then
            ky0       =   ky1
            ky1       =   ky2
            ky2       =   ky3       
            ky3       =   rand:k(1, iSeed)  
            kcount    -=  kperiod
        endif
    
        kndx        +=  1
    od
    
    asig    *=      kAmp
            xout    asig
 
endop

Now the first generated values are always the same, if the iSeed parameter is the same and the first output will always be kAmp*iSeed.

---
Mauro

 


Il 2019-09-27 15:54 john ha scritto:

I di not understand your use of iseed.  Will it not reseed the PRNG on each

On Tue, 24 Sep 2019, Mauro Giubileo wrote:


Wow, that's very nice, just what I wanted! Honestly I'm surprised that there
isn't an internal opcode for this... It's the natural completition of rand,
randh and randi. I noticed that your opcode doesn't have the seed parameter
(that I like to use very much to change the pseudo-random generation in a
repeatable way), so I made a very little mod to make it more similar to randh
and randi (I added the iSeed parameter). I abbreviated the name to "randc" (so
that we have randh, randi, randc):

opcode randc, a,kki
    kAmp,     \
    kfreq,    \
    iSeed     xin
 
    ky0       init    random:i(-1, 1)
    ky1       init    random:i(-1, 1)
    ky2       init    random:i(-1, 1)
    ky3       init    random:i(-1, 1)
 
    kcount    init    0
    asig      init    0
 
    kperiod   =       sr / kfreq
    kndx      =       0
 
    while (kndx < ksmps) do
        ka0         =   ky3 - ky2 - ky0 + ky1
        ka1         =   ky0 - ky1 - ka0
        ka2         =   ky2 - ky0
        ka3         =   ky1
    
        kmu         =   kcount / kperiod
        kmu2        =   kmu * kmu
    
        asig[kndx]  =   ka0 * kmu * kmu2 + ka1 * kmu2 + ka2 * kmu + ka3
    
        kcount      +=  1
    
        if (kcount > kperiod) then
            ky0       =   ky1
            ky1       =   ky2
            ky2       =   ky3       
            ky3       =   rand:k(kAmp, iSeed)  
            kcount    -=  kperiod
        endif
    
        kndx        +=  1
    od
    
    asig    *=      kAmp
            xout    asig
 
endop

 

Now, if someone made this in an internal opcode in Csound it would be great!

Thanks again, Steven!

---
Mauro


Il 2019-09-23 20:48 Steven Yi ha scritto:

      Hi Mauro,

      I implemented a UDO for randcubic to generate bipolar cubically
      interpolated random line with kamp and kfreq arguments.  The code,
      example CSD, and audio example are available here:

https://kunstmusik.com/2019/09/23/randcubic-glissandi-random-line-with-cubic-
      interpolation/

      Just a note that cubic interpolation can overshoot boundaries.

      Hope this helps!
      steven


      On Mon, Sep 23, 2019 at 12:50 PM Mauro Giubileo
      <mgiubileo@computeraltafed.it> wrote:

            I'm playing with randomic sound generation. I noticed
            two useful opcodes that makes me set the frequency of
            the generation of the numbers: randh, randi. That's
            very nice.

            The first (randh) generates some horizontal lines
            between the generated points, so you'll have a
            "step"-style random sequence.

            The second opcode (randi) is similar but it produces
            straight-line interpolation between each new number
            and the next, instead of just holding the values.

            Now I'm wondering: is it possible to make something
            similar to the two above opcodes but with a cubic
            interpolation between every two points instead of a
            linear interpolation? I would like to generate a
            smoothly interpolated curve from the generated random
            points, instead of a step-style curve or a
            linear-interpolated curve... How can I do that?

            ---
            Mauro


            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


Date2019-09-27 21:34
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
My opcode seems t run but I am having trouble devising a real test.  With 
Steven's example the overall shape is the same but the amplitude varies, 
and the randi example in the manual is similar to the equivalent randc 
output but the cubic one is less varied.

Can anyone devise a suitable set of tests?

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

Date2019-09-28 14:41
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

I think it's difficult to make some accurate test when you are dealing with randomic generation. We should give a list of conditions that should be always filled and then check if this is true, but... What are these conditions?

In the case of rand/randi/randh I've identified the following conditions:

1) iSeed in [0, 1] will produce an initial output of "kAmp * iSeed";
2) output should always be between -amp and +amp.
3) If iSeed > 1, the random generation should be always different at each run.

With my last mods, 1 and 3 are satisfied, but 2 is not. It's trivial to ensure that with linear interpolation, but with cubic interpolation is another story... Of course I could simply cut all the values bigger than +amp or smaller than -amp, but that would mean an audible distortion in the audio signal.

---
Mauro

Il 2019-09-27 22:34 john ha scritto:

My opcode seems t run but I am having trouble devising a real test.  With Steven's example the overall shape is the same but the amplitude varies, and the randi example in the manual is similar to the equivalent randc output but the cubic one is less varied.

Can anyone devise a suitable set of tests?

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

Date2019-09-28 14:51
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
Can yu build from source?  If so I could commit my opcode to github and 
you could investigate.

On Sat, 28 Sep 2019, Mauro Giubileo wrote:

> 
> I think it's difficult to make some accurate test when you are dealing with
> randomic generation. We should give a list of conditions that should be always
> filled and then check if this is true, but... What are these conditions?
> 
> In the case of rand/randi/randh I've identified the following conditions:
> 
> 1) iSeed in [0, 1] will produce an initial output of "kAmp * iSeed";
> 2) output should always be between -amp and +amp.
> 3) If iSeed > 1, the random generation should be always different at each run.
> 
> With my last mods, 1 and 3 are satisfied, but 2 is not. It's trivial to ensure
> that with linear interpolation, but with cubic interpolation is another
> story... Of course I could simply cut all the values bigger than +amp or
> smaller than -amp, but that would mean an audible distortion in the audio
> signal.
> 
> ---
> Mauro
> 
> Il 2019-09-27 22:34 john ha scritto:
>
>       My opcode seems t run but I am having trouble devising a real
>       test.  With Steven's example the overall shape is the same but the
>       amplitude varies, and the randi example in the manual is similar
>       to the equivalent randc output but the cubic one is less varied.
>
>       Can anyone devise a suitable set of tests?
>

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

Date2019-09-28 15:06
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

Currently I have not a working csound development environment to build from source... If you make a test binary version I can try it. I'm on Windows.

---
Mauro

 


Il 2019-09-28 15:51 john ha scritto:

Can yu build from source?  If so I could commit my opcode to github and you could investigate.

On Sat, 28 Sep 2019, Mauro Giubileo wrote:


I think it's difficult to make some accurate test when you are dealing with
randomic generation. We should give a list of conditions that should be always
filled and then check if this is true, but... What are these conditions?

In the case of rand/randi/randh I've identified the following conditions:

1) iSeed in [0, 1] will produce an initial output of "kAmp * iSeed";
2) output should always be between -amp and +amp.
3) If iSeed > 1, the random generation should be always different at each run.

With my last mods, 1 and 3 are satisfied, but 2 is not. It's trivial to ensure
that with linear interpolation, but with cubic interpolation is another
story... Of course I could simply cut all the values bigger than +amp or
smaller than -amp, but that would mean an audible distortion in the audio
signal.

---
Mauro

Il 2019-09-27 22:34 john ha scritto:

      My opcode seems t run but I am having trouble devising a real
      test.  With Steven's example the overall shape is the same but the
      amplitude varies, and the randi example in the manual is similar
      to the equivalent randc output but the cubic one is less varied.

      Can anyone devise a suitable set of tests?

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

Date2019-09-28 16:18
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
As you are on Windows I will commit the code as-is and appveyor will build 
a version.  May take a short while.

It adds opcode randc with same arguments as randi; otherwise no 
documentation yet.  Not sure it is te sane as your UDO yet.  In particular 
I am uncertain that I interpref the frequency correctly.


On Sat, 28 Sep 2019, Mauro Giubileo wrote:

> 
> Currently I have not a working csound development environment to build from
> source... If you make a test binary version I can try it. I'm on Windows.
> 
> ---
> Mauro
> 
>  
> 
> 
> Il 2019-09-28 15:51 john ha scritto:
>
>       Can yu build from source?  If so I could commit my opcode to
>       github and you could investigate.
>
>       On Sat, 28 Sep 2019, Mauro Giubileo wrote:
> 
>
>             I think it's difficult to make some accurate test when you are dealing with
> randomic generation. We should give a list of conditions that should be alway
>             s
>             filled and then check if this is true, but... What are these conditions?
>
>             In the case of rand/randi/randh I've identified the following conditions:
>
>             1) iSeed in [0, 1] will produce an initial output of "kAmp * iSeed";
>             2) output should always be between -amp and +amp.
> 3) If iSeed > 1, the random generation should be always different at each run
>             .
> 
> With my last mods, 1 and 3 are satisfied, but 2 is not. It's trivial to ensur
>             e
>             that with linear interpolation, but with cubic interpolation is another
>             story... Of course I could simply cut all the values bigger than +amp or
>             smaller than -amp, but that would mean an audible distortion in the audio
>             signal.
>
>             ---
>             Mauro
>
>             Il 2019-09-27 22:34 john ha scritto:
>
>                   My opcode seems t run but I am having trouble devising a real
>                   test.  With Steven's example the overall shape is the same but the
>                   amplitude varies, and the randi example in the manual is similar
>                   to the equivalent randc output but the cubic one is less varied.
>
>                   Can anyone devise a suitable set of tests?
> 
>
>       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

Date2019-09-28 17:25
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
Seems to have built; Windows system available from

https://ci.appveyor.com/project/csound/csound/buid/artifacts

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

Date2019-09-28 20:13
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

Hi John, thanks. I tried with something like that:

instr 1

    a1      randc   1, sr, 0.5
            printk  1, a1[0]
            printk  1, a1[1]
            printk  1, a1[2]
            
endin

but it prints always the same initial value and it never changes...

---
Mauro

 


Il 2019-09-28 18:25 john ha scritto:

Seems to have built; Windows system available from

https://ci.appveyor.com/project/csound/csound/buid/artifacts

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

Date2019-09-28 20:50
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
OK; clearly this is worse than I thought.  Will try again......

On Sat, 28 Sep 2019, Mauro Giubileo wrote:

> 
> Hi John, thanks. I tried with something like that:
> 
> instr 1
> 
>     a1      randc   1, sr, 0.5
>             printk  1, a1[0]
>             printk  1, a1[1]
>             printk  1, a1[2]
>             
> endin
> 
> but it prints always the same initial value and it never changes...
> 
> ---
> Mauro

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

Date2019-09-29 14:06
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
I ave a new and bwtte version now.  avalable from
https://ci.appveyor.com/project/csound/csound/build/artifacts

Not sure it is right but is better!
\

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

Date2019-09-29 21:57
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?
Attachmentsrandc.png  

Hi John, this version works.

The output is nearly identical to my last version of the Steven's UDO, but, strangely, it has a different phase and so the first generated value is different from kAmp * iSeed. I attached a picture with a waveform printed from my udo output and then from your opcode. Anyway, very thanks for the opcode!

---
Mauro


Il 2019-09-29 15:06 john ha scritto:

I ave a new and bwtte version now.  avalable from
https://ci.appveyor.com/project/csound/csound/build/artifacts

Not sure it is right but is better!
\

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

Date2019-09-30 15:43
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
The difference is in the initialisation of the 4 rando numbers  The udo 
geerates 3 of them them before the seed is set (I think) while my C code 
generates all four after the seed is used.  I could change this but it 
woud be untidy code for not muvch gain in my opinion.

If you are happy wit it as it is I wil document it.

==John

On Sun, 29 Sep 2019, Mauro Giubileo wrote:

> 
> Hi John, this version works.
> 
> The output is nearly identical to my last version of the Steven's UDO, but,
> strangely, it has a different phase and so the first generated value is
> different from kAmp * iSeed. I attached a picture with a waveform printed from
> my udo output and then from your opcode. Anyway, very thanks for the opcode!
> 
> ---
> Mauro
> 
>

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

Date2019-09-30 18:42
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

Hi John, about your opcode, for now the only issue that could give me some trouble is that the first generated value is different from "kAmp * iSeed", so it doesn't satisfy one of those requirements I described before. If you could fix this, I think it would be more consistent with with the current randi/randh behavior.

The cubic interpolation algorithm needs 4 values to start the random sequence. When iSeed<=1 the UDO uses iSeed for the initialization of 3 random values. The fourth value (in the UDO is named "ky1") is set to "kAmp * iSeed". Then the UDO uses always the same seed value for the subsequent randomic generations (in "rand:k(1, iSeed)").

---
Mauro

 


Il 2019-09-30 16:43 john ha scritto:

The difference is in the initialisation of the 4 rando numbers  The udo geerates 3 of them them before the seed is set (I think) while my C code generates all four after the seed is used.  I could change this but it woud be untidy code for not muvch gain in my opinion.

If you are happy wit it as it is I wil document it.

==John

On Sun, 29 Sep 2019, Mauro Giubileo wrote:


Hi John, this version works.

The output is nearly identical to my last version of the Steven's UDO, but,
strangely, it has a different phase and so the first generated value is
different from kAmp * iSeed. I attached a picture with a waveform printed from
my udo output and then from your opcode. Anyway, very thanks for the opcode!

---
Mauro


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

Date2019-09-30 18:48
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

Now that I re-read my last mail, maybe it was not clear that the first output of the UDO when iSeed<=1 is "kAmp * iSeed", like in randi/randh.

---
Mauro

 


Il 2019-09-30 19:42 Mauro Giubileo ha scritto:

Hi John, about your opcode, for now the only issue that could give me some trouble is that the first generated value is different from "kAmp * iSeed", so it doesn't satisfy one of those requirements I described before. If you could fix this, I think it would be more consistent with with the current randi/randh behavior.

The cubic interpolation algorithm needs 4 values to start the random sequence. When iSeed<=1 the UDO uses iSeed for the initialization of 3 random values. The fourth value (in the UDO is named "ky1") is set to "kAmp * iSeed". Then the UDO uses always the same seed value for the subsequent randomic generations (in "rand:k(1, iSeed)").

---
Mauro

 


Il 2019-09-30 16:43 john ha scritto:

The difference is in the initialisation of the 4 rando numbers  The udo geerates 3 of them them before the seed is set (I think) while my C code generates all four after the seed is used.  I could change this but it woud be untidy code for not muvch gain in my opinion.

If you are happy wit it as it is I wil document it.

==John

On Sun, 29 Sep 2019, Mauro Giubileo wrote:


Hi John, this version works.

The output is nearly identical to my last version of the Steven's UDO, but,
strangely, it has a different phase and so the first generated value is
different from kAmp * iSeed. I attached a picture with a waveform printed from
my udo output and then from your opcode. Anyway, very thanks for the opcode!

---
Mauro

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


Date2019-10-01 18:36
Fromjohn
SubjectRe: [Csnd] rand with cubic interpolation?
On Mon, 30 Sep 2019, Mauro Giubileo wrote:

> 
> Hi John, about your opcode, for now the only issue that could give me some
> trouble is that the first generated value is different from "kAmp * iSeed", so
> it doesn't satisfy one of those requirements I described before. If you could
> fix this, I think it would be more consistent with with the current
> randi/randh behavior.


The seed is not thestarting value in randi in all cases. If youuse the 
31but PRNG it starts after two rounds .

In te case of ranc the initial values will always be the second random 
number.  Icould adhjust so it is always the first random nmber so being 
the seed in the old PRNG case.  Would that realy make a difference?

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

Date2019-10-02 11:32
FromMauro Giubileo
SubjectRe: [Csnd] rand with cubic interpolation?

Hi John, I think that if the first value in the output vector could be "kAmp * iSeed" it would be a little better, because there could be some applications where you want to be sure that just the first starting number is not random (for example, maybe you want to generate values starting from the end of a different signal... In this case you would start from the last value of the previous signal, to avoid sudden jumps, i.e. unwanted noise).

---
Mauro

 


Il 2019-10-01 19:36 john ha scritto:

On Mon, 30 Sep 2019, Mauro Giubileo wrote:


Hi John, about your opcode, for now the only issue that could give me some
trouble is that the first generated value is different from "kAmp * iSeed", so
it doesn't satisfy one of those requirements I described before. If you could
fix this, I think it would be more consistent with with the current
randi/randh behavior.


The seed is not thestarting value in randi in all cases. If youuse the 31but PRNG it starts after two rounds .

In te case of ranc the initial values will always be the second random number.  Icould adhjust so it is always the first random nmber so being the seed in the old PRNG case.  Would that realy make a difference?

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