electro-music.org   Dedicated to experimental electro-acoustic
and electronic music
 
 Front Page  |  Radio  |  Forum  |  Media  |  Playlists  |  Wiki
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
LFO filter frequency
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [12 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
otloader



Joined: Jan 10, 2011
Posts: 6
Location: Bournemouth

PostPosted: Mon Jan 10, 2011 8:57 am    Post subject: LFO filter frequency Reply with quote  Mark this post and the followings unread

hi there, im new to chuck but not to programming, though i wouldnt say i was very good at it! This is part of a uni assignment, im trying to get the LFO to talk to the LPF filter, with no success...dont worry about the rest of the code, i know its not exactly tidy, but can anyone see where im going wrong?

//score-multidimensional array

int score[20][20];
52=> score[0][0];
52=>score[1][0];
1000=>score[2][0];
52=>score[3][0];
52=>score[4][0];
1000=>score[5][0];
54=>score[6][0];
52=>score[7][0];
54=>score[8][0];
56=>score[9][0];
58=>score[10][0];
500=>score[0][1];
250=>score[1][1];
500=>score[2][1];
125=>score[3][1];
500=>score[4][1];
500=>score[5][1];
250=>score[6][1];
500=>score[7][1];
500=>score[8][1];
500=>score[9][1];
500=>score[10][1];


int score2[7][7];
52=> score2[0][0];
52=>score2[1][0];
1000=>score2[2][0];
52=>score2[3][0];
52=>score2[4][0];
1000=>score2[5][0];
73=>score2[6][0];
500=>score2[0][1];
250=>score2[1][1];
500=>score2[2][1];
125=>score2[3][1];
500=>score2[4][1];
500=>score2[5][1];
250=>score2[6][1];
Event exit;



fun void instrument(int scorearray[][])
{ //dsp code
SinOsc m => SqrOsc c => Gain g => LPF lp=> dac;
SawOsc c2=> g;

//lfo osc
SinOsc lfo=> blackhole;
5=>lfo.freq;

//gain parameters
.5 =>g.gain;
0.5=> c.gain;

//filter parameters
1000. =>float center_filter_frequency;


// modulator frequency
Std.rand2f (0, 10) => m.freq;

// index of modulation
0 => m.gain;
2 => c.sync;



spork~lfofilter();



//for loop plays thru score
for(0=> int k; k < scorearray.size(); k++)
{
Std.mtof(scorearray[k][0])=>c.freq=>c2.freq;
<<<c.freq()>>>;
//convert int into dur
scorearray[k][1]*2::ms=>now;
}

fun void lfofilter()
{
while (true)
{
(lfo.last()*500) + center_filter_frequency =>lp.freq;
100::ms=>now;
}
}


exit.broadcast();
}

spork~instrument(score);
exit => now;

any help would be much appreciated!
Code:
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Mon Jan 10, 2011 9:24 am    Post subject: Reply with quote  Mark this post and the followings unread

Hm, looks right. I've had some weird effects caused by things being in the wrong order occasionally. Maybe try moving the spork of lfoFilter below the function declaration?

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
otloader



Joined: Jan 10, 2011
Posts: 6
Location: Bournemouth

PostPosted: Mon Jan 10, 2011 9:28 am    Post subject: Reply with quote  Mark this post and the followings unread

its giving me a syntax error on the "fun void lfofilter()" line, but cannot for the life of me figure out why, ive tried what you said, but it still doesnt like it
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Mon Jan 10, 2011 9:36 am    Post subject: Reply with quote  Mark this post and the followings unread

Hey, I think you've lost a curly end bracket at the end of the instrument function. Is that it? ChucK thinks you're trying to define lfofilter inside another function.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
otloader



Joined: Jan 10, 2011
Posts: 6
Location: Bournemouth

PostPosted: Mon Jan 10, 2011 9:50 am    Post subject: Reply with quote  Mark this post and the followings unread

that was part of it...i think the problem is that my dsp functions arent global, they are in the instrument function, but 2 functions need to access them..i think i may be missing something obvious here, but do you think thats part of it?
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Mon Jan 10, 2011 9:55 am    Post subject: Reply with quote  Mark this post and the followings unread

Hmm, I didn't think declaring functions inside other functions was possible. Maybe you want to use a class instead?

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
otloader



Joined: Jan 10, 2011
Posts: 6
Location: Bournemouth

PostPosted: Mon Jan 10, 2011 10:01 am    Post subject: Reply with quote  Mark this post and the followings unread

sorry, my language is a bit off sometimes..didnt mean DSP "functions" ...all my oscilators and effects are in the instrument function, but lfo function and instrument function need access to them...lfo function doesnt know theyre there.."undefined variable"...do you get what i mean or am i just giving you a headache?
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Mon Jan 10, 2011 1:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

Sorry, had to go offline for a bit there.

Yeah, I'm not sure what you're aiming at, heh. :) Anyway, I moved some code around and got it running (see below). The first culprit was the fact that you are declaring lfofilter inside the function called instrument. That doesn't work - ChucK doesn't support declaring functions inside functions. So I moved the curly just before "exit.broadcast()" so it's above the lfofilter function.

This reveals some errors because lfofilder tries to access variables that are declared inside instrument(). So I moved those variables to just above the instrument function, making them global. That got it running.

If you want to hide these variables so you can run this code as a kind of module, you can wrap the global variables and functions with a class declaration, that you can instantiate. You don't need to though, I work with global variables and functions like this all the time. So long as I don't feel like I'll want to import it elsewhere or call the code from other chuck files, it works fine.


Code:
//score-multidimensional array

