Gen~ to record audio

Oct 3, 2012 at 3:39pm

Gen~ to record audio

This is my first foray into gen~. I’m trying to make an audio recorder that will only start/stop recording when the input sample level is very close to zero. I think logic in the patch works fine but I’m getting bad distortion when I play back the recorded sound using groove~. Sounds ok for a while but degrades after a few passes.

Can anyone explain what is going on, and how to fix it?

Patch:

– Pasted Max Patch, click to expand. –

Cheers,

John.

#64555
Oct 3, 2012 at 5:18pm

Hey!
I don’t hear any degrading..?
best

#232912
Oct 3, 2012 at 5:24pm

now i got them.. but its the recording mechanism, not the playback, isn’t it? its recording and not recording(ie resampling) with a high frequency but not high enough to be inaudible,, sample rate reduction..isn’t it?

#232913
Oct 3, 2012 at 5:49pm

Yes it’s the recording mechanism.

Who knows how to do it right?

#232914
Oct 3, 2012 at 7:05pm

i’m not sure if i actually understand what you are trying to achieve, but i guess you should define a “recording length”if you know what i mean.
So in case the signal triggers the recording process, it shouldn’t stop recording until a specified time. I just had a brief look at your patch, but i guess that should be the problem.
Good luck
Cheers

edit: or you could do envelope following.. lowpass filtering, if you want it to stop automatically

#232915
Oct 3, 2012 at 7:21pm

The problem is the degradation in playback, I’ve stripped out all the other parts of the patch so now gen~ is just recording a sine wave and groove is playing it back. You can see and hear the distortion.

– Pasted Max Patch, click to expand. –

Can someone explain what’s going on – do i need some kind of interpolation?

Cheers,

John.

#232916
Oct 3, 2012 at 7:30pm

alright

– Pasted Max Patch, click to expand. –
#232917
Oct 3, 2012 at 7:40pm

woyteg – I’m not sure what you are showing me in that patch – but thanks for trying.

I’ve just worked out what is wrong – the sample increment using ‘%’ was causing all the problems, switching it to a ‘wrap’ makes it work perfectly. I’m not really sure why because I checked the output of ‘%’.

I wish there were some simple gen~ tutorials, have i just missed them?

working:

– Pasted Max Patch, click to expand. –
#232918
Oct 3, 2012 at 7:49pm

hey leavecutter.. what i wanted to show you is, at least on my machine, the buffer was filled with the sample i was hearing. A short burst of about 8000 hz.

#232919
Oct 3, 2012 at 8:34pm

hello, below my version of original problem. Did you find more a concise way? I’m also GEN beginner, so thanks for opportunity for learning!

– Pasted Max Patch, click to expand. –
#232920
Oct 3, 2012 at 9:45pm

Nice one Andrze,

I like what you did with the top sah!
I got rid of the other gates and made the zero crossing detector simpler. Poke is made to stop recording by driving it’s index out of range of the buffer.

– Pasted Max Patch, click to expand. –

John.

#232921
Oct 3, 2012 at 11:26pm

smart zerocrossing detector! But I think ‘out of range’ also means negative values (no need for all those zeros ;))

– Pasted Max Patch, click to expand. –
#232922
Oct 4, 2012 at 3:20am

Hi there,

The strange behavior with % appears to be due to some kind of floating point error, as far as I can tell, in how the % operator is implemented. Although it doesn’t show up in the number~ box, there’s an extremely small fractional offset of the value which is sometimes pushing the sample writing position forward by 1 sample, causing the distortion. The [wrap] operator on the other hand is implemented in a more complex set of instructions which take more care to ensure valid results.

The implementation of % has been flagged for further investigation (ticket #3624). In particular, in this case it should be possible to deduce that it can operate on integers only, which would avoid the problem entirely.

Best,

Graham

#232923
Oct 4, 2012 at 3:51am

I got curious about something that only records the significant portions, and does not record the quiet parts; so the recording position doesn’t update if the input level is too low. here’s a first shot:

– Pasted Max Patch, click to expand. –
#232924
Oct 4, 2012 at 4:14am

Without clicks:

– Pasted Max Patch, click to expand. –
#232925
Oct 4, 2012 at 8:38am

graham, that is a beautifully simple and fantastic patch. thanks. now to try modify it for smooth starts/stops of recording, and perhaps writing the ‘rejected’ below-threshold parts of the recording to a different buffer…

by the way, is gen~accepting-message-rate-inputs new to 6.0.7? i am sure this did not work before (had to be param or signal inputs).

#232926
Oct 4, 2012 at 10:33am

Ah well done Andrzej, I thought there might be a way of getting rid of all the zeros!

Graham, Thanks for looking into % – I was checking it with number~ and capture~ and just seeing ints so I was getting a little bit confused. Like the patch – here is a version built in plain MSP partly because I wanted to hear the difference between Gen and Msp and also compare the cpu load.

This version records high and low amps separately and plays them back together. Quite a lot of fun!

– Pasted Max Patch, click to expand. –
#232927
Oct 5, 2012 at 4:13am

Yes, number (float and int) inputs to gen~ are one of the new features in 6.0.7. No need to use [sig~] anymore.

The recording should be smooth (ish) already, I hope… at least in the second one I posted. The rejected audio could be grabbed just by scaling the input by the output of the [clip] -> [!- 1], and using that to drive another writer I guess. That one will have clicks though…

#232928

You must be logged in to reply to this topic.