Csound Csound-dev Csound-tekno Search About

[Csnd] setting a-rate array in a loop

Date2020-02-05 20:04
FromAndie Sigler
Subject[Csnd] setting a-rate array in a loop
Attachmentsmode_x.csd  
Hello,
I'd really appreciate some help in writing a loop to set the values in an a-rate array.

In the attached csound file, the following block doesn't work:

indx = 0
until indx >= lenarray(aexc) do
aexc[indx]  mode ashock, iexc_freq_arr[indx], iexc_Q[indx]
indx += 1
od


but replaced with the following (supposedly equivalent), it DOES work

aexc[0] mode ashock, iexc_freq_arr[0], iexc_Q[0]
aexc[1] mode ashock, iexc_freq_arr[1], iexc_Q[1]


I know there's something funny about using an i-rate index to set a-rate variables, but i'm not sure how to write it as a loop so that it works. (Obviously a loop is desirable in order to use variable length input arrays).


Thanks!
Andie

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

Date2020-02-05 20:23
FromEduardo Moguillansky
SubjectRe: [Csnd] setting a-rate array in a loop

Using "poly" opcode you can

ilen = lenarray(iecc_freq_arr)
aexc[] poly ilen, "mode", ashock, iexc_freq_arr, iexc_Q

https://github.com/csound-plugins/csound-plugins

cheers
eduardo

On 05.02.20 21:04, Andie Sigler wrote:
Hello,
I'd really appreciate some help in writing a loop to set the values in an a-rate array.

In the attached csound file, the following block doesn't work:

indx = 0
until indx >= lenarray(aexc) do
aexc[indx]  mode ashock, iexc_freq_arr[indx], iexc_Q[indx]
indx += 1
od


but replaced with the following (supposedly equivalent), it DOES work

aexc[0] mode ashock, iexc_freq_arr[0], iexc_Q[0]
aexc[1] mode ashock, iexc_freq_arr[1], iexc_Q[1]


I know there's something funny about using an i-rate index to set a-rate variables, but i'm not sure how to write it as a loop so that it works. (Obviously a loop is desirable in order to use variable length input arrays).


Thanks!
Andie

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

Date2020-02-05 21:02
Fromjoachim heintz
SubjectRe: [Csnd] setting a-rate array in a loop
hi andie -

the problem is not the loop, but that you only have one instance of the 
mode opcode in your loop.  one option is what eduardo showed with his 
poly plugin.  i would perhaps use another architecture of the program: 
rather than one instrument which does everything, you could have two 
instruments.  the first one is calling the second one in a loop, and the 
second one is performing the audio with mode.

if you want to keep everything in one instrument, you could use a 
recursive udo:

sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1
gi_iexc_mode0  ftgen  1, 0, -2, -2, 1., 3.
gi_iexc_Q0  ftgen  2, 0, -2, -2, 12, 8
gi_kpan0  ftgen  3, 0, 1335, -27, 0, 0.5, 1334, 0.5

opcode mode_mult, a[], a[]ai[]i[]o
  aexc[], ashock, iexc_freq_arr[], iexc_Q[], indx xin
  aexc[indx]  mode ashock, iexc_freq_arr[indx], iexc_Q[indx]
  if indx+1 < lenarray(aexc) then
   aexc mode_mult aexc, ashock, iexc_freq_arr, iexc_Q, indx+1
  endif
  xout aexc
endop

instr mode_x
kndx line 0, p3, 1
iamp =  p4
iexc_freq =  p5
kpan  table  kndx, p8, 1
iexc_mode[]  init  ftlen(p6)
copyf2array  iexc_mode, p6
iexc_Q[]  init  ftlen(p7)
copyf2array  iexc_Q, p7
ashock  mpulse  3., 0.
iexc_freq_arr[] = iexc_mode * iexc_freq
aexc[] init lenarray(iexc_freq_arr)

aexc mode_mult aexc, ashock, iexc_freq_arr, iexc_Q

aexc_sum = sumarray(aexc)
aexc_avg = aexc_sum / lenarray(aexc)
aOut = aexc_avg
aL, aR pan2 aOut, kpan
outs aL, aR
endin

ciao -
	joachim

On 05/02/2020 21:04, Andie Sigler wrote:
> Hello,
> I'd really appreciate some help in writing a loop to set the values in 
> an a-rate array.
> 
> In the attached csound file, the following block doesn't work:
> 
> indx = 0
> until indx >= lenarray(aexc) do
> aexc[indx]  mode ashock, iexc_freq_arr[indx], iexc_Q[indx]
> indx += 1
> od
> 
> 
> but replaced with the following (supposedly equivalent), it DOES work
> 
> aexc[0] mode ashock, iexc_freq_arr[0], iexc_Q[0]
> aexc[1] mode ashock, iexc_freq_arr[1], iexc_Q[1]
> 
> 
> I know there's something funny about using an i-rate index to set a-rate 
> variables, but i'm not sure how to write it as a loop so that it works. 
> (Obviously a loop is desirable in order to use variable length input 
> arrays).
> 
> 
> Thanks!
> Andie
> 
> 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

Date2020-02-05 21:03
Fromjohn
SubjectRe: [Csnd] setting a-rate array in a loop
The poblem is that in the loop code there is only one mode keeping state. 
The "expanded" version has 2 mode instances.

This comes up repeatedly (sorry) which is why some peole did nt want to 
allow lops.

The poly extension is one appraoch to a fix.

==John ff

On Wed, 5 Feb 2020, Andie Sigler wrote:

> Hello,
> I'd really appreciate some help in writing a loop to set the values in an
> a-rate array.
> 
> In the attached csound file, the following block doesn't work:
> 
> indx = 0
> until indx >= lenarray(aexc) do
> aexc[indx]  mode ashock, iexc_freq_arr[indx], iexc_Q[indx]
> indx += 1
> od
> 
> 
> but replaced with the following (supposedly equivalent), it DOES work
> 
> aexc[0] mode ashock, iexc_freq_arr[0], iexc_Q[0]
> aexc[1] mode ashock, iexc_freq_arr[1], iexc_Q[1]
> 
> 
> I know there's something funny about using an i-rate index to set a-rate
> variables, but i'm not sure how to write it as a loop so that it works.
> (Obviously a loop is desirable in order to use variable length input arrays).
> 
> 
> Thanks!
> Andie
> 
> 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

Date2020-02-06 05:10
FromAndie
SubjectRe: [Csnd] setting a-rate array in a loop
Very helpful. Thanks so much everyone!



--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

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