int score[20][20];
52=> score[0][0];
52=>score[1][0];
1000=>score[2][0];
52=>score[3][0];
52=>score[4][0];
1000=>score[5][0];
54=>score[6][0];
52=>score[7][0];
54=>score[8][0];
56=>score[9][0];
58=>score[10][0];
500=>score[0][1];
250=>score[1][1];
500=>score[2][1];
125=>score[3][1];
500=>score[4][1];
500=>score[5][1];
250=>score[6][1];
500=>score[7][1];
500=>score[8][1];
500=>score[9][1];
500=>score[10][1];


int score2[7][7];
52=> score2[0][0];
52=>score2[1][0];
1000=>score2[2][0];
52=>score2[3][0];
52=>score2[4][0];
1000=>score2[5][0];
73=>score2[6][0];
500=>score2[0][1];
250=>score2[1][1];
500=>score2[2][1];
125=>score2[3][1];
500=>score2[4][1];
500=>score2[5][1];
250=>score2[6][1];
Event exit;


SinOsc m => SqrOsc c => Gain g => LPF lp=> dac;
SawOsc c2=> g;

//lfo osc
SinOsc lfo=> blackhole;
5=>lfo.freq;

//filter parameters
1000. =>float center_filter_frequency;
   
fun void instrument(int scorearray[][])
{ //dsp code
   
   
   //gain parameters
   .5 =>g.gain;
   0.5=> c.gain;
   
   
   // modulator frequency
   Std.rand2f (0, 10) => m.freq;
   
   // index of modulation
   0 => m.gain;
   2 => c.sync;
   
   spork~lfofilter();

   //for loop plays thru score
   for(0=> int k; k < scorearray.size(); k++)
   {
      Std.mtof(scorearray[k][0])=>c.freq=>c2.freq;
      <<<c.freq()>>>;
      //convert int into dur
      scorearray[k][1]*2::ms=>now;
   }
}

fun void lfofilter()
{
   while (true)
   {
      (lfo.last()*500) + center_filter_frequency =>lp.freq;
      100::ms=>now;
   }
}


exit.broadcast();

spork~instrument(score);
exit => now;

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
otloader



Joined: Jan 10, 2011
Posts: 6
Location: Bournemouth

PostPosted: Tue Jan 11, 2011 10:08 am    Post subject: Reply with quote  Mark this post and the followings unread

thanks for your help, although i got it covered in the end anyway! The only problem i have now is how to stop the lfo spork; once the note pattern is done it continues to produce a low rumble (presumably the lfo coming out) ive tried a few things, but im sure its just something obvious!

//score-multidimensional array

int score[20][20];
52=> score[0][0];
52=>score[1][0];
1000=>score[2][0];
52=>score[3][0];
52=>score[4][0];
1000=>score[5][0];
54=>score[6][0];
52=>score[7][0];
54=>score[8][0];
56=>score[9][0];
58=>score[10][0];
500=>score[0][1];
250=>score[1][1];
500=>score[2][1];
125=>score[3][1];
500=>score[4][1];
500=>score[5][1];
250=>score[6][1];
500=>score[7][1];
500=>score[8][1];
500=>score[9][1];
500=>score[10][1];


int score2[7][7];
52=> score2[0][0];
52=>score2[1][0];
1000=>score2[2][0];
52=>score2[3][0];
52=>score2[4][0];
1000=>score2[5][0];
73=>score2[6][0];
500=>score2[0][1];
250=>score2[1][1];
500=>score2[2][1];
125=>score2[3][1];
500=>score2[4][1];
500=>score2[5][1];
250=>score2[6][1];
Event exit;


SinOsc m => SqrOsc c => Gain g => LPF lp=> dac;
SawOsc c2=> g;

//lfo osc
SinOsc lfo=> blackhole;
5=>lfo.freq;

//filter parameters
1000. =>float center_filter_frequency;

fun void instrument(int scorearray[][])
{ //dsp code


//gain parameters
.5 =>g.gain;
0.5=> c.gain;


// modulator frequency
Std.rand2f (0, 10) => m.freq;

// index of modulation
0 => m.gain;
2 => c.sync;

spork~lfofilter();

//for loop plays thru score
for(0=> int k; k < scorearray.size(); k++)
{
Std.mtof(scorearray[k][0])=>c.freq=>c2.freq;
<<<c.freq()>>>;
//convert int into dur
scorearray[k][1]*2::ms=>now;
}
}

fun void lfofilter()
{
while (true)
{
(lfo.last()*500) + center_filter_frequency =>lp.freq;
100::ms=>now;
}
}


exit.broadcast();

spork~instrument(score);
exit => now;
Code:
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Tue Jan 11, 2011 12:23 pm    Post subject: Reply with quote  Mark this post and the followings unread

I usually solve this kind of stuff with a boolean outside lfofilter, and inside lfofilter you check this in the while condition, instead of true. You initialize the boolean to 1, and then set it to 0 when you want lfofilter to stop.

A common thing to do instead of this is save an identifier to the sporked shred, and then use something like machine.destroy() on it when you want it to go away. I haven't used this approach, maybe someone else can offer some help? You may be able to find examples of this in the chuck distro too.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
otloader



Joined: Jan 10, 2011
Posts: 6
Location: Bournemouth

PostPosted: Tue Jan 11, 2011 12:43 pm    Post subject: Reply with quote  Mark this post and the followings unread

cheers for all your help man, ill take it all on board..!
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 373
G2 patch files: 100

PostPosted: Tue Jan 11, 2011 1:03 pm    Post subject: Reply with quote  Mark this post and the followings unread

No problems. Smile Always good to see people using ChucK!

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [12 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Log in
Username:     Password:      Log me on automatically each visit    


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2026 by electro-music.org