Rounding up numbers to a specific set of values

mistermanugo's icon

I'm faced with the following problem:

I would like to round up random values going from 0 to 255 to the fixed values of the frequencies of the C major Scale.

I want the random value to be converted to the nearest frequency value in the C major Scale.

For example, if I have the value 422 I would like it to be converted the an A1 which is has the value of 440 (in hertz).

I hope you will be able to help me,

Thank you very much !

11OLSEN's icon

maybe scale that to 12 steps [scale 0 255 0 11] and then it's easy to call notes with it. strange that you're then talking about a value higher than 255?

mistermanugo's icon

420 is higher then 255: True. Haha. I was thinking about multiple ways to do it so my example wasn't fitting was I had said above.
Thank you very much for figuring that out for me!
It was pretty simple I don't know why I didn't think of it...
I'm a bit tired today

Have a nice day :)

11OLSEN's icon

because you were talking about major you would have to scale it to 7 steps of course, but you know that..
have a nice day, too
O.

Chris Muir's icon
Max Patch
Copy patch and select New From Clipboard in Max.

ftom is your friend here. 422 is not going to round to A 440 though, as it's closer to the G# below.