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

Jun 22, 2013 at 8:18pm

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

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

#253765
Jun 23, 2013 at 12:33am

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

#253769
Jun 23, 2013 at 9:57am

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

#253793
Jun 23, 2013 at 10:26am

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

#253796
Jun 24, 2013 at 5:51am

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

#253832
Jun 24, 2013 at 11:15am

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

#253893

You must be logged in to reply to this topic.