From the original SynthMaker forum (2004–2014), with its members’ names and dates.
distante ·
I'm trying to generate the first armonic of a signal,
I'm using an 1k test tone to make my tests,
I have inside my module a code module with this code
monoin in;
monoout out;
But I don't know how to extract the amplitude and frecuency of the [b]in[/in] variable so I can made the math with them
Help please?
Thank you
oddson ·
The first harmonic is the fundamental...
If you mean the second harmonic or first overtone then you mean an octave.
The usual analog way of adding an octave is to rectify the signal -- which adds much more than just the first overtone but that plus filtering it about all you can do in analog.
There are other options but -- as I understand things -- none are simple.
Here some code that rectifies (take the absolute value), removes the DC offset and expands back to full range.
A lowpass will remove some of the other overtones this will add.
martinvicanek ·
Hey distante,
to get the amplitude of a signal you would use an envelope follower, which is basically a rectifier followed by a lowpass. Look at the stock module, there is a codeblock inside which you can examine.
Frequency or pitch extraction is a bit more tricky. If your signal is single-pitched with a dominant fundamental, then the zero crossing method is most efficient. Search for "zero crossing" on the forum, Trog has posted a ready-to-use module. There are alternatives based on autocorrelation, where you compare the original signal with a delayed version. If you can find a delay time where the signal essentially folds back on itself, that will give you the (inverse) frequency. These methods are more CPU demanding than zero crossing however they may perform better on signals with rich spectral content.
Hope that helps!
distante ·
oddson wrote: The first harmonic is the fundamental...
If you mean the second harmonic or first overtone then you mean an octave.
The usual analog way of adding an octave is to rectify the signal -- which adds much more than just the first overtone but that plus filtering it about all you can do in analog.
There are other options but -- as I understand things -- none are simple.
Here some code that rectifies (take the absolute value), removes the DC offset and expands back to full range.
A lowpass will remove some of the other overtones this will add.
Yeap, I was talking about the second harmonic, Sometime I'm stuck with the musician theory where the second acoustic harmonic is the first musical one. Big Sorry!
I'm not afraid (yet) to enter into complicated low level coding, after all, I'm doing this for as a "final project" in my place of study; so I'm already prepare to take the hard path, It's just that somethings are managed in a different way in SW, so It's very possible that I will be posting a lot of stuff here 😊.
I will take a look of your code and tried. Thanks!
martinvicanek wrote: Hey distante,
to get the amplitude of a signal you would use an envelope follower, which is basically a rectifier followed by a lowpass. Look at the stock module, there is a codeblock inside which you can examine.
Frequency or pitch extraction is a bit more tricky. If your signal is single-pitched with a dominant fundamental, then the zero crossing method is most efficient. Search for "zero crossing" on the forum, Trog has posted a ready-to-use module. There are alternatives based on autocorrelation, where you compare the original signal with a delayed version. If you can find a delay time where the signal essentially folds back on itself, that will give you the (inverse) frequency. These methods are more CPU demanding than zero crossing however they may perform better on signals with rich spectral content.
Hope that helps!
Hello martinvicanek,
In the end I want to run a real time vst (as in insert in a DAW) with this "harmonic generator" in a channel with some musical content , so I supposed that the delay stuff isn't the best option (I need to read it first). I will look for zero crossing and mess with the stock module thanks!
*****************************
I hope what I want to do is possible with SW, If not I will need to change my project request 🙁
treacherousumbrella ·
A 2nd order Chebyshev polynomial will give you the 2nd harmonic if the input signal is a full value sine wave.
out=-1 + 2in^2
martinvicanek ·
distante wrote: I want to run a real time vst (as in insert in a DAW) with this "harmonic generator" in a channel with some musical content , so I supposed that the delay stuff isn't the best option
There will be some latency even with the zero crossing method, since you need to wait at least one complete cycle to know the actual period or frequency of a single-pitched signal. The correlation method will require a bit more than one cycle, however both methods are fast enough for real time applications.
distante wrote: I hope what I want to do is possible with SW, If not I will need to change my project request 🙁
If you want to add an octave (= second harmonic = first overtone) in real time to a single-pitched signal, yes, that's perfectly possible. I am stressing "single-pitched" because musical content is often polyphonic, and then pitch detection beomes really, really tricky. Only very advanced software like Melodyne can do that reasonably well, however not in real time.
distante ·
Mmm, the ultimate goal will be to used this in music content.
I saw One person who did this using the language program that REAPER had inside: JESUSONIC (http://www.cockos.com/jesusonic/)
But had the disadvantage that you need or use REAPER for use the plugin or use a bridge.
Using that language (JESUSONIC) he managed to do this:
So... I'm trying to do something like that but in SM... But I'm not quite sure now if it's possible...
trogluddite ·
That JS code is definitely possible in SM - it's very much like oddson and treachorousumbrella's suggestions - adding the harmonics by distoritng the waveform directly. It will add much more than just 2nd harmonics - I couldn't begin to guess the harmonic content of that function, but most forms of distortion will have particular ones that they emphasise. It's also way, way less demanding on the CPU than frequency extraction etc.
The harmonic generation is actually only a tiny part of the code - just the two lines with the 'sin' and 'cos' functions, at the start of the code proper ("@sample"). The remainder of the code is just a series of 6dB filters - and there are many alternative filter modules around for SM that can be used for this.
Most of the stuff before the "@sample" marker needn't be in your code at all - it is just scaling the controls appropriately, which you can do using the properties of SM's knobs, and a few "green" maths modules.
Most of the maths formulae can be used in SM just as they are, it has all of the functions you need. SM code differs slightly in the way it uses variables, and the conditional bits ("?") have to be done a different way. I've used JS a bit, so if you want a hand porting the code, let me know and I'll post a few pointers.
distante ·
Well I really never used JS, I rater don't get my head into other language until I'm comfortable enough with SM (since you already confirm that want I want to do is possible, I will stick to SM, I'm in process to get the money to buy the student version 🙂
I'm now looking for the math expression for the pair and odd harmonics so I can try to distort the original signal and add this.
I'm still a little bit confused on how can I get the info of the freq and amplitude of the signal in a code box. Seems like the monoin or streamin (or whatever-in) just manage amplitude, that part in the manual doesn't specify what is what (maybe because is something that It's suppose to be known it by me 😊 😊 )
trogluddite ·
All of the stream connection (mono, mono4 and poly) only have the actual values of the samples as they pass through - so yes, just the instantaneous amplitude for a tiny fraction of a second. The stream data is like points on a graph that draw the "sound wave". For recording and playing audio that's just what is needed because the voltages in microphones, speakers etc. also follow the contour of the waveforms
As you may have guessed from the other posts, working out the frequencies that are there is actually a pretty difficult thing to do - kudos to nature for providing us with a brain and ears that do the same job so effortlessly!
For a hell of a lot of processes, this just doesn't matter - echo, chorus, synths etc. all work really well from the raw wave data. Other things like pitch-shifts, or time-stretches really do need to know the frequency if they are to work properly.
Your harmonics project is in the grey-area between these two extremes. On one hand, you have the option of a complex, CPU intensive frequency anaylsis etc. - which, in principle, could accurately generate a very clean, precise 2nd harmonic. Or, there are the "distortion" methods - less accurate, and they need some "side-effects" filtering out; but no sweat for your CPU.
Whether you prefer accuracy, or speed and simplicity, is your choice as the designer. If your tutor is a good one, he will not judge you for the complexity of your code - there is no shame in keeping things simple as long as you can explain why.
distante ·
Oh, So the stream is something like the array of amplitude values in time don't? Like in MatLab!
Well since I need to reproduce more than just the second harmonic, I will go for the distortion method, also because If I use the one that need a lot of CPU process using it in real time will be painful so a destructive off line method will be better, BUT I don't that I can't afford the cost of the SM Pro to export to .EXE
I will need to talk this things with my tutor, I hope to have my first meeting with him on Tuesday, until then I will continue exploring the modules and maybe work a little bit in the GUI.
Thanks to you all for your time and patience.
trogluddite ·
distante wrote: BUT I don't that I can't afford the cost of the SM Pro to export to .EXE
Note that the Enterprise edition (half the price) will also export .exe's - and the "restrictions" to features are not likely to be a problem for the vast majority of designs.
Also the Free version will export VST's - there is an annoying "noise burst" on the sound sometimes (to encourage customers to pay for registered versions) - but that may not be a big problem if you just need to show your progress to your tutor.
If you (or your tutor) do not have a suitable VST host, then there are some freeware hosts (e.g. VSTHost) that you could use for testing etc.
distante ·
trogluddite wrote:
distante wrote: BUT I don't that I can't afford the cost of the SM Pro to export to .EXE
Note that the Enterprise edition (half the price) will also export .exe's - and the "restrictions" to features are not likely to be a problem for the vast majority of designs.
Also the Free version will export VST's - there is an annoying "noise burst" on the sound sometimes (to encourage customers to pay for registered versions) - but that may not be a big problem if you just need to show your progress to your tutor.
If you (or your tutor) do not have a suitable VST host, then there are some freeware hosts (e.g. VSTHost) that you could use for testing etc.
I see, while I'm doing the vst "design" I can use the free version (hehe, I feel like I'm thinking too much of me for saying "do the design" )
Then after do my official presentation buy the Enterprise edition so the jury of my project (besides my tutor, there's 3 teachers) don't have any problem using the VST, and they can test it without any disturb 😀
Wrote something here? To have a post removed or your name hidden, write to [email protected].