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 
 Forum index » DIY Hardware and Software » ChucK programming language
Getting no sound when playing array of Sine waves
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Someone...



Joined: Mar 07, 2014
Posts: 8
Location: Somewhere

PostPosted: Fri Mar 14, 2014 7:13 pm    Post subject: Getting no sound when playing array of Sine waves
Subject description: but there are no syntax errors...
Reply with quote  Mark this post and the followings unread

I made a class that can be used to set the frequency of an oscillator to a random number within a range of 0 - twice the frequency of the original wave. So when doing this for every sample, it sounds like a fuzzified sine wave of the original frequency. I want to make an array of these "fuzzified sine waves", each set apart by an octave, and play them all at once with the higher frequency ones being at a lower volume but this code doesn't produce any sound.

Code:

//can be used with any wave. SinOsc, TriOsc, etc
class RandomWave
{
   float randomOscFrequency;
   float originalOscFrequency;
   
   float minRandomFrequency;
   float maxRandomFrequency;
   
   
   
     //this needs to be called before anything else.
    //would do something like this in a constructor but ChucK
    //does not support constructor right now
    fun void setOriginalOscFrequency(float frequency)
    {
        frequency => originalOscFrequency;
       
        originalOscFrequency * 2 => maxRandomFrequency;
        0.0 => minRandomFrequency;
    }
   
    //changes frequency of randomOscFrequency to a random frequency in the range of 0 to
    //twice the frequency and returns the result
   fun float getRandomOscFrequency()
   {   
       
       Std.rand2f(minRandomFrequency, maxRandomFrequency) => randomOscFrequency;
       
       return randomOscFrequency;
       
   }
}




RandomWave theRandomWave;


//the frequency that RandomWave will use to generate a random frequency
float baseForRandomFrequency;
5.0 => baseForRandomFrequency;


int sineArraySize;
   
SinOsc sineArray[sineArraySize];
.0001 => float gain;

//connect all the sinOscs in the array to the dac
for (0 => int i; i < sineArraySize; i++)
{
    sineArray[i] => dac;
}


while (true){   
   
    for (0 => int i; i < sineArraySize; i++)
    {
        theRandomWave.setOriginalOscFrequency(baseForRandomFrequency);
       
        theRandomWave.getRandomOscFrequency() => sineArray[i].freq;
       
        gain => sineArray[i].gain;
       
        2.0 *=> baseForRandomFrequency;
        //sound at higher frequencies should be queiter
        .00001 -=> gain;
    }
    1::samp => now;
}





This is a simple demonstration of the class I'm trying to use (but the
variable name theRandomWave here is the same so there will be an error running
this and the above code in the same program)

Code:

SinOsc theSinOsc => dac;

RandomWave theRandomWave;

theRandomWave.setOriginalOscFrequency(200.0);


while (true)
{

    theRandomWave.getRandomOscFrequency() => theSinOsc.freq;
    1::samp => now;
}

Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3734
Location: Sweden
Audio files: 277
G2 patch files: 96

PostPosted: Sat Mar 15, 2014 10:01 am    Post subject: Reply with quote  Mark this post and the followings unread

You don't assign a value to sineArraySize. It will default to zero, meaning that sineArray will have size zero and you don't create any SinOscs that make sound.
_________________
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 [2 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