Author |
Message |
makeitgofaster
Joined: Jul 01, 2015 Posts: 4 Location: Saint Paul, MN
|
Posted: Wed Jul 01, 2015 5:21 am Post subject:
Codes doesn't work: object scoping / no sound plays |
 |
|
Hiya!
I'm new here and trying to figure out how to get going on this CHucK stuff.
I have the code below, which does not play any sound. Essentially, I'm trying to build a class to represent an arbitrary listing of notes to be played as a chord.
Two questions:
1) In test_play, I'm throwing an oscillator declared in the while loop to DAC. When I wait outside the loop, those are still "thrown to DAC" and don't magically disappear because I'm out of scope of the loop, right?
2) Other code examples I can run are making sound... why isn't this working?
Code: | public class ratiochord
{
10 => int rcl;
float chordarray[rcl];
1 => chordarray[0];
for( 1 => int i; i <rcl> chordarray[i];
fun void addnote (float note)
{
for( 0 => int i; i <rcl> chordarray[i];
break;
}
}
}
fun void addnotes(float note[])
{
for(0 => int i; i <note> int i;
while(i <rcl> dac;
chordarray[i] => s.sfreq;
<<<"adding " + chordarray[i]>>>;
i++;
}
notedur => now;
<<<"done">>>;
}
}
ratiochord rc;
rc.addnote(1.5);
rc.test_play(2::second);
//[chuck](VM): sporking incoming shred: 1 (ratiochord)...
//"adding 1.0000" : (string)
//"adding 1.5000" : (string)
//"done" : (string)
ratiochord rc2;
rc2.addnotes([1.5,1.75]);
rc2.test_play(2::second);
// outputs:
//"adding 1.0000" : (string)
//"adding 1.5000" : (string)
//"adding 1.7500" : (string)
//"done" : (string)
|
Last edited by makeitgofaster on Thu Jul 02, 2015 5:08 am; edited 1 time in total |
|
Back to top
|
|
 |
makeitgofaster
Joined: Jul 01, 2015 Posts: 4 Location: Saint Paul, MN
|
Posted: Wed Jul 01, 2015 7:38 pm Post subject:
just.. really stupid |
 |
|
But then that's writing code in a new language for you.
1) I had not multiplied my array of notes by a baseline value. It was playing sounds at 1, 1.5, and 1.75 hz instead of those three factors multiplied by 220hz or something sensible.
2) When writing test code, I was also surprised to find that this first one causes a segmentation fault:
[1.0,1.5,1.75] @=> float chordarray[3];
... but this is correct:
[1.0,1.5,1.75] @=> float chordarray[]; |
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4146 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Jul 02, 2015 3:29 am Post subject:
|
 |
|
makeitgofaster!
Glad to see that you fixed your problem - we're a bit slow here sometimes.
As you noticed ChucK isn't completely bug-free, and the responses when you do something that ChucK doesn't expect (like reference assigning to an already initialized array) can be less than helpful. NullPointerExceptions aren't unheard of either.
A tip if you post code again - check "Disable HTML in this post" and "Disable Smilies in this post" - if you check your post you will see that some usage of less than mangled things a bit.
If you run into stuff in the future, a tip is to post a question to the ChucK users mailing list:
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
..chances are you will get a quick and useful response there, some of the guys who make ChucK read that list too. If you post your segmentation fault example there I think it may be well received.  _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
makeitgofaster
Joined: Jul 01, 2015 Posts: 4 Location: Saint Paul, MN
|
Posted: Thu Jul 02, 2015 5:08 am Post subject:
|
 |
|
Got it! Thanks.  |
|
Back to top
|
|
 |
|