Someone...
Joined: Mar 07, 2014 Posts: 8 Location: Somewhere
|
Posted: 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... |
|
|
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;
}
|
|
|