COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 09-28-2016, 07:02 AM   #1
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default Init function with GetSampleRate()

Where VST functions like GetSampleRate(), GetSamplesPerBeat() are available for all hosts?

I see this function is not available on Reset() or OnParamChange() to all hosts. Cubase for example return real value of this function only in ProcessDoubleReplacing(). To solve this problem I build a Init() function like this:

Code:
//in IPLUG_CTOR

sbeat=0.;


void Init() {
///// here can safe access GetSampleRate() or GetSamplesPerBeat
	srate = GetSampleRate();
	sbeat = 4*GetSamplesPerBeat();
}
Reset() {
	TRACE;
	IMutexLock lock(this);

	if (sbeat<1.) {
		this->Init();
	}
}
OnParamChange() {
	TRACE;
	IMutexLock lock(this);

	if (sbeat<1.) {
		this->Init();
	}
}
ProcessDoubleReplacing() {
	TRACE;
	IMutexLock lock(this);

	if (sbeat<1.) {
		this->Init();
	}
}
There is no other solution ? What do you use to get safe values of this functions for all hosts?
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 09-28-2016, 11:19 AM   #2
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

AFAIK Reset() should be called by ALL hosts at least if the sample rate changes. So this would definitely be the right place for GetSampleRate().

GetSamplesPerBeat(), or GetTempo() should be placed in ProcessDoubleReplacing() if you want somewhat reliable data because it depends on the host tempo which could have changed meanwhile if you read it elsewhere.
stw is offline   Reply With Quote
Old 09-29-2016, 02:51 AM   #3
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Quote:
Originally Posted by stw View Post
AFAIK Reset() should be called by ALL hosts at least if the sample rate changes. So this would definitely be the right place for GetSampleRate().

What host can change the sample rate on the timeline ? GetSampleRate() is enough to get it only one time on the init/loading.
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Old 09-29-2016, 03:31 AM   #4
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by SaschArt View Post
What host can change the sample rate on the timeline ? GetSampleRate() is enough to get it only one time on the init/loading.
But you can change sample rate on your soundcard while the host is open, this is then also reflected in the host, so I don't think it's enough to only get it at one time at init / loading.
nofish is offline   Reply With Quote
Old 09-29-2016, 03:41 AM   #5
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

Yes the sample rate is determined by your soundcard (nevertheless e.g. Reaper can request a 88.2k samplerate if available).
So the samplerate can change after your plug is loaded. In this case Reset() is called. So if you want to make your plug aware of samplerate changes you have to place GetSampleRate() there!
stw is offline   Reply With Quote
Old 09-29-2016, 03:43 AM   #6
SaschArt
Human being with feelings
 
SaschArt's Avatar
 
Join Date: Aug 2013
Posts: 236
Default

Quote:
Originally Posted by nofish View Post
But you can change sample rate on your soundcard while the host is open, this is then also reflected in the host, so I don't think it's enough to only get it at one time at init / loading.
If sample rate changed by soundcard, Reset() is called? In this case maybe required to be in ProcessDoubleReplacing()

I read now your message stw, thanks
__________________
Audio plugins | BrainWaveProducer | EmRysRa
SaschArt is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.