how do samplers work?!


    Dec 14 2006 | 9:41 am
    i'm trying to integrate a sample player built in maxmsp with a rewire host ,usually ableton.
    how do monophonic samplers manage to play a loop triggered by midi, without clicking? (since they cant know in advance when the next midi note will occur)

    • Dec 14 2006 | 10:38 am
      adsr~ ?
    • Dec 14 2006 | 11:04 am
      adsr~ doesnt seem to work for me in this case. i dont see how i can fade to zero gain *before* retriggering the sample ,other than having every single midi note made a little bit short (a pain in the ass) to allow the envelope to close in time befor i retrigger it.
      i was wondering how a commercial sampler app deals with this problem
    • Dec 14 2006 | 3:29 pm
      it could be very great and interesting if somebody could answer to this question.
      it's really not easy for young maxers...
      and it's certainly very simple for you, o masters of max.
      :)
      please.
      ;)
      fp.
      ps: i have only a solution for simple wave (thx ej):
    • Dec 14 2006 | 3:58 pm
    • Dec 14 2006 | 4:35 pm
      Here is a solution taking advantage of info~ to know the length of the sample. If you trigger the loop, the envelope will automatically go to 0. then rise for the fade in/out time (default 10ms). The sample will play and then the envelope will fade out to 0 during the last 10 ms of the sample. Again, if you re-trigger the
      sample at any time, the envelope will re-trigger as well.
      I put in a quick little loop thing as well, so you can see how this would allow any loop to continue without clicks at the start/end points (if thats something you wanted).
      I've always found line~ and curve~ to be the best envelope tools, they do exactly what you tell them.
    • Dec 14 2006 | 5:05 pm
      After re-reading your post, i think I may have misunderstood your problem. Here is another solution using two line~ objects to do the following things:
      fade out the sample over 5 ms
      (re)trigger the sample
      fade the ssample back in over 5 ms
      This way you can re-trigger the sample over and over again, click free. I tried it and the 10 ms total fade-in out time doesn't seem too bad, though you could tweak these values up or down to taste.
      (edited....forgot a couple of things..)
    • Dec 14 2006 | 6:28 pm
      so basically youre suggesting introducing a latency into the sampler to allow time to fade out. is this what the exs24 or kontakt or whatever does? how come you cant hear a latency in those instruments?
      i would guess this concept isnt going to get on too well with a max sampler using poly~ thispoly~ etc.....
      >adsr~ @legato 1? It won't force to start at 0 (like the [route >list] trick).
      surely the envelope has to go to zero to stop the sample clicking at the start ....theres a discontinuity when the sample is retriggered, not caused by the gain envelope
    • Dec 14 2006 | 6:39 pm
      i'm really sorry but none solution work well for me.
      tried with "cello-f2.aif" in the examples/sound folder.
      ??
    • Dec 14 2006 | 7:59 pm
      i think i may have the answer!
      use adsr~ and send a retrigger amount of 10ms say. when the second outlet of adsr~ goes from 0 to 1 the sample is retriggered, so it will always trigger when the envelope is at zero. i think this will work inside poly~ too
      of course then i have a latency of 10ms, but i guess i can compensate in my host somehow
      please test this out
      max v2;
    • Dec 14 2006 | 8:26 pm
      perfect...
      thx.
      in fact i had a conflict between adsr~ (max release) and adsr~ Lyon potpourri... strange.
    • Dec 14 2006 | 9:55 pm
      I beleive you can work with two play~ or groove~ or whatever. This wait you won't have the 10ms latency... All you need to do is alternate for one to the other. When you start reading a sound from one, you fade the other.
    • Dec 14 2006 | 10:01 pm
      actually this seems to work better.....the envelope is a simple Attack-decay with retrigger setting also
      max v2;
    • Dec 14 2006 | 10:06 pm
      >I beleive you can work with two play~ or groove~ or whatever. This >wait you won't have the 10ms latency... All you need to do is >alternate for one to the other. When you start reading a sound >from one, you fade the other.
      that would double your CPU load though, if only for a millisecond or so
    • Dec 14 2006 | 10:53 pm
      Quote: bin wrote on Thu, 14 December 2006 04:04
      ----------------------------------------------------
      > adsr~ doesnt seem to work for me in this case. i dont see how i can fade to zero gain *before* retriggering the sample ,other than having every single midi note made a little bit short (a pain in the ass) to allow the envelope to close in time befor i retrigger it.
      >
      > i was wondering how a commercial sampler app deals with this problem
      ----------------------------------------------------
      realtime programs do not _need to know the next (midi)
      event _BEFORE it comes to perform an action on audio
      (like interpolating or crossfading but also think about
      _starting a new audio event.)
      realtime systems like ableton live or the plug-in interfaces
      (VST AU RTAS...) do the opposite: the events from the
      sequencing part of the software are sent _earlier than you
      think/see/hear them.
      without that simple trick cubase or protools would not even
      be able to start 10 tracks of disk audio at the same moment
      ( =within 1 sample =eventually 1/192 milliseconds)
      in the case of ableton live (i.e. or a similar solution within
      MAXMSP) you could also perform a complex declicking or
      crossfading DSP _offline as soon as the main speed in the
      "song" is changed. for such a system, you would use 2 buffers
      for every sample slot, so that the calculation of newly
      processed files will be fast enough so that one does not
      notice the process.
      lastly, if all what you are looking for is a quick hack to
      remove the bad bad click in a loop, why not just fadout
      the sample slot for 10-12 milliseconds; noone will notice
      that in a drumloop.
      or give up drumloops, they stopped beeing cool in 1996.
    • Dec 15 2006 | 1:39 am
      check out the audiorate-sequencing-looping folder in the max examples folder or msp examples or something. Groove duck I think is the name of the patch, good way to duck in and out loops at the begin and ending curtousy of jhno.
      I thought it was 93 when drum loops went out ;)
    • Dec 15 2006 | 8:57 am
      I'm not trying to play a loop, cool/uncool drums or otherwise
      youre not understanding my initial question! i cant use that groove duck patch because i'm not playing a loop. the end point is unknown by the max patch!
      the problem is to do with retriggering a sample, or playing a sequence of samples in sucession with no clicks between them, triggered by midi input.....
      adsr~ has a retrigger function, but it seems to be hard to synchronise the triggering of a sample with the zero point after the retrigger ramp down. this is not such an issue with synth patches since its less likely to be a discontinuity in the audio being enveloped
      the last patch i posted was giving me good results last night if anyone is interested in this sort of thing....
    • Dec 15 2006 | 9:43 am
      Build a poly~ player :
      [Bang]
      |
      [random 127]
      |
      [makenote 127 0]
      |
      [poly 4 1]
      | | |
      [pack 0 0 0]
      |
      (target $1, $2 $3)
      |
      yourpoly~
      |
      |
      [unpack 0 0]
      |
      [sel 127]
      |
      (startloop)
      While the[makenote]'s third inlet is fed by the seventh outlet of an
      [info~] object linked to your buffer~.
      Inside your poly~ player, you may add a smoothing mechanism (using
      line~) to get rid of clicks when retriggering : buffer the message, wait
      for line to finish, output the message.
      f.e
      f.e chanfrault | aka | personal computer music
      > >>>>>> http://www.personal-computer-music.com
      > >>>>>> |sublime music for a desperate people|
      bin ray wrote:
      > I'm not trying to play a loop, cool/uncool drums or otherwise
      > youre not understanding my initial question! i cant use that groove duck patch because i'm not playing a loop. the end point is unknown by the max patch!
      >
      > the problem is to do with retriggering a sample, or playing a sequence of samples in sucession with no clicks between them, triggered by midi input.....
      >
      > adsr~ has a retrigger function, but it seems to be hard to synchronise the triggering of a sample with the zero point after the retrigger ramp down. this is not such an issue with synth patches since its less likely to be a discontinuity in the audio being enveloped
      >
      > the last patch i posted was giving me good results last night if anyone is interested in this sort of thing....
      >
      >
      >
      >
      >
    • Dec 15 2006 | 10:15 am
      im finding buffering the message to restart the sample alot less accurate than delaying the audio from the sample player (before enveloping it).
    • Dec 15 2006 | 10:25 am
      sorry i was confusing y'all. my loop is a midi loop , not an audio one. there is no looping audio
    • Dec 15 2006 | 10:39 am
      No accuracy loss at all, unless you made it the wrong way. Works with or
      without loop.
      f.e
      f.e chanfrault | aka | personal computer music
      > >>>>>> http://www.personal-computer-music.com
      > >>>>>> |sublime music for a desperate people|
      bin ray wrote:
      > im finding buffering the message to restart the sample alot less accurate than delaying the audio from the sample player (before enveloping it).
      >
      >
    • Dec 15 2006 | 10:40 am
      Yes. Works either.
      f.e
      f.e chanfrault | aka | personal computer music
      > >>>>>> http://www.personal-computer-music.com
      > >>>>>> |sublime music for a desperate people|
      bin ray wrote:
      > sorry i shouldnt have said i was playing a loop at first, its just about triggering midi without clicks, in a loop or otherwise
      >
      >
    • Dec 15 2006 | 10:53 am
      show me a patch?
    • Dec 16 2006 | 4:29 am
      Quote: bin wrote on Fri, 15 December 2006 01:57
      ----------------------------------------------------
      > I'm not trying to play a loop, cool/uncool drums or otherwise
      > youre not understanding my initial question! i cant use that groove duck patch because i'm not playing a loop. the end point is unknown by the max patch!
      >
      > the problem is to do with retriggering a sample, or playing a sequence of samples in sucession with no clicks between them, triggered by midi input.....
      lets say a sample _usually starts with some waveform
      smoothly beginning at 0.0 - and if not, the click which
      would occur if wanted.
      so the "click problem" you see is only at the end of
      the sample - where it is cut off at an unknown time and
      instantly plays again from the start.
      a solution could be to let your sample fade out 20 ms
      or so instead of cutting it off immediatley when you
      retrigger it.
      if you ue groove~ instead of buffer~ you do not even
      need 2 buffers to play a sample with such an overlap.
      -110
    • Dec 16 2006 | 7:53 am
      bin ray wrote:
      > adsr~ doesnt seem to work for me in this case. i dont see how i can
      > fade to zero gain *before* retriggering the sample....surely that the
      > only way to have no click...
      You'd still need two voices for a mono sampler, just any new note will
      switch of the old voice with its envelope...
      Stefan
      --
      Stefan Tiedje------------x-------
      --_____-----------|--------------
      --(_|_ ----|-----|-----()-------
      -- _|_)----|-----()--------------
      ----------()--------www.ccmix.com
    • Dec 16 2006 | 11:49 am
      Emmanuel Jourdan wrote:
      > adsr~ @legato 1? It won't force to start at 0 (like the [route list]
      > trick).
      But if you jump at the same time to the beginning of the sample, it
      would create a click, it works with synths though...
      Stefan
      --
      Stefan Tiedje------------x-------
      --_____-----------|--------------
      --(_|_ ----|-----|-----()-------
      -- _|_)----|-----()--------------
      ----------()--------www.ccmix.com
    • Dec 16 2006 | 1:01 pm
      bin ray wrote:
      > that would double your CPU load though, if only for a millisecond or
      > so
      for 10ms to be exact, and only if you put it into a properly setup poly~
      - but if you're concerned about that, I'd recommend to sing, this will
      bring your CPU down to zero...
      Stefan
      --
      Stefan Tiedje------------x-------
      --_____-----------|--------------
      --(_|_ ----|-----|-----()-------
      -- _|_)----|-----()--------------
      ----------()--------www.ccmix.com
    • Dec 16 2006 | 1:05 pm
      Roman Thilenius wrote:
      > or give up drumloops, they stopped beeing cool in 1996.
      I thought it was 1986, but I guess I was ahead of time that time.
      (Timing has been confusing me always thats why I can't keep it...)
      Stefan
      --
      Stefan Tiedje------------x-------
      --_____-----------|--------------
      --(_|_ ----|-----|-----()-------
      -- _|_)----|-----()--------------
      ----------()--------www.ccmix.com
    • Dec 17 2006 | 12:13 pm
      >bin ray wrote:
      >> that would double your CPU load though, if only for a >millisecond or
      >> so
      >for 10ms to be exact, and only if you put it into a properly setup >poly~
      >- but if you're concerned about that, I'd recommend to sing, this >will
      >bring your CPU down to zero...
      do you not think it would be a problem to double CPU load for even 10 ms? it would certainly screw up the audio output if you went above 100 percent load....crossfading isnt an option for me since i am working at around 50 percent CPU load normally
    • Dec 17 2006 | 12:25 pm
      the last patch i posted using line~ seems to give me clickless playback using a host sequencer, or from any midi input. albeit with a latency of the same time as the retrigger time.
      however it would be useful if anyone could tell me to use adsr~ to do the same thing seeing as thats what it is supposed to be for? and its nicer for muting and stuff.
      please build me a patch! you clever people
    • Dec 17 2006 | 1:51 pm
      Quote: bin wrote on Thu, 14 December 2006 19:28
      ----------------------------------------------------
      > so basically youre suggesting introducing a latency into the sampler to allow time to fade out. is this what the exs24 or kontakt or whatever does? how come you cant hear a latency in those instruments?
      >
      I assume these samplers are all polyphonic, which means they will always start a newly triggered sample on a new voice (just like poly~), fading out the previous sample independently from the new one in its own release phase. This is a feature that of course uses more cpu power than a monophonic approach. If there would be only one voice I assume you'd get clicks.
      Mattijs
    • Dec 17 2006 | 2:17 pm
      > please build me a patch! you clever people
      >
      I didn't give an answer to your last post because of this. Don't order
      people to 'show a patch' as i usually do when asking for C code
      about delays ;-)
      We sure got the solution but :
      1 - you don't explain your problem _clearly
      2 - you're way too much nervous & aggressive to give people the taste to
      help you.
      Again, the 10ms solution is the best one in any case, mono or poly.
      Human usually detect a delay starting at 20ms... I use this solution
      since years, in *every* MSP patch i have, to avoid any kinds of clicks.
      5ms fade out, then 5ms fade in. Simple as that. If it doesn't work at
      your home, it's because you don't build it correctly.
      If your ears are too delicate for this delay, it also depends how long
      is your sample. If you're playing a drum, building a minimum voices
      poly~ would never charge your cpu. And for drum, you don't even need
      anything else than a simple groove~ player AND the fade solution. If
      you're playing long waves, 24 poly voices will be ok. About commercial
      samplers, please note that, in the case of Kontakt, for example, there's
      ALWAYS a problem with voices, stealing & cpu charge. All my different
      versions of Kontakt begun to play shit after the 24 full voices were fed.
      Forget about adsr~, it's not as good as it seems to be. Build your own
      enveloppe with line~ or, better, curve~. This last one will allow you to
      use a very handfull curve factor.
      f.e
      > --
      > www.myspace.com/binray
      >
      >
    • Dec 17 2006 | 2:53 pm
      "please build me a patch" is not meant to be agressive.
      its alot easier for me to understand a patch than a description of one. i share enough of my patches, such as they are. you can have the tracks i made with em for free too!
      anyways, i agree adsr~ seems not as useful as building your own envelope... i couldnt get rid of clicks using adsr~ in a monophonic player
      and you are all very clever;)
    • Dec 17 2006 | 3:19 pm
      Ok. If you're ok in a mono world, here's what you need :
      [ddg.mono] external by Darwin Grosse (you should have since your first
      days, if not -> Maxobjects.com)
      [fe.nocut~.pat] :
      [fe.nocut~.help] :
      This is an example patch built from yours :
      cheers
      f.e
      f.e chanfrault | aka | personal computer music
      > >>>>>> http://www.personal-computer-music.com
      > >>>>>> |sublime music for a desperate people|
      Mattijs Kneppers wrote:
      > Quote: bin wrote on Thu, 14 December 2006 19:28
      > ----------------------------------------------------
      >
      >> so basically youre suggesting introducing a latency into the sampler to allow time to fade out. is this what the exs24 or kontakt or whatever does? how come you cant hear a latency in those instruments?
      >>
      >>
      >
      > I assume these samplers are all polyphonic, which means they will always start a newly triggered sample on a new voice (just like poly~), fading out the previous sample independently from the new one in its own release phase. This is a feature that of course uses more cpu power than a monophonic approach. If there would be only one voice I assume you'd get clicks.
      >
      > Mattijs
      > --
      > SmadSteck - http://www.smadsteck.nl
      > Interactive audiovisual sampling soft- and hardware
      >
      >
      >
    • Dec 17 2006 | 5:02 pm
      thanks!
      that fe.nocut~ patch is just what i needed...
    • Dec 17 2006 | 6:54 pm
      use the pipe object to delay the midi note for 5ms or so, and have a bang go to the adsr~ to start from zero gain. Then the delayed midi note is processed.
    • Dec 18 2006 | 9:31 pm
      f.e wrote:
      > Forget about adsr~, it's not as good as it seems to be. Build your own
      > enveloppe with line~ or, better, curve~. This last one will allow you to
      > use a very handfull curve factor.
      I completely agree, though I use cycle~ for fades, it just sounds so
      much better...
      (just to add another approach for enhanced confusion experience... ;-)
      Stefan
      --
      Stefan Tiedje------------x-------
      --_____-----------|--------------
      --(_|_ ----|-----|-----()-------
      -- _|_)----|-----()--------------
      ----------()--------www.ccmix.com
    • Dec 20 2006 | 3:39 am
      > Forget about adsr~, it's not as good as it seems to be. Build your own
      > enveloppe with line~ or, better, curve~. This last one will allow you
      > to use a very handfull curve factor.
      >
      Quick hack for exponential envelopes with adsr~:
      adsr~
      |
      |
      *~ (send the leftmost outlet of adsr~ into BOTH inlets of *~)
      Now when you set the velocity for adsr~, presumably at control rate,
      just take the square root before sending it in to adsr~. Same for
      sustain point.
      You can't adjust the curve factor, but it definitely improves the sound
      of adsr~ and it's CPU cheap.
      Also, if you're using line~ and function (the graphical envelope
      object) be sure to check "output only list for line~". This ensures
      that it sends only one control-rate event rather than two, so the time
      accuracy will be better. (try it both ways in a
      line~-bang-when-done-loop and you'll see...)
      Peter McCulloch
    • Dec 20 2006 | 12:41 pm
      On 20-Dec-2006, at 4:39, Peter McCulloch wrote:
      > Quick hack for exponential envelopes with adsr~:
      >
      > adsr~
      > |
      > |
      > *~ (send the leftmost outlet of adsr~ into BOTH inlets of *~)
      That's not exponential, it's parabolic. Those are two different animals.
      A parabolic release curve is maybe better than linear, but don't
      pretend it's the same as exponential.
      -------------- http://www.bek.no/~pcastine/Litter/ -------------
      Peter Castine +--> Litter Power & Litter Bundle for Jitter
      Universal Binaries on the way
      iCE: Sequencing, Recording &
      Interface Building for |home | chez nous|
      Max/MSP Extremely cool |bei uns | i nostri|