Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
Posted: Tue Feb 26, 2008 4:32 am Post subject:
Additive Synthesis with IFFT and LiSa Subject description: realtime
Additive synthesis (working on the level of sinewave partials) let's you control the whole sound spectrum so it can be used to create any timbre but even the limiting case of harmonic additive synthesis is very powerful.
I made a patch involving an IFFT doing the harmonic generation and a LiSa to make up for the fact that IFFT only works with sampling periods that are powers of two.
Here's the break down:
-make a complex array for the spectrum
-fill it up with a function of your choice
-transform with IFFT
-tune with LiSa
-chuck to dac and rock on
Code:
fun float odd(float val){ //Alternation for sums
if(val%2.0 < 1.0) return -1.0;
else return 1.0;
}
fun void ifftlisa(float freq){
IFFT ifft => LiSa lisa => dac;
( (second/samp)/freq )$int => Math.nextpow2 => int size;
2 /=> size; //Math.prevpow2
size => ifft.size; //Make a ifft with base frequency "slightly" above freq. (slightly < one octave)
complex s[size/2];
size::samp + samp => lisa.duration;
(size$float)/(second/samp) => float delta_t;
size*freq/(second/samp) => float rate => lisa.rate; //Correct for the error that ifft makes in the frequency
true => lisa.record;
true => lisa.loop; //loop around the buffer. LiSa seems to stop playing if it reaches the end of the buffer while recording
1.0 => lisa.feedback; //but preserve the contents, ifft should output zero when it reaches end of the buffer
true => lisa.play;
0.0 => float t;
now + second => time later;
while(now < later){
lisa.clear(); //Start fresh for each period
0::samp => lisa.recPos; //The ifft fills the whole buffer lisa has and then loops without sound
0::samp => lisa.playPos;
for(1.0 => float i; i < s.cap(); 1.0 +=> i){
//odd(i)*Math.pow(i,-1.0) == saw harmonic number 'i'
//Math.sin(i*t) should produce a phasing like the adding of two detuned saw waves
#(0,0.1*odd(i)*Math.pow(i,-1.0-t*0.5)*Math.sin(i*t*15.0)*Math.exp( -t*2.0 ) )=> s[i$int];
}
ifft.transform( s );
delta_t/rate +=> t;
second/freq => now;
}
}
//Chromatic scale, how boring
0 => int p;
while(p <= 12){
spork~ifftlisa(50 + p++ => Std.mtof);
1.0::second => now;
}
EDIT: Confusion about sampling rates and odd LiSa behaviour lead to a revision of the above code. Thrice. _________________ To boldly go where no man has bothered to go before.
Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
Posted: Wed Feb 27, 2008 6:26 am Post subject:
Ok. Maybe using LiSa wasn't the optimal solution. Replacing it with a simple linear interpolating Impulse that's controlled on a frame basis improves quality but the basic idea stays the same: downsample ifft frames.
Attached is a little preview of the technique in action:
monkeyisland.ogg
Description:
The theme of Monkey Island played with an additive synthesis clav. Format: 48kHz ogg
Filesize:
668.59 KB
Duration:
1:08
Viewed:
1552 Time(s)
_________________ To boldly go where no man has bothered to go before.
Sorry, I cannot play the ogg file. What is an ogg file?
It's a open-source alternative to the copyrighted MP3 one.
This has lots of political implications which we could go into but I'd rather just stick to saying "it sounds much better at the same file-size though it's (slightly) less compatible".
I can't remember ATM what you run as a OS but I'm sure VLC is available on it and VLC will play .ogg files for you (As it will play nearly everything which is why I like it).
And when it doesn't play it it will at least tell you why it can't play it.
Often at a rate of at least 15 lines per frame, but yes :¬).
It's one of my two favourite players. The other is Alsa-player. That one is good because it has "volume", "pan" and "playback speed", that last one defaults to 100% but goes from -400% to 400%. Doesn't looks so pretty but those turns out to be the exact controls I find convenient. _________________ Kassen
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