Math Problems and Max Patchers

The current state of the turns sampler!

This week I built out some additional functionality to my Turns sampler. This was to help coordinate chance in the feel of random style for it. I wanted to change the feel of the chance, by setting a set sample length that would then move around the sample. And building this out I ran into a few little math problems that I thought it would be interesting to discuss in writing Max MSP patchers.

The first one was I needed to decide if I needed to generate two random numbers the start and end point and then adjust them down to the sample length size that I had set. I realise that this was very inefficient and decided not to go down this path.

Next I decided that I needed to pick a sample length and then randomly generate it start point so that the sample would just move around in that space. This ended up being where I went in the end but it was a little hard to conceptualise the problem; what if the sample went over the total end length? I needed to build out a math formula that took the maximum length of the sample and subtracted the length of what I'm allowing to be played in this random sample playback. That number would be where my random number generator would pick a number between zero and eight as the start point of the sample so that I knew it would never go past the end point of the full sample length. This involves me getting out a pen and paper and conceptualising the math of it a little bit while building, which was fun but also a little challenging.

While building this I also realised I had an issue where the previous version wasn't setting the sample end point that was chosen 100% of the time for some reason, (which I only still think I haven't fully got my head across why). I would send the sample start and end point (which you might remember, used to be completely random up until the length maximum of the full sample). Those two numbers would be sent to the sample to create the starting point and end point. The end point wasn't always updating, and I guess I never noticed this because it was random, so I never saw it. I guess I didn't really pick up that that was happening but only when I would then create these two set starting end points, that I noticed that was not happening 100% of the time. This was resolved through setting a pipe object to delay the second number which was the end point down the chain into the waveform~ object.

My notes in sketching out the maths!

I also wanted to keep the original sample random playback style, so I needed to put another gate in there and overall it was a pretty interesting experience too conceptualise a very tricky math problem.

I hope that this has been helpful to you not for this particular circumstance which I'm sure people male may not want to build but just for thinking about problems that crop up as you're building that you might need to resolve this sort of problem-solving is really the joy I get from Max coding and I hope that you do too while you're creating anyway. Here are some other readings on this topic for those that are interested otherwise happy patching!


https://www.matthewdavisprojects.com/thoughts/additions-to-turns-sampler

https://www.matthewdavisprojects.com/thoughts/coordinating-chance?rq=coordin

The patch internals around the math!


Next
Next

Pixel Shot