Old 06-03-2017, 09:42 AM   #1
Chain
Human being with feelings
 
Join Date: May 2017
Location: Italy
Posts: 19
Default Midi Sinewave Synth (Need Help)

Hello!! I made this sinewave synth ... I am a noob at coding and my idea was to learn jsfx to countine development in c one day....
It is still not finished... I wanted to ask if there is the possibilty to get the noteon value and the note off value
My idea:
Midi:when the noteon comes then the *of the frequency should initalise
and when the noteoff comes it should stop..
Is there a possibility to write that with a if/else.. i think it is with the "?"...
Code Idea: When noteon_cnt stopped ramp volume to 0 in 50 ms(or probably more to avoid clicks)...
Is it better to do this with an amp envelope?
how to ramp things? I mean in a software called pure data there is a object called line... it has the function to get from a value to a value in a certain period of time... example: go from 0 to 1 in 1000ms
how to code that?
Sound is just coming when i move the * of the frequency... and not when the noteon_cnt is starting... how to trigger that?
Am i using the right code?
sorry for so much questions... i got very intrested in jsfx coding...
just i cant find those things on the net..
Attached Files
File Type: zip sinusoid.zip (692 Bytes, 145 views)
__________________
Instrested in everything!! Hit me up!!
Chain is offline   Reply With Quote
Old 06-03-2017, 10:33 AM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Generating sinus frequencies of arbitrary frequencies supposedly will introduce terrible aliasing problems. I suppose this can be overcome (I did see non-aliasing JSFX code), but needs some decent planning.

If you don't want realtime (live playing), using FFT might be a more promising approach for an "additive synthesis" instrument.

-Michael
mschnell is offline   Reply With Quote
Old 06-03-2017, 10:41 AM   #3
Chain
Human being with feelings
 
Join Date: May 2017
Location: Italy
Posts: 19
Default non-aliasing JSFX code?

sorry but .... what is a non-aliasing JSFX code?
are there some resources that i can read about that?
Edit:
That means there could be some error in the dsp process or noise?
is this better? spl0=sin((OscPhase+=1)*Frequency)
Edit:
found some useful information here:
http://ajaxsoundstudio.com/cookdspdoc/
__________________
Instrested in everything!! Hit me up!!

Last edited by Chain; 06-03-2017 at 05:33 PM.
Chain is offline   Reply With Quote
Old 06-04-2017, 01:03 AM   #4
bezusheist
Human being with feelings
 
bezusheist's Avatar
 
Join Date: Nov 2010
Location: Mullet
Posts: 829
Default

Quote:
Originally Posted by Chain View Post
sorry but .... what is a non-aliasing JSFX code?
are there some resources that i can read about that?
Check out the code for the JS tone generator, very simple, no aliasing for sine waves.
I honestly have never seen a sine gen alias, so no idea what mscnell is talking about...
__________________
I like turtles

Last edited by bezusheist; 06-04-2017 at 01:18 AM.
bezusheist is offline   Reply With Quote
Old 06-04-2017, 01:59 AM   #5
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by bezusheist View Post
I honestly have never seen a sine gen alias,
Maybe as the aliasing is at "SampleFrequency - WaveFrequency", it might be sufficient to make sure that the WaveFrequency is not higher than half the SampleFrequeny, which does make sense, anyway.

The JS tone generator produces tons of aliasing when in saw and triangle mode !

-Michael
mschnell is offline   Reply With Quote
Old 06-04-2017, 02:10 AM   #6
bezusheist
Human being with feelings
 
bezusheist's Avatar
 
Join Date: Nov 2010
Location: Mullet
Posts: 829
Default

Quote:
Originally Posted by mschnell View Post
Maybe as the aliasing is at "SampleFrequency - WaveFrequency", it might be sufficient to make sure that the WaveFrequency is not higher than half the SampleFrequeny, which does make sense, anyway.

The JS tone generator produces tons of aliasing when in saw and triangle mode !

-Michael
yeh, you need to stay within the boundaries, for sure w/sines...
the saw/tri are just nasty, regardless. not the best code for those.
__________________
I like turtles
bezusheist is offline   Reply With Quote
Old 06-04-2017, 04:44 AM   #7
Chain
Human being with feelings
 
