Analysis – 0 detection buffer/cropper ?
This is my first post on this forum. I am a Max beginner, well a complete beginner at programming, etc in general, but I am loving it! :) Nice to meet you all, I am 5mg3 (Smudge).
I am working on a project where a recording is taken of the participants voice and played back at them in various ways. A sensor (URF) triggers the record when they are in position. However, this means there will be significant unwanted audio recorded.
What tool(s), methods and techniques can I use in order to crop the audio to the desired sample? What objects will I need to use and what would be the best way of approaching such a task?
Some sort of ‘analysis’??
I do this using peek~ into a buffer with an uzi and a counter looking for a threshold.
For instance this is from one of my patches – looks for a threshold above absolute value of 0.07 or greater in the first 10 seconds of a buffer~. It takes a look every 10 samples (for speed in live situation) – this seems to be enough for what I use it for, but you might want to do every sample. Before doing this I normalize the recorded sample using the normalize command of waveform~. This really helps if you are using signals of varying intensity (ie different instruments or people all the time). Then I use waveform~ to crop to that many milliseconds into the buffer. Or if that is not important, just tell groove~ to play starting that many ms in.
----------begin_max5_patcher---------- 707.3oc0XksiaBCE8YxWAhGqnodkk9Pk52PerZTEj3IwcXIJXZSmQS+1qWHS xjIPMDDh4Er7Rt9bO2UmmV33kVdfU449Y2u6537zBGG8RpEbZl63kmbXUVRk 9Xdo0BQYgmuYqh5bdQFSn2C1r3tDwps7hM+XOakvHaHfBWB7cQ3P8.33W26Z 9Q70ZwWl9yOBwmI9xZwkx2rj3O6XFg6klTrwy8N0tOuXg5iukZy8Ykx6n+ZS bfRABvD0.sasAEbT92WVHJRx0v16q64IYWWQQsonR3lH77eQiOStU7G0mBhV BF.QTv9sDrGgifcPqpdexkPVBuJ+frfe.wpABra9Iru7Cra9YB3EdgXnjBMR 6zfQKocQJQiFonv5XRI4rppjMr2vIo6YIOzaVABLQOXvIWEXTarBczXkQkRF XRQH13QfisHoHBMYYEawoe0VoDY8WKMJFEDYSxRPesv3Vsv9MwoieHPKDzWb kpUX+CALDDIzjsjzIAACmsIFZgURRqj7xPcaHTpd.2MqDMiqgLvlLfDc1ABR G2DD2MA7NtIiOHqMNzfFLJvhpoPz7MnoNOksenQGXJwFmCxn4bzjPcpbM1wX O7W2L9uXeKIeWF65shhsfnhMcVnfWWLE88Wun0OxkEMj8Q0+NRC0AOn.SFlN SwFGMZEl0NO9mFsMjReFuLdwkuXUqap0eM4UUVue0wK83CKcOocqYUBdQhfK ac6zgTJ5YGZKe8ZldePyJ4706JkXtADszgk0XR0S6bCT5qC8evjNq5TxTWbe sgJxbDUp2y4BsGURwFqJogIQl7V.8ebxESog.yTX7KSuY+Q60moLJIxJTENw nJzJTELwnxNKHsenRFXQUdjTS0BHBCuxTDpwiDD+xzaNByJaObhs8P6r8fI1 1CdUdl1P0Tm4lZkELZVhpIN58h5WsgJ5MfJ4jmW7OnY.0YH -----------end_max5_patcher-----------
Alternately, since max is made for realtime, just define a threshold and keep track of how far into recording it is crossed with "timer". The only problem here is that you don’t get to normalize for how loud the original voice is. But maybe you could record the occurrence of several different thresholds and the max amplitude over the recording, and depending on what the max gain is, choose which threshold to crop your audio to.
PS – and definitely use uzi instead of metro with peek~ – with metro bangs are scheduled for realtime. With uzi, they happen as fast as your computer can do them, which is much, much faster (hopefully!) But beware that other realtime stuff scheduled to happen while uzi is banging out like 1000000 times can sometimes get delayed.
Thanks arvidtp that was really helpful but I am still a little stuck, could you show me an example with the use of the waveform~ and audio input please?
waveform~ just attaches to a buffer~ with a "set buffername" message – see its help file. Then AFTER the buffer is recorded with record~, you use the crop and/or normalize commands on the waveform~, then play the buffer back. I dont have an example handy but it is pretty simple.
You don’t need to walk around your buffer~ to find zero crossings and transients – if you do it via uzi, depending on the duration of the audio you’re examining, this might also hang your max for a while…
same thing for normalizing – you don’t really need to do it!
what I would do is:
- while you’re recording, check for transients and silences to detect the actual beginning and end of the speech. you may use a timer object to track the start and end positions relative to the beginning of the recording. then you can use these values as the groove~’s loop boundaries.
- while you’re recording, keep track of the maximum amplitude (or, why not, the max RMS power) of your audio: you will use this value (well, its [!/ 1.], actually) as the gain for your playback.
- when you play back your audio, you can send groove~ the startloop message; you can use groove~’s right outlet to stop the playback and control a trapezoid~ object to perform a very short fade-in and fade-out in order to avoid clicks!
I can’t send you an example patch right now, but I hope this helps…