problem with synth envelope

stefano capas's icon

hello i have build a small synth with 1 sine osc and ring modulator
I have used the function elements as adsr control
I can't get to have a sound that last for as long as i play
If i do like in th epicture sounds have a short duration and then it stop
If i remove the vertical line..i can have a sound playing for as long as i press the key..but no control on release..
how can i do that?

Source Audio's icon

use adsr~ instead of function

stefano capas's icon

i know..but i wanted to try the function for more capabilities

Source Audio's icon

well then you need to set sustain mode for the point that you want to keep while holding the note.
bang to run till that point, next to proceed

stefano capas's icon

how do i do that in practical?

Source Audio's icon

I‘ll post example when I get home later
it is quite simple

stefano capas's icon

ok thank you

Source Audio's icon

I think you need curved shapes, otherwise adsr would do as well.
this exmple covers it all.
point number 2 is set as sustain, bang starts and runs till first sustain point, next message continues till the end or next sustain point if there are any.
mouse click - release triggers them.

Max Patch
Copy patch and select New From Clipboard in Max.

stefano capas's icon

ok thank you
I am trying to adapt it to a simple patch where i have a notein from external midi keyboard and oscillator

Source Audio's icon

you can scale curve~ output from velocity

Max Patch
Copy patch and select New From Clipboard in Max.

stefano capas's icon

ok thank you..this is perfect for me
I just would like to properly understand all this code
Is most of this code needed for my requirements..or there si more?
i want to attach my projet to understand how much of your code is really needed. Of coourse i know that the oscillator part is not needed.
but i want to understand

