Csound Csound-dev Csound-tekno Search About

[Csnd] Another newbie question regarding random read of table

Date2022-08-24 21:14
FromScott Daughtrey
Subject[Csnd] Another newbie question regarding random read of table
I'm going thru Chapter 3 of the FLOSS manual, working on 03D (Function Tables). I decided to revisit a previous ex. from the manual (01D13) as I have a little better understanding now.

Line 26 reads:
iNote table rnd(1),giNotes,1

I understand that the table index is being read as normalized due to the final "1" being the index data mode. If it is altered to 0 it now reads as raw, however when played that way the note never changes, but I don't understand why. Below is a slightly modified csd:



-odac -m0


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

;seed 0

giNotes ftgen   0,0,-100,-17,0,48, 15,53, 30,55, 40,60, 50,63, 
                60,65, 79,67, 85,70, 90,72, 96,75
giDurs  ftgen   0,0,-100,-17,0,2, 30,0.5, 75,1, 90,1.5

  instr 1
kDur  init        1         ; initial rhythmic duration
kTrig metro       2/kDur      ; metronome freq. 2 times inverse of duration
kNdx  trandom     kTrig,0,1   ; create a random index upon each metro 'click'
kDur  table       kNdx,giDurs,1   ; read a note duration value
      schedkwhen  kTrig,0,0,2,0,1,p4,p5; trigger a note!
  endin

  instr 2
iNote table rnd(1),giNotes,1 ; read a random value from the function table
aEnv  linsegr   0, 0.005, p5, p3-0.105, p5, 2, 0 ; amplitude envelope
iPlk  random    0.1, 0.3 ; point at which to pluck the string
iDtn  random    -0.05, 0.05 ; random detune
aSig  wgpluck2  0.98, 0.2, cpsmidinn(iNote+p4+iDtn), iPlk, 0.06
      out       aSig * aEnv
  endin



i 1  0 16  0  .8
e


;example by Iain McCurdy

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

Date2022-08-24 21:32
From"Jeanette C."
SubjectRe: [Csnd] Another newbie question regarding random read of table
Hi Scott!
Aug 24 2022, Scott Daughtrey has written:
...
> I understand that the table index is being read as normalized due to the final "1" being the index data mode. 
> If it is altered to 0 it now reads as raw, however when played that way the note never changes, but I don't understand why.
Because you still retain rnd(1), which will generate a random number
between 0 and 1. To get different notes use a range of 99 and to make
sure you get only exact values as stored in the table round the number
or use the int opcode to only get an integral place and not something
like the 17.57th note:
iNote = table(round(rnd(99)), giNotes, 0)
If you use the int opcode, I sugest a range of 99.9 or something,
because int will return the integral part of the number, the part before
the decimal point. With 99.9 you'll get a fair chance of reading the
last note as well.

Why 99? Because in raw mode indices are counted from 0. So if 0 is the
first note, then 99 is the 100th note.

Btw. in the example below you still appear to use the original
normalised index.
...
> iNote table rnd(1),giNotes,1 ; read a random value from the function table
...

HTH, best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

All you people look at me like I'm a little girl.
Well did you ever think it be okay for me to step into this world. <3
(Britney Spears)

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

Date2022-08-24 22:00
FromST Music
SubjectRe: [Csnd] Another newbie question regarding random read of table
Thank you for the explanation Jeanette, that makes complete sense now. In this particular case it appears it's not necessary to use round or the int opcode as the table being read is Gen17 which states "This subroutine creates a step function of x-y pairs whose y-values are held to the right." .
 
It doesn't appear that integers have any effect, however I'll try to keep that suggestion in mind for the future. 

And yes, I left the index normalised so anyone playing the file would hear it correctly and could then alter the index mode to 0 to hear the difference. Good catch!

Thanks again. 

On Wed, Aug 24, 2022, 4:34 PM Jeanette C., <julien@mail.upb.de> wrote:
Hi Scott!
Aug 24 2022, Scott Daughtrey has written:
...
> I understand that the table index is being read as normalized due to the final "1" being the index data mode.
> If it is altered to 0 it now reads as raw, however when played that way the note never changes, but I don't understand why.
Because you still retain rnd(1), which will generate a random number
between 0 and 1. To get different notes use a range of 99 and to make
sure you get only exact values as stored in the table round the number
or use the int opcode to only get an integral place and not something
like the 17.57th note:
iNote = table(round(rnd(99)), giNotes, 0)
If you use the int opcode, I sugest a range of 99.9 or something,
because int will return the integral part of the number, the part before
the decimal point. With 99.9 you'll get a fair chance of reading the
last note as well.

Why 99? Because in raw mode indices are counted from 0. So if 0 is the
first note, then 99 is the 100th note.

Btw. in the example below you still appear to use the original
normalised index.
...
> iNote table rnd(1),giNotes,1 ; read a random value from the function table
...

HTH, best wishes,

Jeanette

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

All you people look at me like I'm a little girl.
Well did you ever think it be okay for me to step into this world. <3
(Britney Spears)

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

Date2022-08-24 22:17
From"Jeanette C."
SubjectRe: [Csnd] Another newbie question regarding random read of table
Aug 24 2022, ST Music has written:
...
> In this particular case it appears it's not necessary to use round or the int
> opcode as the table being read is Gen17 which states "This subroutine
> creates a step function of x-y pairs whose y-values are held to the right."
...
The cases where it makes a difference are rare, depending on the number
of steps. You will encounter them at each border, where adjecent values
are different. So not very important here, but you might get a surprise
now and then. :)

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

All you people look at me like I'm a little girl.
Well did you ever think it be okay for me to step into this world. <3
(Britney Spears)

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

Date2022-09-07 16:35
FromJohn ff
SubjectRe: [Csnd] Another newbie question regarding random read of table


On 24 Aug 2022, at 21:35, "Jeanette C." <julien@mail.upb.de> wrote:
Hi Scott!
Aug 24 2022, Scott Daughtrey has written:
...
I understand that the table index is being read as normalized due to the final "1" being the index data mode.
If it is altered to 0 it now reads as raw, however when played that way the note never changes, but I don't understand why.
Because you still retain rnd(1), which will generate a random number
between 0 and 1. To get different notes use a range of 99 and to make
sure you get only exact values as stored in the table round the number
or use the int opcode to only get an integral place and not something
like the 17.57th note:
iNote = table(round(rnd(99)), giNotes, 0)
If you use the int opcode, I sugest a range of 99.9 or something,
because int will return the integral part of the number, the part before
the decimal point. With 99.9 you'll get a fair chance of reading the
last note as well.

Why 99? Because in raw mode indices are counted from 0. So if 0 is the
first note, then 99 is the 100th note.

Btw. in the example below you still appear to use the original
normalised index.
...
iNote table rnd(1),giNotes,1 ; read a random value from the function table
...

HTH, best wishes,

Jeanette