Forums > Dev

sampleframes and samplerate outside of perform64() and dsp64()

June 22, 2013 | 8:18 pm

Hi, I want to access the sampleframes variable outside of the perform64 function and I want to access the samplerate variable outside of the dsp64 function.

Right now, I’m assigning x->sampleframes = sampleframes inside of perform64(), and x->samplerate inside dsp64(). Access to these assignments is only possible after audio is enabled, which isn’t ideal for my object.

thoughts?
thanks in advance,
kristin


June 23, 2013 | 12:33 am

Hi there,

you are only gonna get reliable samplerate and sampleframes (or block size) information after the audio has been enabled, since different objects in different sub-patchers might operate at different rates (i.e. poly~). However if you want to access those fields before turning audio on and still get values that make somewhat sense here is the way to do it:

in your new method add the following:
x->samplerate = sys_getsr();
x->sampleframes = sys_getblksize();

Both functions are defined in z_dsp.h that will need to be included of course.
Hope this is what you were after…

- Luigi


June 23, 2013 | 9:57 am

that’s it.
z_dsp.h has lots of methods!
cool,
kristin


June 23, 2013 | 10:26 am

One more related question:

My understanding of the perform64 function is that it loops at a rate of samplerate/sampleframes.
What if I want to generate audio output for every sample, and not every frame of samples?
I can’t imagine all of the msp~ objects being calculated at 1/64th the samplerate, so I must have a misunderstanding.
Mostly, I’m looking for reasons why the oscillator I built is noisy.

thanks in advance,
kristin


June 24, 2013 | 5:51 am

I believe your understanding is correct, but let me rephrase it:
the perform64 method gets called at a rate of samplerate/sampleframes.
Inside the perform64 method you loop through each sample for that frame.
Audio output is generated for every sample and it could not be otherwise.
However, for efficiency reasons the audio system works with buffers of a certain (power of 2) length (64,128,256,512,etc…). So what the perform64 method hands to you are groups of samples.
You could tell MSP to work with buffers of 1 sample, but – as you’ll notice – it will be very inefficient.

Hope this helps clarifying things a bit.

- Luigi


June 24, 2013 | 11:15 am

Oh yeah, I update the variables inside the while(n–) loop and yes! 44,100 sounds way better than ~686 sample rate. now it makes sense.
thanks for your help!
kristin


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