[chuck-users] wavetable synthesis

eduard aylon eduard.aylon at gmail.com
Fri Oct 19 10:40:51 EDT 2007


Hello list,

Does anyone know if there is any UGen to store waveforms in a table?  
Thus, wavetable synthesis.
I've come up with a few ideas, but none of them seem to work:

1. The first was to use a Gen7 together with a phasor. However, I get  
no sound. See the following patch which I think should synthesise a  
sine wave:

512 => int length;
440. => float freq;
1./ length => float step;

float coefs[ 2*length-1];
for( 1 => int i; i < coefs.cap() ; 2 +=> i )
{
     Math.sin((i-1)*2.*pi/511.) => coefs[i-1]; // value at pos
     step => coefs[i]; // duration of value, 1 samp
}
Math.sin( length*2.*pi/length ) => coefs[ length - 1]; // last value
Phasor p => Gen7 gen7 => WvOut file => dac;
coefs => gen7.coefs;
freq => p.freq;
while( true )
     1::samp => now;


2. The second idea was to use a sndbuf, but the results are far from  
satisfactory. see example:

//first you need to generate one period of a sine wave:

SinOsc s => WvOut file => blackhole;
"sine_period.wav" => file.wavFilename;
1024 => int length;
second/samp => float sr;
sr/length => s.freq;
now + length::samp => time later;
while( now < later )
   1::samp=>now;

----- separate chuck file ----

// wavetable synth part: synthesise a sine wave at any freq

SndBuf snd  => blackhole;
Impulse imp => dac;
"sine_period.wav" => snd.read;
snd.samples() => int length; // must be power of 2
length - 1 => int bitmask;
second/samp => float sr;

440. => float freq;
freq*length/sr => float delta;
delta $int => int int_delta;
0 => float pos;
0 => int int_pos;
1 => int interpolate;
if( me.args() ) Std.atoi( me.arg(0) ) => interpolate;
while( true )
{
     if( !interpolate )
     {
         int_delta::samp => now;
         snd.last() => imp.next;
         snd.pos( snd.pos()&bitmask );
         continue;
     }

     delta + pos => pos;
     pos $int => int_pos;
     (snd.valueAt( (int_pos&bitmask) + 1 ) -
      snd.valueAt(int_pos&bitmask))*(pos-int_pos) + snd.valueAt 
(int_pos) => imp.next;
     1::samp => now;

}


Could someone give me a hand?

thanks,

eduard


More information about the chuck-users mailing list