Forums > MaxMSP

Reading from buffer~ and DSP question about sample rate/vector size

Jun 13 2013 | 6:45 am

Greetings! (my first post in here,…)

Some confusion with how the buffer~ object works as well as the relationship between sample rate, vector size etc:

If I write in exactly 512 values into a stereo.aiff file and want to read it back via wave~ plus phasor~ , how can I calculate the length in milliseconds (or samples) of this buffer? For example if phasor~ is going at 1Hz this should mean the buffer of 512 plays through once in a second? But in fact when I do this I only hear the sound at the beginning of the second as a click. The wave~ object allows one to set the start and end point of what should be read – at the moment I have that set as reading from 0. to 12. simply because the visual wave looks correct but I wish I knew how to calculate this. Does the vector size, sampling rate or other factors have anything to do with it? Are these 512 values actually one sample each?

Also is there a way that I can convert the signal back to numbers and ‘draw’ the signal (similar to building my own oscilloscope without using scope~). [In the long run I’d like to research a microscopic relationship between sound and visual].

Thanks for clarifying any part of the question!

— Pasted Max Patch, click to expand. —
Jun 13 2013 | 7:22 am

– thats the main difference between wave~ and cycle~, cycle~ has a fixed size.
– your assumptions about frequency and cycle~ are correct.
– the vectorsize can be ignored in this context.
– the sampling rate (of maxmsp) will always be the one which objects have, too.

– the only thing you must take care of in this realm is when you want to do calculations, and you are expressing a time value IN samples. for example, when you are writing "22.050" somewhere to express "0.5 second" or "2 hertz". this patch will later work wrong when the maxmsp runtime is set to another rate. the solution is to use [dspstate~]–[* 0.5] instead of a fixed value.


Jun 13 2013 | 7:42 am

For plotting, see plot~ (especially the buffer~ tab in the help file).
To get the buffer~’s sample rate, see info~.
To convert between samples and milliseconds, see sampstoms~ and mstosamps~.

The phasor~ outputs a signal that goes repeatedly (i.e., cyclically) from 0 to 1, or more exactly from 0 to almost 1, because when it would arrive at 1 it loops back to 0. It completes that cycle f times per second, where f is the phasor~’s frequency in Hz. You can use it to control wave~ to cycle through a portion of the buffer~ f times per second, thus turning that portion of the buffer~ into a wavetable for synthesis.

Jun 13 2013 | 10:38 am

Thank you, both Chris and Roman, you are totally great! This helps a lot.

To be clear, if I load an audio buffer~ with 512 values does that mean the length of the buffer is 512 samples so now I can calculate the corresponding milliseconds needed. 512 samples at a sample rate of 44k is thus

512*(1/44000) = 512* (0.0227227273) ms = 11.6363 ms

sampstoms~ tells me one sample is 0.022676 which is slightly different to my own answer. Also interestingly sampstoms~ tells me 44000 samples = 997.732422 ms thus slightly less than 1 sec!

and @Chris! I will have to wait for next month to purchase my upgrade to max 6 and use plot~

Jun 13 2013 | 12:04 pm

if you load a file into a buffer object it will remain the size you set it to.
you can use sfinfo~ to see how long a file ist, then change the buffer size with message, then import the file. or just make it bigger and dont care about the free space.

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > MaxMSP