Reading peaks from a waveform

Luca De Rosso's icon

Hi there,
I've been working on this retarded patch the whole morning and I did all I need except for this little problem.
Here is a simplified version of the patch I'm working on.

1 / Just replace a sample into the buffer
2 / Toggle the [sig~]
3 / Change the number to move wherever you want on the sample and bang the [peakamp~].

From what I learned from the max help at this point the [peakamp~] should give me the amplitude value but most of the times it seems incorrect.

Do you have any idea about how to read peaks at specific points?

Thanks as always.

1305.wavereader.maxpat
Max Patch
Tim Lloyd's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Does this help? You're using a millisecond value to check the peak values, and this won't be sample-accurate, so will miss some peaks.

Luca De Rosso's icon

Thanks Tim,
suddenly I thought that your solution was working correctly but I then figured out that I was having the same problems. It looks like a max problem but I don't know how to explain it.
Try to put the attached file into the buffer for example. There are some empty parts in the loop which are read from the [peek~] and the [peakamp~] as well giving really strange values that looks non sense to me.

Anyway thanks for remembering me about the [peek~]. I didn't like to use a [groove~] for that.

1306.110_DRM_track#06.aif
aif
Tim Lloyd's icon

The link to your .aif isn't working. I have to go make some soup before I implode, but I'll have a little think about it while I cook :) You're not driving the [groove~ > peekamp~] and [peek~] with the same integer object are you? That would produce completely different results as one is ms and the other is samples.

Luca De Rosso's icon

Hey I was wrong!
Your last message opened my eyes in some way!
I was using the same number to move the line on the [waveform~] and to control the [peek~] as well. But in order to match the visualization and the [peek~] output I had to multiply by 44.1 the number before going into the [peek~].
I've attached the final one.

Thanks Tim

1307.wavereader.maxpat
Max Patch
Luca De Rosso's icon

By the way, have a nice lunch... or dinner.

Roman Thilenius's icon

for peak by sample just use minimum and maximum ...

Tim Lloyd's icon

I don't think degezo wants the "peak" value of the buffer, but rather the rectified amplitude value of a variable time point within the buffer.

(so in my comment object, I shouldn't have put "peak sample value" because it isnt ;) )