[chuck-users] Question on BlitSquare

eduard eduard.aylon at gmail.com
Mon Jan 15 16:29:34 EST 2007

Hi list,

Today I've noticed something unexpected while using BlitSquare. What  
happens is that I understand the freq() method as to set the  
fundamental frequency of the oscillator, however this is not true,  
and somehow the frequency being set is way below the specified one  
The following code may be more explanatory. First, I use BlitSquare  
to create a band limited square waveform with fundamental frequency =  
200 Hz and 4 harmonics. Secondly, I try to reproduce the same sound  
while using a sum of sinusoids which frequencies are related by 1, 3,  
5, 7, etc... (odd harmonics) and their gains are 1, 1/3, 1/5, 1/7  
etc. However I must start with a fundamental frequency of 50Hz in  
order to obtain the same sound as a 200Hz BlitSquare.

// using BlitSquare
BlitSquare b => gain g=> WvOut audio => dac;
audio.wavFilename( "blitSqr.wav" );
0.9 => g.gain;
4 => int n; // number of harmonics
200. => float fund_freq;
b.harmonics( n );
b.freq( fund_freq );
now => time end;
1::second +=> end;

while( now < end )
     1::second => now;

b =< g;

// "hand made" band limited square wave
sinosc s[n];
50 => fund_freq; // note that fund_freq must be set to 50 Hz in order  
to yield same
                  // results as a 200Hz BlitSquare
for( 0=> int i; i < n; i++ )
     s[i].freq( fund_freq*(2*i+1) );
     s[i].gain( 1./((2*i+1)) );
     s[i] => g;
0.5 => g.gain;
1::second +=> end;
while( now < end )
     1::second => now;

Am I understanding BlitSquare wrongly?

Thanks in advance,


More information about the chuck-users mailing list