Page 1 of 1

Sample Rate for CV modules

Posted: Thu Jan 26, 2023 6:31 am
by Centripidity
Very new to this so I'm interested in the opinions of those with experience.

If you are producing a module designed to generate a control voltage (EV or LFO) what sort of sampling rate would you use for that CV? Basically, I'm asking if you would generate the CV in ProcessSample() or use a timer to generate each new CV sample, in the hope that it would reduce the overall CPU load of the module.

If you'd use a timer, what sort of interval would you recommend?

Thanks.

Re: Sample Rate for CV modules

Posted: Thu Jan 26, 2023 8:59 am
by UrbanCyborg
You'd do it in ProcessSample(), because you need to update the value for each sample.

Reid

Re: Sample Rate for CV modules

Posted: Thu Jan 26, 2023 9:34 am
by Centripidity
UrbanCyborg wrote: Thu Jan 26, 2023 8:59 am You'd do it in ProcessSample(), because you need to update the value for each sample.
I assumed that would be the way do it. It just seemed overkill for, as a hypothetical example, a 0.1Hz LFO to be sampled at 48kHz.

Re: Sample Rate for CV modules

Posted: Fri Jan 27, 2023 12:41 am
by UrbanCyborg
Even if you're outputting a constant value, you have to supply it on each sample tick. In fact, recently there was a thread in which it was noted that turning an output off still means having to output a zero, for the benefit of any module that might be connected.

Reid

Re: Sample Rate for CV modules

Posted: Fri Jan 27, 2023 5:05 am
by Centripidity
UrbanCyborg wrote: Fri Jan 27, 2023 12:41 am Even if you're outputting a constant value, you have to supply it on each sample tick. In fact, recently there was a thread in which it was noted that turning an output off still means having to output a zero, for the benefit of any module that might be connected.

Reid
Ok, so even if, for some reason, I choose not to calculate a new CV value for every sample I still need to output something in every call to the ProcessSample function.

That's good to know.

Thanks.

Re: Sample Rate for CV modules

Posted: Fri Jan 27, 2023 8:48 am
by UrbanCyborg
Glad to help.

Reid

Re: Sample Rate for CV modules

Posted: Tue Jan 31, 2023 4:42 pm
by ChR_is
sample theory says you can perfectly replicate any frequency below half your sample rate. unfortunately that does also include all frequency content of your signal.
that means if you have a perfect sine wave at 5hz you can basically turn down the sample rate to 10hz and still have a perfect sine wave. that does not work if you have a saw wave at 5hz since the harmonics will stretch far beyond 5hz.
however, since you're talking about lfos and envelopes which do not care about aliasing all that much you can get away with imperfect waveforms just fine. i wouldn't go as far as 10hz samplerate, but anything above 2.4khz should suffice.
the way to do that is to just calculate and store the output of your signal generator for every N-th sample with N being the divisor for your sample rate. so e.g. if you wanted to have a 4.8khz sample rate you'd need to sample every 10th sample and just keep outputting this value for 10 sample straight.

e.g.

Code: Select all

private void processsample()
{
	if( ++m_cntr >= 10 )
	{
		m_cntr = 0;
		m_lfoValue = calculate_lfo_value();
	}

	output.SetValue( m_lfoValue );
}

private dobule 		m_lfoValue;
private int 		m_cntr;
NOTE: make sure your samplerate-dependend processors adapt to the new sample rate. e.g. the phase increment of your oscillator or the coefficient calculation of your filter etc. etc.

Bonus points: if you're worried about steppy signals just throw in an extra one pole lowpass filter set to the maximum expected frequency before the ouptut and you're good to go. ;)


EDIT: DON'T use a timer! the timers run on a different thread and are not precise. you'll get all sorts of jitter and artifact problems. plus you'd have to worry about synchronizing those threads then. it's definitely not worth the effort and hassle.