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
Newbie Questions
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
rasselas21



Joined: Jan 08, 2009
Posts: 4
Location: Kentucky

PostPosted: Wed Jan 14, 2009 10:17 pm    Post subject: Newbie Questions
Subject description: Lots of New-ChucKian Questions
Reply with quote  Mark this post and the followings unread

Hi,

First, let me start off by stating that I don't wish to clutter up this forum with countless questions that very well might be documented elsewhere. I don't think many people BROWSE the threads by subject lines anyways (past the first page), but rather use the search tool for finding answers to their questions. I have been on the irc.freenode.org/#chuck (?address?) IRC Chat, but they prefer I ask questions here... at least until more people start visiting the IRC chat. Most of these questions are fairly simple sounding, and for many a link may suffice. So here goes:

1) Is there a way to append printed statements after each other? <<<"first string", "second string">>> obviously work... but that's not what I mean... rather, can I do something like <<<"first string">>> some code here APPEND<<<"second string">>> ??? If there isn't a way, will either the future stdout or chout correct this problem?

2) What is the code to accept line inputs? To post a question to the Console Monitor, and then type in an answer and such be stored in a variable... in other ProgLangs something like -- Line Input "enter a number": x; -- works. (And can those be appended onto a pre-printed line as well? Anyways...)

3) Is there a way to replace the miniAudicles runtime version of ChucK (1.2.1.1) with the latest official download (1.2.1.2 or later)??? The miniAudicle's version isn't powerful enough (on arrays) for me.

4) Is there an EASY way to avoid the pops/clicks upon playing a note for the first time, or playing a note for the last time?

5) Is there an easy way of converting a .ck file into an .exe file? (I'm sure that's explained elsewhere, a link is appreciated if the answer is not overly simple)

6) Is there no ^ (power, exponent) sign/function in ChucK? Neither the bitwise XOR nor the ^=> (upchuck) seem to be such, but I could be wrong. With no ^ (exponent) sign, nor "e" (2.721...) it seems hard to implement musical "cents" in ChucK. Does anybody know of anything relating to this?

7) Is there a convenient way to reverse a string or the elements of an array? Such as "a b c d" becomes "d c b a"?

Cool Can someone give me the SHORTEST line/amount of code possible to play a one second ~440 tone, preferrably both for SinOsc and also an example for StifKarp, at a volume of ~50%?

9) Would the previous question be very different if I ask instead for a four note melody with two tones lasting a second at 50% volume and two tones lasting 1/2 a second at 25% volume? I ask these two questions as that's probably one of the most common things newbies will be doing (playing notes) and the most concise/easy way to do such could be a big help over time.

10) This is more of a generic question (to clip onto the back of another answer)... what do you think the biggest function of ChucK is? As an algorithmic generator/composer? As a tonal sound creator/editor (making up timbres)? Is it's main use as you see it, also your main use of the program?

Thanks for all the help... any other advice to a newbie ChucK programmer is also appreciated. See-ya.

PS - I'm using miniAudicle (not the command-line), so gear your answers towards that please.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Jan 14, 2009 11:55 pm    Post subject: Re: Newbie Questions
Subject description: Lots of New-ChucKian Questions
Reply with quote  Mark this post and the followings unread

rasselas21 wrote:


1) Is there a way to append printed statements after each other? <<<"first string", "second string">>> obviously work... but that's not what I mean... rather, can I do something like <<<"first string">>> some code here APPEND<<<"second string">>> ??? If there isn't a way, will either the future stdout or chout correct this problem?


So, let me get this straight; you want to use several commands to print and have the result appear on a single line? I don't think that's possible, you may have to merge the different command outputs into a single string and print that.

Quote:
2) What is the code to accept line inputs? To post a question to the Console Monitor, and then type in an answer and such be stored in a variable... in other ProgLangs something like -- Line Input "enter a number": x; -- works. (And can those be appended onto a pre-printed line as well? Anyways...)


