Sengin Posted April 30, 2009 Share Posted April 30, 2009 So I just finished my real-time systems final project. We were to take an input file, consisting of stuff like: ...A4 QE4 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 sinst tuba - sg2 e. inst trombone a#3 e. e4 e.inst tuba a#2 q inst trombone a#3 e e4 einst flute_vibrato g6 sa#6 sinst tuba c3 e inst flute_vibrato c7 qinst tuba d#3 sc3 e. inst flute_vibrato - sg5 sa#5 sinst 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? Quote Link to comment Share on other sites More sharing options...
SenPi Posted April 30, 2009 Share Posted April 30, 2009 what was this program coded in? Quote Link to comment Share on other sites More sharing options...
Sengin Posted April 30, 2009 Author Share Posted April 30, 2009 I knew you'd reply to this sometime since you were in a real-time class as well . 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. Quote Link to comment Share on other sites More sharing options...
SenPi Posted April 30, 2009 Share Posted April 30, 2009 they arent too bad. I was researching the file format just because. I could probably explain it to you some time. I never used matlab I just got to program in verilog.... uhh yay? lol Quote Link to comment Share on other sites More sharing options...
Bahamut Posted April 30, 2009 Share Posted April 30, 2009 Cool, harmonic analysis! Quote Link to comment Share on other sites More sharing options...
Sengin Posted April 30, 2009 Author Share Posted April 30, 2009 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)! Quote Link to comment Share on other sites More sharing options...
SenPi Posted April 30, 2009 Share Posted April 30, 2009 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/ Quote Link to comment Share on other sites More sharing options...
The Pezman Posted April 30, 2009 Share Posted April 30, 2009 I can't listen! Have someone host it plz. Quote Link to comment Share on other sites More sharing options...
Native Jovian Posted April 30, 2009 Share Posted April 30, 2009 I did everything in matlab You have my sincerest sympathies, sir. Quote Link to comment Share on other sites More sharing options...
TSori Posted April 30, 2009 Share Posted April 30, 2009 You have my sincerest sympathies, sir. amen to that Quote Link to comment Share on other sites More sharing options...
analoq Posted April 30, 2009 Share Posted April 30, 2009 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. Quote Link to comment Share on other sites More sharing options...
zircon Posted April 30, 2009 Share Posted April 30, 2009 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. Quote Link to comment Share on other sites More sharing options...
analoq Posted April 30, 2009 Share Posted April 30, 2009 Did you click the SHARC link in the OP? Quote Link to comment Share on other sites More sharing options...
zircon Posted April 30, 2009 Share Posted April 30, 2009 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. Quote Link to comment Share on other sites More sharing options...
analoq Posted April 30, 2009 Share Posted April 30, 2009 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. Quote Link to comment Share on other sites More sharing options...
Bahamut Posted April 30, 2009 Share Posted April 30, 2009 You have my sincerest sympathies, sir. Matlab isn't all that bad...we use Mathematica here, but my department did invent it after all. Quote Link to comment Share on other sites More sharing options...
Sengin Posted April 30, 2009 Author Share Posted April 30, 2009 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? http://ccrma.stanford.edu/courses/422/projects/WaveFormat/ Ah, thanks. Quote Link to comment Share on other sites More sharing options...
zircon Posted May 1, 2009 Share Posted May 1, 2009 OK, thanks for clearing that up. I guess one of the reasons I was confused was because this didn't sound like any resynthesis I've heard before. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.