Author |
Message |
Frostburn
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. |
|
Back to top
|
|
|
Frostburn
Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Feb 27, 2008 2:44 pm Post subject:
|
|
|
Frostburn wrote: | Attached is a little preview of the technique in action: |
Sounds like it has potential, it could use some beef, but it's lively. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
Inventor
Stream Operator
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Wed Feb 27, 2008 5:08 pm Post subject:
|
|
|
Sorry, I cannot play the ogg file. What is an ogg file? |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Feb 27, 2008 5:49 pm Post subject:
|
|
|
Ogg is a compression format like mp3, but it's an open format : http://en.wikipedia.org/wiki/Ogg
It is supported for most computers, like Linux, mac, Windows. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Feb 27, 2008 5:54 pm Post subject:
|
|
|
Inventor wrote: | 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).
Here's a start on the matter if you'd like to go in depth;
http://en.wikipedia.org/wiki/Vorbis _________________ Kassen |
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Wed Feb 27, 2008 5:57 pm Post subject:
|
|
|
Kassen wrote: | (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. _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
Inventor
Stream Operator
Joined: Oct 13, 2007 Posts: 6221 Location: near Austin, Tx, USA
Audio files: 267
|
Posted: Wed Feb 27, 2008 6:25 pm Post subject:
|
|
|
Interesting reading, neat stuff! I'll look into getting a player later. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Wed Feb 27, 2008 6:36 pm Post subject:
|
|
|
Blue Hell wrote: |
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 |
|
Back to top
|
|
|
|