Have a look at "examples/string/readline.ck" The other examples in the "string" dir are likely of interest to you as well. This is somewhat hacky right now. File IO is promised for the next version and if the notes are to be believed that should clean this stuff up.

Quote:
3) Is there a way to replace the miniAudicles runtime version of ChucK (1.2.1.1) with the latest official download (1.2.1.2 or later)??? The miniAudicle's version isn't powerful enough (on arrays) for me.


Yes. Replace the contents of the chuck dir in the mini's source with the contents of the latest version and compile. Do note that for some reason the dir does need to be named after version 1.2.1.1 but that it does work fine. I've been running it like that under Linux for quite a while now. This does require a C++ compiler, I fear, so that might be a bit hardcore.

Quote:
4) Is there an EASY way to avoid the pops/clicks upon playing a note for the first time, or playing a note for the last time?


I'm not sure I understand the issue. Likely these pops that you have depend on some code of yours. Generally Envelopes are good at avoiding pops but this may depend on the context.

Quote:
5) Is there an easy way of converting a .ck file into an .exe file? (I'm sure that's explained elsewhere, a link is appreciated if the answer is not overly simple)


Not right now. It has been suggested in the past but I'm not sure how much work on this has been done, if any. If you need a single executable to run a certain amount of ChucK code a batchfile may be of help?

Quote:
6) Is there no ^ (power, exponent) sign/function in ChucK?


Here you go;
Code:
<<<Math.pow(2, 4)>>>;
<<<Math.e>>>;


I'm not sure why "e" is in the math library and "pi" is just a plain build in variable.

Quote:

7) Is there a convenient way to reverse a string or the elements of an array? Such as "a b c d" becomes "d c b a"?


Not for strings. For arrays you'll have to write a simple function to loop over it.

Quote:

Cool Can someone give me the SHORTEST line/amount of code possible to play a one second ~440 tone, preferrably both for SinOsc and also an example for StifKarp, at a volume of ~50%?


Code:
SinOsc s => dac;
.5 => s.gain;
440 => s.freq; //default is 220
second => now;


Code:

StifKarp s => dac;
.5 => s.gain;
440 => s.freq;
1 => s.noteOn;
second => now;



Quote:
9) Would the previous question be very different if I ask instead for a four note melody with two tones lasting a second at 50% volume and two tones lasting 1/2 a second at 25% volume? I ask these two questions as that's probably one of the most common things newbies will be doing (playing notes) and the most concise/easy way to do such could be a big help over time.


Clearly there would be many ways of doing this. I took a simple way, assuming you'd like to have a sort of defined "score". You could of course get more clever and/or elaborate but for a start this works and it's easy to extend.

Code:

StifKarp s => dac;
.5 => s.gain;

[49,       44,       47,       40]    @=> int note_pitch[];
[second,    .5::second, .5::second, second] @=> dur note_dur[];

for(int n; n< note_pitch.cap(); n++)
   {
   note_pitch[n] => Std.mtof => s.freq;
   1 => s.noteOn;
   note_dur[n] => now;
   }

//let it sound out for a bit
2::second => now;


Quote:
10) This is more of a generic question (to clip onto the back of another answer)... what do you think the biggest function of ChucK is? As an algorithmic generator/composer? As a tonal sound creator/editor (making up timbres)? Is it's main use as you see it, also your main use of the program?


I think the bigest function is the versatility. I like using ChucK to develop instruments and for livecoding, others like using it to generate timbres or to learn more about how sound works or even to learn how to program. I don't think it's better at one thing at the expense of something else though most attention has so far gone towards making it work in a intuitive way, more so than in into raw performance.

Quote:

Thanks for all the help... any other advice to a newbie ChucK programmer is also appreciated. See-ya.


