electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
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 
Live streaming at radio.electro-music.com

  host / artist show at your time

poster

Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
Codes doesn't work: object scoping / no sound plays
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
makeitgofaster



Joined: Jul 01, 2015
Posts: 4
Location: Saint Paul, MN

PostPosted: Wed Jul 01, 2015 5:21 am    Post subject: Codes doesn't work: object scoping / no sound plays Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
makeitgofaster



Joined: Jul 01, 2015
Posts: 4
Location: Saint Paul, MN

PostPosted: Wed Jul 01, 2015 7:38 pm    Post subject: just.. really stupid Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4086
Location: Sweden
Audio files: 350
G2 patch files: 100

PostPosted: Thu Jul 02, 2015 3:29 am    Post subject: Reply with quote  Mark this post and the followings unread

welcome 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. Smile

_________________
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
makeitgofaster



Joined: Jul 01, 2015
Posts: 4
Location: Saint Paul, MN

PostPosted: Thu Jul 02, 2015 5:08 am    Post subject: Reply with quote  Mark this post and the followings unread

Got it! Thanks. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 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
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use