Jump to content

Fourier Synthesis


Sengin
 Share

Recommended Posts

So I just finished my real-time systems final project. We were to take an input file, consisting of stuff like:


...
A4 Q
E4 E.
G4 S
...

and our program would create a sound file of that tune. We used the SHARC Archive to provide the necessary information (i.e. frequency of each note playable by that instrument, number of harmonics, amplitude/phase of each harmonic, etc...) to get "real sounding" computer-generated instruments. Basically, we would read the info about the instrument into our program, and it would calculate the amplitudes for each note and its harmonics by this big sine wave:

a * sin(2*pi*harmNum*fundamental(noteIndex)*t + phi)

where a is the amplitude, harmNum is the harmonic number, fundamental(noteIndex) is the fundamental at the specific note (i.e. A4), t is the current time value, and phi is the phase.

Now, since I found this so interesting, I went ahead and implemented chords and the ability to change instruments. Still not satisfied and still very interested in this, I thought it would be a good idea (and fun) to implement an ADSR envelope as well. And after much frustration and headache, I have finished. My input files now look like:


...
inst tuba a#2 s inst trombone a#3 s e4 s
inst tuba - s
g2 e. inst trombone a#3 e. e4 e.
inst tuba a#2 q inst trombone a#3 e e4 e
inst flute_vibrato g6 s
a#6 s
inst tuba c3 e inst flute_vibrato c7 q
inst tuba d#3 s
c3 e. inst flute_vibrato - s
g5 s
a#5 s
inst tuba d#3 s inst flute_vibrato c6 s
...

and the result is something like this:

Hydrocity Zone Act II

Needless to say, I am quite happy. Have any of you ever used Fourier Synthesis or any other ways to generate sound?

Link to comment
Share on other sites

I knew you'd reply to this sometime since you were in a real-time class as well :P. I did everything in matlab (nice and easy vector operations and a nice function called wavwrite() which will take the data points and save it as a .wav file), but I'm thinking about porting it to C++ or Java over the summer if I'm bored (and so I can use it anywhere and not have to have matlab installed). I just need to figure out how to write wav files...I heard they have really stupid rules.

Link to comment
Share on other sites

they arent too bad. I was researching the file format just because. I could probably explain it to you some time.

I remember reading something where this guy was ranting at the horribleness that was the wav file (not the quality, but how it's written). From what I remember, it was something like a header section, then some data for each channel, then another header, then more data, etc... I couldn't understand why there needed to be so many headers, and why not something like "sample rate, number of channels, start of data, etc.." and then the data.

I never used matlab I just got to program in verilog.... uhh yay? lol

I've never heard of verilog? What's it used for? The name reminds me of prolog...ugh.

Cool, harmonic analysis!

Indeed (on both accounts)!

Link to comment
Share on other sites

verilog is basically a language used for synthesizing circuits. I used it to program an FPGA with is basically a chip with millions of gates. So the code essentially gets turned into gates somehow. Its pretty crazy. You should check out my vid for my project if you havent already.

"and why not something like "sample rate, number of channels, start of data, etc.." and then the data."

Actually thats exactly what it is... not sure what you read... :S

A wav file (a basic one anyways) is just a header and then the data.

Header,Sample 1(LeftChan,RightChan),Sample 2(LeftChan,RightChan)....Sample n(LeftChan,RightChan)

thats pretty much it. Well if its mono then there is no left/right chan, or if its 5 channels, then its channel1,channel2,channel3,channel4,channel5, etc.

http://ccrma.stanford.edu/courses/422/projects/WaveFormat/

Link to comment
Share on other sites

hey, I remember you mentioning this in the diy thread. Good stuff, hope you continue with it.

Have any of you ever used Fourier Synthesis or any other ways to generate sound?

I coded a drawbar organ, which is additive synthesis. Fourier and additive synthesis are roughly synonymous, I've seen projects like yours referred to as 'additive resynthesis'.

I've also done a single operator FM synth. And you may have seen my subtractive synth from the diy thread (though I borrowed some code to make it).

I remember reading something where this guy was ranting at the horribleness that was the wav file (not the quality, but how it's written)

Do you have a link to that rant? I'm just curious because in my experience WAVE is one of the easiest formats to work with.

cheers.

Link to comment
Share on other sites

I coded a drawbar organ, which is additive synthesis. Fourier and additive synthesis are roughly synonymous, I've seen projects like yours referred to as 'additive resynthesis'.

Hmm... why would you classify this as additive resynthesis? Resynthesis implies that some form of recording is being analyzed and broken down into component harmonics, then literally re-synthesized from scratch through the synth engine. Among other recent releases, Camel Audio's "Alchemy" does just this. The OP's project seems like straightforward additive synthesis.

Link to comment
Share on other sites

I did, but my impression was that the OP was manually inputting all of this data into the program ("we would read the info about the instrument into our program...") which imo puts it more in the additive end rather than resynthesis. I mean, it's cool either way, I'm not knocking it at all. I guess I'm just unclear on what exactly was doing the analysis of the original data.

Link to comment
Share on other sites

Let's use your definition:

Resynthesis implies that some form of recording is being analyzed and broken down into component harmonics, then literally re-synthesized from scratch through the synth engine.

That's exactly what's going on here. Somebody already did the work of recording the instruments and breaking down their harmonics into a nice set of XML files (SHARC archive). OP uses the harmonic data from SHARC and re-synthesizes the harmonic data from scratch with a big sine function.

Link to comment
Share on other sites

Do you have a link to that rant?

It was over a year ago I believe, and I never saved the link, unfortunately.

OP uses the harmonic data from SHARC and re-synthesizes the harmonic data from scratch with a big sine function.

Correct; the program looks at all the files it needs, and uses the data within to set the parameters of the huge sine function. All the parameters need to be re-evaluated for every instrument, every note, and every harmonic...and calculates the value of the sine for 44100 times a second. There's even more to it because I implement a basic ADSR envelope, so it has to calculate that for every note and harmonic as well. I'm actually surprised it took only 30 seconds to calculate hydrocity.

Matlab isn't all that bad.

I agree, I rather somewhat enjoy using matlab. It's quite fast. It certainly takes time to get used to using it, but it's really not that bad.

I guess I'm just unclear on what exactly was doing the analysis of the original data.

The program does the analysis of the original data, then uses what it needs inside of the sine function.

I can't listen! Have someone host it plz.

It works fine for me. What page do you get when you click on it?

Ah, thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...