Get to know the examples directory, read the examples, run them and modify them to see what the effect is. Once you are comfortable with it start on a small project writing something that would be useful or fun to you (this helps keep you motivated). Look up the examples and relevant documentation entries for all problems you encounter and borrow from those. Ask questions when you get stuck for more than a few hours. Make sure you enjoy yourself, if tutorials are too dry simply start out trying to write a techno/breakcore/folksong/ambient generator.

Welcome on board, BTW! Assuming you make at least some attempt at seeing whether something is in the docs or examples already please do feel free to ask questions in any way you like.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
rasselas21



Joined: Jan 08, 2009
Posts: 4
Location: Kentucky

PostPosted: Thu Jan 15, 2009 4:11 pm    Post subject: See next >>> Reply with quote  Mark this post and the followings unread

This post was mis-posted and is obsoleted by next post.
Last edited by rasselas21 on Thu Jan 15, 2009 4:22 pm; edited 1 time in total
Back to top
View user's profile Send private message
rasselas21



Joined: Jan 08, 2009
Posts: 4
Location: Kentucky

PostPosted: Thu Jan 15, 2009 4:15 pm    Post subject: Thanks :) Reply with quote  Mark this post and the followings unread

Kassen,

Excellent replies Smile

Quote:
So, let me get this straight; you want to use several commands to print and have the result appear on a single line? I don't think that's possible, you may have to merge the different command outputs into a single string and print that.


Print "first string",
IF first string is less than three words THEN
Print "second string";

In the example above (derived from a BASIC Lang) the comma after the first print string shows that no new-line is created... so any additional print statements will print on the same line. The second print statement is followed by a semi-colon though, and as such would generate a new-line statement. It seems that <<<"something">>> always generates a new-line, I was kinda wondering if there was a way to tell it NOT to generate the new-line, or else, a way to back up (in the console monitor) to the end of the previous line, so as to pretty much over-ride the automatic generation of a new-line (sorta like a back-space).


Quote:
Have a look at "examples/string/readline.ck" The other examples in the "string" dir are likely of interest to you as well. This is somewhat hacky right now. File IO is promised for the next version and if the notes are to be believed that should clean this stuff up.


I hope so. It sure is bulky.

Anyways, for me... it didn't work. I opened it straight up into miniAudicle and Added the Shred... it gave a line in the Console Monitor that said "input some text here:" or such, and then... I couldn't type anything. Assuming it might still be taking my info down behind the scenes, I hit ENTER to move on... nothing. I removed the shred and tried again... this time not even the input line was printed... (several restarts later and no difference). Maybe I am doing something wrong?

Quote:
Yes. Replace the contents of the chuck dir in the mini's source with the contents of the latest version and compile. Do note that for some reason the dir does need to be named after version 1.2.1.1 but that it does work fine. I've been running it like that under Linux for quite a while now. This does require a C++ compiler, I fear, so that might be a bit hardcore.


Note exactly so simple, but much more info than I had before. Thanks. BTW folks, there is a free C++ comiler named Pelles C or something.

Quote:
I'm not sure I understand the issue. Likely these pops that you have depend on some code of yours. Generally Envelopes are good at avoiding pops but this may depend on the context.


Code:

SinOsc s => dac;

220 => s.freq;
.5::second => now;

0 => s.freq;
40::ms => now;

330 => s.freq;
.5::second => now;

0 => s.freq;
40::ms => now;

440 => s.freq;
.5::second => now;


Rather clicky/poppy between notes for me, you too? Ok, so I kinda think that might be a result of lack of envelopes.

Code:

SinOsc s => dac;
fun void c() {Std.mtof(60) => s.freq; .4::second => now;}
fun void e() {Std.mtof(64) => s.freq; .4::second => now;}
fun void g() {Std.mtof(67) => s.freq; .4::second => now;}
c(); e(); g();  //s =< dac;


However in the above code the click is most noticeable at the end of the phrase. Another case of envelopes? Does that mean one should almost always put a SinOsc in an envelope?

