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
  mosc Live music with Twyndyllyngs - Bill Fox and Howard Moscovitz
Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
NullPointerException error
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
shmoyko



Joined: Dec 19, 2013
Posts: 5
Location: London

PostPosted: Thu Dec 19, 2013 8:02 am    Post subject: NullPointerException error
Subject description: Tryint to dynamically create a two-oscillator synth
Reply with quote  Mark this post and the followings unread

Hello all,

I just finished the ChucK Coursera course and wanted to try building a simple 2-oscillator bass synth.

The synth is a class and the user can choose what each oscillator should be (e.g. SinOsc or TriOsc). In order to achieve this, I need to somehow create oscillators dynamically. But, that's when I run into problems.

Here's the code I have so far: http://pastebin.com/BCuYbVWL

I understand why I'm getting the NullPointerException error, but just can't figure out how to build the oscillators "dynamically".

Does anyone have examples of something like this?

Many thanks.
Back to top
View user's profile Send private message
fretless



Joined: Nov 29, 2009
Posts: 19
Location: Boston

PostPosted: Thu Dec 19, 2013 6:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

Code:

public class EitherOrBass extends Chubgraph
{
    SinOsc s0, s1;
    TriOsc t0, t1;
    int which;
   
    fun void init (int Qsin)
    {
        Qsin => this.which;
        if(Qsin){s0 => outlet; s1 => outlet; 0.1 => s0.gain => s1.gain;}
        else {t0 => outlet; t1 => outlet; 0.1 => t0.gain => t1.gain;}
    }
   
    fun void Play (float f0, float f1)
    {
        if(this.which){f0 => s0.freq;f1 => s1.freq;}
        else {f0 => t0.freq;f1 => t1.freq;}
    }   
   
}

    EitherOrBass FL;
    1 => FL.init;

    FL => NRev verb => dac;
    0.234 => verb.mix;
    float note;
    while(true)
    {
        Math.random2f(45.0, 200.0) % 30. * 7.  => note;
        FL.Play(note, note*2.);
        0.15::second => now;
     }
Back to top
View user's profile Send private message
shmoyko



Joined: Dec 19, 2013
Posts: 5
Location: London

PostPosted: Thu Dec 26, 2013 7:44 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks. Neat solution, although, if I'm not mistaken, you not dynamically generating oscillators, but connecting them to the Chubgraph outlet as needed.

I guess there's no other way.
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 [3 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