{
    "patcher" :     {
        "fileversion" : 1,
        "appversion" :         {
            "major" : 8,
            "minor" : 5,
            "revision" : 6,
            "architecture" : "x64",
            "modernui" : 1
        }
,
        "classnamespace" : "box",
        "rect" : [ 47.0, 85.0, 1380.0, 905.0 ],
        "bglocked" : 0,
        "openinpresentation" : 0,
        "default_fontsize" : 12.0,
        "default_fontface" : 0,
        "default_fontname" : "Arial",
        "gridonopen" : 1,
        "gridsize" : [ 15.0, 15.0 ],
        "gridsnaponopen" : 1,
        "objectsnaponopen" : 1,
        "statusbarvisible" : 2,
        "toolbarvisible" : 1,
        "lefttoolbarpinned" : 0,
        "toptoolbarpinned" : 0,
        "righttoolbarpinned" : 0,
        "bottomtoolbarpinned" : 0,
        "toolbars_unpinned_last_save" : 0,
        "tallnewobj" : 0,
        "boxanimatetime" : 200,
        "enablehscroll" : 1,
        "enablevscroll" : 1,
        "devicewidth" : 0.0,
        "description" : "",
        "digest" : "",
        "tags" : "",
        "style" : "",
        "subpatcher_template" : "",
        "assistshowspatchername" : 0,
        "boxes" : [             {
                "box" :                 {
                    "id" : "obj-6",
                    "maxclass" : "newobj",
                    "numinlets" : 2,
                    "numoutlets" : 2,
                    "outlettype" : [ "int", "int" ],
                    "patching_rect" : [ 648.5, 351.0, 59.0, 22.0 ],
                    "text" : "stripnote"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-9",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 2,
                    "outlettype" : [ "bang", "int" ],
                    "patching_rect" : [ 677.25, 478.0, 29.5, 22.0 ],
                    "text" : "t b i"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-7",
                    "maxclass" : "newobj",
                    "numinlets" : 2,
                    "numoutlets" : 2,
                    "outlettype" : [ "signal", "bang" ],
                    "patching_rect" : [ 1011.333333333333371, 742.0, 34.0, 22.0 ],
                    "text" : "line~"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-5",
                    "maxclass" : "live.scope~",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "bang" ],
                    "patching_rect" : [ 298.0, 911.0, 184.0, 68.0 ]
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-4",
                    "maxclass" : "newobj",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "patching_rect" : [ 619.0, 218.0, 50.0, 22.0 ],
                    "text" : "midiinfo"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-2",
                    "maxclass" : "newobj",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "float" ],
                    "patching_rect" : [ 851.0, 478.0, 39.0, 22.0 ],
                    "text" : "/ 127."
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-61",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 3,
                    "outlettype" : [ "int", "int", "int" ],
                    "patching_rect" : [ 648.5, 315.0, 99.0, 22.0 ],
                    "text" : "notein"
                }

            }
,             {
                "box" :                 {
                    "attr" : "inputmode",
                    "id" : "obj-60",
                    "maxclass" : "attrui",
                    "numinlets" : 1,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "parameter_enable" : 0,
                    "patching_rect" : [ 610.0, 284.0, 150.0, 22.0 ]
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-51",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 1,
                    "outlettype" : [ "signal" ],
                    "patching_rect" : [ 778.0, 599.0, 31.0, 22.0 ],
                    "text" : "sig~"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-50",
                    "maxclass" : "newobj",
                    "numinlets" : 1,
                    "numoutlets" : 1,
                    "outlettype" : [ "" ],
                    "patching_rect" : [ 778.0, 516.0, 32.0, 22.0 ],
                    "text" : "mtof"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-49",
                    "inputmode" : 1,
                    "maxclass" : "kslider",
                    "mode" : 2,
                    "numinlets" : 2,
                    "numoutlets" : 2,
                    "outlettype" : [ "int", "int" ],
                    "parameter_enable" : 0,
                    "patching_rect" : [ 517.0, 388.0, 336.0, 53.0 ]
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-48",
                    "maxclass" : "newobj",
                    "numinlets" : 0,
                    "numoutlets" : 4,
                    "outlettype" : [ "int", "int", "int", "int" ],
                    "patching_rect" : [ 1287.25, 478.0, 50.5, 22.0 ],
                    "text" : "key"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-47",
                    "maxclass" : "button",
                    "numinlets" : 1,
                    "numoutlets" : 1,
                    "outlettype" : [ "bang" ],
                    "parameter_enable" : 0,
                    "patching_rect" : [ 983.0, 520.0, 24.0, 24.0 ]
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-44",
                    "maxclass" : "newobj",
                    "numinlets" : 2,
                    "numoutlets" : 1,
                    "outlettype" : [ "signal" ],
                    "patching_rect" : [ 624.0, 1010.0, 29.5, 22.0 ],
                    "text" : "*~"
                }

            }
,             {
                "box" :                 {
                    "id" : "obj-42",
                    "maxclass" : "newobj",
                    "numinlets" : 5,
                    "numoutlets" : 4,
                    "outlettype" : [ "signal", "signal", "", "" ],
                    "patching_rect" : [ 1282.0, 555.0, 61.0, 22.0 ],
                    "text" : "adsr~"
                }

            }
,             {
                "box" :                 {
                    "addpoints" : [ 0.0, 0.0, 0, 177.215189873417728, 1.0, 0, 436.708860759493689,

ring modulation with adsr and key.maxpat
Max Patch

Source Audio's icon

I don't unerstand your patch because there are many unconnected,
unneeded as well as contradictory objects inside.
Like - you use stripnote at midi input, but then want to use
velocity and note off ?

what should connction from / 127. velocity to function object do ?

and so on.

stefano capas's icon

sorry i send again cleaned from unused stuff

i had to put stripnote because with the keywoard the sound play when i do note on, and when i release the key, note off, it will play again..so i was told to use stripnote..and it works for midi keyboard. Of course stil have this behaviour if you play the kslider
The /127 also i was told. It seems to have a better control on velocity...

ring modulation with adsr and key.maxpat
Max Patch


Source Audio's icon

Whoever is telling you things, makes mistakes.
Nothing there makes sense.

- midi input - no note off, no velocity ?
- sending float to function makes no sense.
if it was sent to adsr~ then yes, but only if note off is received.
function set like that has no benefit to adsr~

then modulator - it is linked wrong.
you mix original cycle~ with ring modulated - which inverts the phase ...

but if it is effect that you want ...





stefano capas's icon

let me explain
i am following a teacher for the synth part
I made with him the ring modulator part and we wanted the control over the 2 signals separates..so the original cycle and the ring modulator: you say that the *~ after the 2 gain is inverting the phase?
We were looking for sperimental music creation, so may be it is what he wanted?
All the part related to the midi keyboard and enevlope control i did it searching in the web..and yes of course i might not have choose the proper info..for me seems working enough apart of the sustain, so was fine

Source Audio's icon

Please tell the techer to explain to you why he/she does one or the other thing.
For example - inserting stripnote disables normal functioning
of notes and controlling of adsr, function etc.
The only thinkable reason to do so would be to avoid triggering something
with note off .
But in your patch note number only sets freq for cycle~
and it does not matter if it gets sent once or twice.
but you loose note off, and so can't run release phase of adsr
or function.
here is patch using function with velocity, and amp modulation,
you can replace it with ring mod at the right if you prefer that.

Max Patch
Copy patch and select New From Clipboard in Max.

and here much simpler adsr~ variant :

Max Patch
Copy patch and select New From Clipboard in Max.


by the way, your patch as is can only work for single notes.
to make playable synth you need to pack as many instances of it into poly~ object


stefano capas's icon

ok..this look very good
As i said all the part regarding the midi note input and enevelope i did it by myself searching aroundThe stripnote suggestion to solve the problem i had was suggested here, in this forum, times ago when i had my first approach to max
So i start form that..i know that there is no velocity but for now i did not give it much improtance as therewere mor eimportant problems to solve. And for poliphony of course is the same! I know all this part could be not well done, as i did it puttting together various info i found

WHat really leave me surprised is the problem with synth part, all the algorhytm for the ring modulation, which is what the teacher did.
I have not enough knowledge to properly understand the differences, i see that in both (my patch and yours) the carrier and the modulating get mixed
I post what was th eoriginal i did it with him. May be it is a simplified version for teaching pourpouses? Or a version to to more sperimental? (as we want to do)

p.s.
how do i put the code the way you do, here in the forum?

ring modulation.maxpat
Max Patch

Source Audio's icon

to post patches you select all in your unlocked patch or a portion that you want to post, then select "copy compressed " in edit menu and paste it here.

.......
if you use symetric wave as modulator (oscilating -1. - 1.) ,
it multiplies carrier signal positive and negative, depending on current phase. means it inverts the phase while it's cycle is negative.
amplitude modulation uses only positive signals.

if you mix carrier with amp modulated signal, they will add and
only be louder, masking amplitude changes.
mix of carrier with frequncy modulated signal introduces phase
cancelations.

there are many tutorials, explanations etc dealing with that,
but max tutorial which is unchanged since many years shows it wrong,
telling that tremolo is ring modulator.

real tremolo effect should use amplitude modulation because one can set the depth - or limit modulating range from top 1. (no change) to any value between 1. and 0.
lower the bottom, more pronounced is volume change.

stefano capas's icon

ok so i understand better. the scale -1 1 0 1 you used is to avoid negative signal. ok
One thing is not clear yet.The algorythm you used is an amplitude modulation, AM..not a ring modulation then?
I see you have( unconnected) aside the ring modulation.
So you have used AM, not ring modulation. Does ring modulation also need only positive then?

With ring modulaton we are looking at at the modulating frequencies between 20hz and 40hz as interesting for experimenting. Tremolo is not, for now, on our interest

what tools shall i use to visually see th edifference between the signal mixed with negative and the one without? oscillocope, spectroscope or sonogram?

p.s.
much more complicated for me to understand is all th epart that comes from the velocity output of kslider, and the one form the loadbang!

Source Audio's icon

if you don't need AM then remove scale object.
I only wanted that you see the difference
because you were mixing carrier with modulated signal in your patch.

here is that patch again with few comments

Max Patch
Copy patch and select New From Clipboard in Max.

stefano capas's icon

ok clear. thanks!so ring modulation effectively use also negative

i'lll try to understand now all the rest

stefano capas's icon

hello onme thing i 'd like to ask
You put a toggle before the message SUSTAIN, that tells to sustain to stay on until i release a key
This way i don't have anymore the possibilities to make an ADSR with a sustain that has a limited time..like a piano for example
SO if i toggle the elements instead the ADSR respond to what i draw, and the sustain last acocrding the graph
Is this the way you think to this?
There is a but , though
With the toggle to off, i have the problem i told you..for which i used the stripnote: with toggle off, when i release the ky the wave is played back again, and this shouldn't happen
SO how it works then?
thanks

Source Audio's icon

you wanted to use function - now you need to learn how to use it.

if you disable sustain - you will not have it - simple as that.
That was you initial problem.
if you want shorter envelope, you have to program shorter domain,
or move points earlier, you can make presets for your function.
all is possible.


and so on ...

stefano capas's icon

yes ok..but whyt if i toggle off i have the soun playing when i release the key?

Source Audio's icon

I am sorry but I have no idea how to explain it better to you.
You should know it by now.
don't use stripnote.

stefano capas's icon

ok that's clear