Sync buffer recording to zero cross

Dec 5, 2011 at 5:11am

Sync buffer recording to zero cross

I’m trying to record real-time audio into a buffer starting at a zero cross. I’m using a zerox~ and edge~ to trigger the record~ but the buffer contents never sync up. I’m must be doing something silly.

Any help is much appreciated!

-Charley

– Pasted Max Patch, click to expand. –
#60468
Dec 5, 2011 at 9:51pm

The problem you are having is because you are using edge~ which converts your click from zerox~ to a bang causing you to leave the signal domain making you lose sample-rate accuracy.

Depending on how you will use this, it might be easier just to recording into a buffer, then use peek~ to search for the first zero crossing, then that sample location as your start point for playback.

I know it isn’t exactly the same as what you are looking for, but check out this thread: http://cycling74.com/forums/topic.php?id=36023

If you look in the help file for the mxj I posted to that thread, you will see a subpatcher that shows the algorithm for that mxj implemented in Max.

More to the point of your question, here is an example of how to trigger recording from a zerocrossing with sample accuracy. It might look a little strange, but works.

– Pasted Max Patch, click to expand. –
#217641
Dec 6, 2011 at 5:26am

Thanks very much Roth! I see now. I need to stay in the signal domain.

I’m going to try to write a gen~ path to encapsulate zero cross detection and writing to the buffer all in one. I’ll report back when I make some progress.

#217642
Dec 6, 2011 at 3:43pm

Yeah, I’d go for doing that in gen~ probably myself—just figured MSP would provide a more general example. Off the top of my head, it seems like you might be able to make it more elegant with gen~ getting rid of the need for sah~ and some of the other conditional logic because you can do real ifs with signals in gen~.

#217643
Dec 6, 2011 at 5:35pm

I was just wondering about if statements in genExpr. I couldn’t find a reference to it in the Max docs. Would you show me an example of syntax?

Is there a repository of genExpr example code somewhere? I think I get the main syntax but I’m still not 100%.

#217644
Dec 6, 2011 at 6:01pm

Turns out I may have said something misleading—real response to come later when I’m done working.

#217645
Dec 6, 2011 at 11:50pm

Sorry to get your hopes up, but it looks like support for if-statements might not be ready yet. I was talking about branching/control-flow stuff with some of the devs at the expo and got the impression that it was already implemented in GenExpr. From trying it out myself, it seems like if-statements (and perhaps other parts of codebox) are a work in progress. Normally, bad GenExpr syntax gives a parsing error in the Max window. The following GenExpr code in a codebox generates no errors, but does not function correctly.

if (in > 0) {
    out = 1;
}
else {
    out = 0;
}

I think the GenExpr documentation is still in progress. You should check out this thread: http://cycling74.com/forums/topic.php?id=35693 and stuff in the Max6/examples folder. Those places and just messing around is where I’ve picked up my gen~ knowledge (plus some presentations from the Expo whose files are in the Toolbox on this site I think).

#217646

You must be logged in to reply to this topic.