Trimming leading silence from buffer~

patrickkidd's icon

I am writing a sampler and want to trim any relative silence from the beginning of the buffer~ object. This way the sample's attack will be in time with the sequencer. Does anyone know how to do this? The "silent" samples will not be zero but will be the baseline signal level from the guitar input, hence the word "relative".

I am getting pretty good with Max and Live's api but am useless for programming Msp.

Thank you so much!

Mark Durham's icon

Have you looked at waveform~ and the crop option?

That would be a manual edit. Though perhaps you could use peek~ to count through the samples until X amplitude and set display start in waveform~ there.

patrickkidd's icon

It was the detection logic I was looking for. Instead I have a multi-phase record workflow, where I "arm" the input which begins tracking the absolute peak of the clean line signal into a [peakamp~]. Then when I enable recording of the note it bangs the value out of the [peakamp~]. Then when the moment the input signal rises above this peak value, it tells [record~] to start recording.

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

I tested it with a bell sample from Ableton Operator, and I can't hear any latency in the triggering (There is bound to be a ms or so from signal -> bang conversion) :) Here is the patch.

Mark Durham's icon

I think something with counter, peek~, abs and waveform~, setting the display start and cropping till end should work. Sorry, don't have time to put something together right now.

patrickkidd's icon

And I was able to integrate my above solution into my sampler, and while it works really well it gets a little rocky when there are release or reverb tails from previous notes, (I'll sometimes record each note with about 250ms in between), or if I do the slightest finger slide between notes.

So I need to come up with a more involved silence detection algorithm. Maybe something that includes an amplitude threshold? I imagine this would have to be processed offline because of the time delay involved? Has anyone seen something like this done? It would be so cool to crop the beginning of the sample!

Buma's icon

There's something to do with Mubu + Pipo onseg maybe. Offline or Realtime. http://forumnet.ircam.fr/product/mubu/
Or "simple" thresh~ and / or edge~

patrickkidd's icon
Max Patch
Copy patch and select New From Clipboard in Max.

I used some info in another thread to end up with this:

It uses a slightly more advanced algorithm to detect when an attack spike has occurred, and also does a quick fade-in to eliminate clicks. The inlets and outlets are commented appropriately.

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

And then here is the containing sampler channel. I have eight of these to form an 8-channel sampler that I use with midi pedals and guitar, violin, etc:

Klangschmied's icon

@PATRICKKIDD
there are some missing files in your patch (poly…,pk´s.).
Would be great if you can postt it.

patrickkidd's icon

Sorry, those were just the patches to solve the problem asked in the thread. But I can post them all for sure. Is there a way to easily post full .amxd files with lots of complex sub-patchers in them? I have to post 2 amxd's here.

patrickkidd's icon

here is a link to the device on maxfirlove.com. Let me know if you want more than just that.