electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Additive Synthesis with IFFT and LiSa
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Tue Feb 26, 2008 4:32 am    Post subject: Additive Synthesis with IFFT and LiSa
Subject description: realtime
Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Wed Feb 27, 2008 6:26 am    Post subject: Reply with quote  Mark this post and the followings unread

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

Download
 Filename:  monkeyisland.ogg
 Filesize:  668.59 KB
 Downloaded:  580 Time(s)


_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23624
Location: The Netherlands, Enschede
Audio files: 266
G2 patch files: 320

PostPosted: Wed Feb 27, 2008 2:44 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Wed Feb 27, 2008 5:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

Sorry, I cannot play the ogg file. What is an ogg file?
Back to top
View user's profile Send private message Send e-mail
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23624
Location: The Netherlands, Enschede
Audio files: 266
G2 patch files: 320

PostPosted: Wed Feb 27, 2008 5:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Feb 27, 2008 5:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 23624
Location: The Netherlands, Enschede
Audio files: 266
G2 patch files: 320

PostPosted: Wed Feb 27, 2008 5:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Wed Feb 27, 2008 6:25 pm    Post subject: Reply with quote  Mark this post and the followings unread

Interesting reading, neat stuff! I'll look into getting a player later.
Back to top
View user's profile Send private message Send e-mail
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Feb 27, 2008 6:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [9 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

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


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use