[Csnd] Dynamically naming variables
| Date | 2013-02-11 12:36 |
| From | Anders Genell |
| Subject | [Csnd] Dynamically naming variables |
|
Hi list! I am wondering if someone know of a way to dynamically name variables? What I want to do is typically create filter coeffs in e.g. matlab, save them to a text file and GEN23 them into an ftable, which all works very well, then I want to read one coeff at a time as argument to e.g. filter2. So, ;read filtercoeffs from matlab into tables gibcoeff ftgen 5, 0, 0, -23, "matlab_b_coeff.txt" giacoeff ftgen 6, 0, 0, -23, "matlab_a_coeff.txt" is all good and well, but depending of my system analysis in matlab, the length of the tables can vary. I can of course check with ftlen, but how do I do something like kb0 tab 0, 5 kb1 tab 1, 5 kb2 tab 2, 5 ka1 tab 1, 6 ka2 tab 2, 6 dynamically so that I can read all coeffs in the tables regardless of length? something like (in pseudo-ish csound code) kindx init 0 loop: kb_coeff[insert dynamic num 2 variable name] tab kindx, 5 kindx = kindx +1 if (kindx < ftlen(5)) kgoto loop And how to call filter2 with dioferent number of coeffs? ares filter2 asig, ftlen(5), ftlen(6=, i(kb0), i(kb1), ..., ia1, ia2, ..., iaN
Any ideas?
Thanks!!
Best regards,
/Anders
|
| Date | 2013-02-11 13:33 |
| From | Victor Lazzarini |
| Subject | Re: [Csnd] Dynamically naming variables |
tvars? t1 init 4 k1 init 0 until k1 < 4 do k2 table k1, 1 t[k1] = k2 k1 = k1 +1 od Victor On 11 Feb 2013, at 12:36, Anders Genell wrote: > Hi list! > > I am wondering if someone know of a way to dynamically name variables? > > What I want to do is typically create filter coeffs in e.g. matlab, save them to a text file and GEN23 them into an ftable, which all works very well, then I want to read one coeff at a time as argument to e.g. filter2. > > So, > > ;read filtercoeffs from matlab into tables > gibcoeff ftgen 5, 0, 0, -23, "matlab_b_coeff.txt" > giacoeff ftgen 6, 0, 0, -23, "matlab_a_coeff.txt" > > is all good and well, but depending of my system analysis in matlab, the length of the tables can vary. > > I can of course check with ftlen, but how do I do something like > > kb0 tab 0, 5 > kb1 tab 1, 5 > kb2 tab 2, 5 > > ka1 tab 1, 6 > ka2 tab 2, 6 > > dynamically so that I can read all coeffs in the tables regardless of length? > > something like (in pseudo-ish csound code) > > kindx init 0 > > loop: > kb_coeff[insert dynamic num 2 variable name] tab kindx, 5 > kindx = kindx +1 > > if (kindx < ftlen(5)) kgoto loop > > And how to call filter2 with dioferent number of coeffs? > > ares filter2 asig, ftlen(5), ftlen(6=, i(kb0), i(kb1), ..., ia1, ia2, ..., iaN > > > Any ideas? > > Thanks!! > > Best regards, > /Anders > > > Dr Victor Lazzarini Senior Lecturer Dept. of Music NUI Maynooth Ireland tel.: +353 1 708 3545 Victor dot Lazzarini AT nuim dot ie |
| Date | 2013-02-11 18:38 |
| From | Anders Genell |
| Subject | Re: [Csnd] Dynamically naming variables |
On 2013-02-11 14:33, Victor Lazzarini wrote: > t1 init 4 > k1 init 0 > until k1 < 4 do > k2 table k1, 1 > t[k1] = k2 > k1 = k1 +1 > od Brilliant, thanks!! I have not really used t-vars before so this didn't really occur to me... They don't happen to be useable directly as in ares filter2 ain, ftlen(5), ftlen(6), t_acoeffs, t_bcoeffs do they? If not, that would be my two cents as requested feature for csound6... I suppose I could figure something out using strcatk, spfrintfk, and perhaps some macro? Best regards, /Anders |
| Date | 2013-02-11 18:44 |
| From | Victor.Lazzarini@nuim.ie |
| Subject | Re: [Csnd] Dynamically naming variables |
| Attachments | None None |
| Date | 2013-02-11 19:55 |
| From | Anders Genell |
| Subject | Re: [Csnd] Dynamically naming variables |
Just to let you know, I took the lazy way out and had matlab do the
dirty work.
In matlab
[b,a]=butter(2,2*fc/fs);
csvwrite('coeffs.txt',[length(b) length(a)-1 b a(2:end)])
...and in another m-file
fid=fopen('coeffs.txt','r');
coeffs=fread(fid);
coeffs=char(coeffs)';
system(['csound -d -W -o out.wav --omacro:COEFFS=' coeffs ' my_csd.csd'])
and in csound
ares filter2 ain, $COEFFS
Best regards,
/Anders
On 2013-02-11 19:44, Victor.Lazzarini@nuim.ie wrote:
> There is set of operations for them. You can assign them to kvars etc.
> In csound6 there are generalized arrays, so there you can use them
> directly.
>
>
>
>
> ----- Original Message -----
> From: Anders Genell |