Code:
SinOsc s => dac;

Std.mtof(60) => s.freq;
.4::second => now;


Quote:
Not right now. It has been suggested in the past but I'm not sure how much work on this has been done, if any. If you need a single executable to run a certain amount of ChucK code a batchfile may be of help?


Yes, I hadn't thought of that. Good idea.

Quote:
[concerning exponents...]<<<Math.pow(2, 4)>>>; <<<Math.e>>>;


Super-helpful Smile

Cool Can someone give me the SHORTEST line/amount of code possible to play a one second ~440 tone, preferrably both for SinOsc and also an example for StifKarp, at a volume of ~50%?

Code:
SinOsc s => dac;
.5 => s.gain;
440 => s.freq; //default is 220
second => now;


I was hoping there was something faster, and so I asked. At least that's settled for now. BTW, I was surprised to realize there is a base tone of 220. That might be more useful if that was set to 0, as then it could serve as a silent-note, ie, rest.

Quote:
Clearly there would be many ways of doing this. I took a simple way, assuming you'd like to have a sort of defined "score". You could of course get more clever and/or elaborate but for a start this works and it's easy to extend.


Code:

StifKarp s => dac;
.5 => s.gain;

[49, 44, 47, 40, 42, 37, 37]    @=> int note_pitch[];
[second, .5::second, .5::second, second, .25::second, .25::second, second] @=> dur note_dur[];

for(int n; n< note_pitch.cap(); n++)  //neat way of declaring n here... didn't realize n's initial value is 0, cool
   {
   note_pitch[n] => Std.mtof => s.freq;
   1 => s.noteOn;
   note_dur[n] => now;
   }


Only thing is that you don't need ".5 => s.gain;" at the top if you change "1 => s.noteOn;" to "0.5 => s.noteOn;" at the bottom... like this:

Code:

StifKarp s=> dac;

[0,1,3,0,4,1,6,3,8,16,4,8,3,1,4,1,1,-3,-3,1,0,1,3,0,4,1,6,3,8,16,16,16] @=> int mel[];   //sequence data inspired by coleman

for (0 => int i; i < 32; i++)
{
  Std.mtof( 48 + mel[i%mel.cap()] ) => s.freq;
  s.noteOn( 0.5 );  // or instead of "0.5 => s.noteOn;" you could say this.
  295::ms => now;
}


Thanks for all the help Kassen (and any future replies by you or others). This was pretty helpful info. I do realize now that digging through the examples is a shortcoming of mine (but I do wish they were more documented though... like sometimes I run an example and am left wondering what it even was supposed to demonstrate). BTW, I wasn't expecting to here your comment of "The main function of ChucK is to be well-rounded". I don't know how feasible that is in practical terms either... most things in life exist/advance by being niche entities... giraffes have long necks for eating tall tall plants, anteaters have long tongues for digging in ant-holes, and I have a long... er, anyways, don't most things tend to tilt one way or the other?

Rass,

PS...
Quote:
Make sure you enjoy yourself, if tutorials are too dry simply start out trying to write a techno/breakcore/FOLKSONG/ambient generator.


Umm, any examples of a ChucK folksong generator?
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Thu Jan 15, 2009 8:40 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks. This conversation will be very valuable to future chuckers.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Thu Jan 15, 2009 8:45 pm    Post subject: Re: Thanks :) Reply with quote  Mark this post and the followings unread

rasselas21 wrote:

It seems that <<<"something">>> always generates a new-line, I was kinda wondering if there was a way to tell it NOT to generate the new-line, or else, a way to back up (in the console monitor) to the end of the previous line, so as to pretty much over-ride the automatic generation of a new-line (sorta like a back-space).


That's not a bad idea at all. If that isn't in the escape characters already I think we need that, this sounds quite useful.


Quote:

Anyways, for me... it didn't work. I opened it straight up into miniAudicle and Added the Shred... it gave a line in the Console Monitor that said "input some text here:" or such, and then... I couldn't type anything. Assuming it might still be taking my info down behind the scenes, I hit ENTER to move on... nothing. I removed the shred and tried again... this time not even the input line was printed... (several restarts later and no difference). Maybe I am doing something wrong?


No, I just verified and you are right. It does seem that this function needs a actual console to work and hence doesn't work with the Mini. This should likely be send to Spencer (who maintains the Mini) for consideration.


Quote:

Note exactly so simple, but much more info than I had before. Thanks.


I know. This is a result of having a small and time-starved dev-team; I don't think Spencer has yet found the time for a update.

Quote:

Rather clicky/poppy between notes for me, you too? Ok, so I kinda think that might be a result of lack of envelopes.


Yes, also; I wouldn't recommend silencing a Oscillator this way as it may lead to DC-offset. A frequency of 0 does not need to mean a *output* of 0. I'd use a envelope with a very short duration here.

Quote:

However in the above code the click is most noticeable at the end of the phrase. Another case of envelopes? Does that mean one should almost always put a SinOsc in an envelope?


Well, at the end here the SinOsc will disconnect from the DAC so it's output will jump from some value to 0 instantaneously; that will indeed result in a click. Here too a short envelope will remedy the situation.


Quote:
I was hoping there was something faster, and so I asked.


I actually think this is a appropriate length; it's exactly one line for each of the points in your definition and the function of each line is quite clear, even if you would've never seen ChucK before.

Quote:
At least that's settled for now. BTW, I was surprised to realize there is a base tone of 220. That might be more useful if that was set to 0, as then it could serve as a silent-note, ie, rest.


Wel, there needs to be *some* preset value. I don't think a preset value of 0 would be very useful; if we'd want to start with a rest we could simply start with a tone a bit later instead.


Quote:
Only thing is that you don't need ".5 => s.gain;" at the top if you change "1 => s.noteOn;" to "0.5 => s.noteOn;" at the bottom... like this:


Yes, that is correct. Setting the amplitude at the gain parameter here implies it's a property of the instrument itself, not of specific notes. Your preference is equally valid and results in the same but implies a different perspective (at least to me it does).

That said; the main reason for me to do it like this here was to copy-paste as much as possible to show the link between the bits of code. You'll notice it could've been done like that in the example that only plays a single StifKarp note as well. To me such factors are more important than minimising the number of lines used.

Quote:

Code:

  s.noteOn( 0.5 );  // or instead of "0.5 => s.noteOn;"



Yes, those are completely equivalent. Use whatever you prefer. I prefer the "chuck" one because you can build chains like;

Code:

64 => Std.mtof => s.freq;


and I find that very easy to read (as it's left to right instead of inside to out). Some people prefer the function-style notation because it's what they are used to. That is of course perfectly fine and equally valid.

Quote:
I do wish they were more documented though... like sometimes I run an example and am left wondering what it even was supposed to demonstrate).


I agree in some cases. There should probably be a communal cleanup spree of the examples some time in the future. Most are very good but there is some odd stuff in there here and there.


Quote:
BTW, I wasn't expecting to here your comment of "The main function of ChucK is to be well-rounded". I don't know how feasible that is in practical terms either... most things in life exist/advance by being niche entities... giraffes have long necks for eating tall tall plants, anteaters have long tongues for digging in ant-holes, and I have a long... er, anyways, don't most things tend to tilt one way or the other?


I think programming for audio is already quite niche... IMHO the various sides to ChucK benefit from each other. Synthesis is more useful with versatile input methods, there are also great advantages to integrating analysis and synthesis within the same system. Of course many people end up specialising in one or two topics within such a system but I wouldn't be able to say what topics would be most typical to specialise in for ChucK.

Quote:

Umm, any examples of a ChucK folksong generator?


I don't think so; all the more reason to try writing one! :¬)

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 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