Join Date: May 2017
Location: Italy
Posts: 19
Default adding harmonics with sinewaves...

i have learnd that there is a formula(i cant find it yet)
were you can calculate the harmonics of the saw,square,triangle,ecc. just by adding sinewaves
i think it is for the saw: 2ndharmonic= 2*freq/(amp/2) 3rdharmonic=3*freq/(amp/4)...
how about to add different sinewaves and with that formula into the js code and lets say to calculate 24 harmonics for each....
it will be a long code...
has somebody tried that?
are there some problems with disturbs or noise or something?
and thanks for the answers....
edit:
if that is a solution i could do that with excel..
has the alaising thing to do with the "Nyquist–Shannon sampling theorem"?
This says that a audio signal with fmax can be reconstructed as a digital signal if the sampling frequency is bigger than 2*fmax. (Got this from wikipedia, correct me if i am wrong)....
if the frequency is higher than fmax*2... then i have to apply a lowpassfiler? with cutting(idk if this is the right therm) of -60db?
has that to do with the 44100?
__________________
Instrested in everything!! Hit me up!!

Last edited by Chain; 06-04-2017 at 08:47 AM.
Chain is offline   Reply With Quote
Old 06-04-2017, 02:07 PM   #8
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

Quote:
Originally Posted by Chain View Post
i have learnd that there is a formula(i cant find it yet)were you can calculate the harmonics of the saw,square,triangle,ecc. just by adding sinewaves
This is what FFT does. FFT in fact creates not aliasing signals that way (but there are other (supposedly more realtime-enabled) ways to do this.
...
In a digital system (software) you only can't apply a lowpass filter that is decently lower than half the sample frequency. Higher frequencies are kind of "virtual" and not affected by such a filter software, as same is "inside" the digital system. To avoid those they need to be avoided when constructing any waveform.

There is a non aliasing wave generator JSFX somewhere...

-Michael

Last edited by mschnell; 06-04-2017 at 02:14 PM.
mschnell is offline   Reply With Quote
Old 06-04-2017, 02:49 PM   #9
Chain
Human being with feelings
 
Join Date: May 2017
Location: Italy
Posts: 19
Default

that means i just have to use the right sinewave code and i will have no problems... right?
__________________
Instrested in everything!! Hit me up!!
Chain is offline   Reply With Quote
Old 06-04-2017, 10:42 PM   #10
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,686
Default

I suppose creating multiple sine-waves and adding them should be just fine.

But if you modify the volume of a running sine (i.e. doing an envelope) it's not a sine any more, and hence it is prone for aliasing. I don't know when this does harm and how it can be avoided.

(Generally, the way to avoid aliasing is "oversampling"): virtually create the wave form with a higher sampling rate and do an appropriate low pass filter software at that rate before creating the final samples.)

-Michael
mschnell is offline   Reply With Quote
Old 06-05-2017, 04:58 AM   #11
Chain
Human being with feelings
 
Join Date: May 2017
Location: Italy
Posts: 19
Default thanks!!

i will try that.. i will post the results then
will the filter type be a brickwallfilter?
Edit:
to get note on and note offs :
msg3>0 ? noteon=1 : noteon=0;
@sample
spl0=spl0*noteon;
spl0=spl1*noteon;

still struggling about how to ramp things....
__________________
Instrested in everything!! Hit me up!!

Last edited by Chain; 06-06-2017 at 02:43 PM. Reason: more questions
Chain is offline   Reply With Quote
Old 10-05-2017, 01:49 PM   #12
Chain
Human being with feelings
 
Join Date: May 2017
Location: Italy
Posts: 19
Default FM

actually i think i should make an option to filter the alasing freqencys out and an option to bypass it.....
in alasing freq are very intersteing to create new types of sound...
actually in FM it can be mindblowing....
but still the envelope is very difficult.... at least i made a attack but the decay keeps increasing it..
__________________
Instrested in everything!! Hit me up!!
Chain is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.