Old 10-03-2020, 01:00 PM   #1
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default Get buffer size?

Is there any way to get what the current buffer sizes? Thanks as always
Coachz is offline   Reply With Quote
Old 10-03-2020, 01:11 PM   #2
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 5,844
Default

If you're referring to the sample buffer size of the audio device, try the GetAudioDeviceInfo function: https://www.extremraym.com/cloud/rea...udioDeviceInfo
Quote:
GetAudioDeviceInfo

Get information about the currently open audio device. attribute can be MODE, IDENT_IN, IDENT_OUT, BSIZE, SRATE, BPS. returns false if unknown attribute or device not open.
lua example:
Code:
retval, desc = reaper.GetAudioDeviceInfo("BSIZE", "")
if retval then
  reaper.ShowConsoleMsg(desc)
end
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 10-04-2020, 05:34 AM   #3
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

Awesome, that made it so easy for me to enable master fx based on my buffer. Thanks solger !

Code:
retval, desc = reaper.GetAudioDeviceInfo("BSIZE", "")

if(tonumber(desc) < 257) then
	-- disable master fx
	reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_DISMASTERFX"), 0)

else 
	-- enable master fx
	reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_ENMASTERFX"), 1)
end
Coachz is offline   Reply With Quote
Old 10-05-2020, 11:30 AM   #4
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

How come I'm getting nil:

JB_mastering_mode_fx_toggle.lua:45: attempt to compare nil with number
from "desc" when I run this in a project startup script ?

retval, desc = reaper.GetAudioDeviceInfo("BSIZE", "")


Code:
retval, desc = reaper.GetAudioDeviceInfo("BSIZE", "")
if retval then
	if debug then Msg("buffer returned: " .. desc) end
end




if(tonumber(desc) < 257) then
	-- disable master fx
	reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_DISMASTERFX"), 0)
	if debug then Msg("disabled master fx") end

else 
	-- enable master fx
	reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_ENMASTERFX"), 1)
	if debug then Msg("enabled master fx") end
end
Coachz is offline   Reply With Quote
Old 10-05-2020, 12:08 PM   #5
Yanick
Human being with feelings
 
Yanick's Avatar
 
Join Date: May 2018
Location: Moscow, Russia
Posts: 612
Default

And how to set a new buffer size? The reaper.SNM_SetIntConfigVar('asio_bsize', newvalue ) function doesn't seem to work
Yanick is offline   Reply With Quote
Old 10-05-2020, 01:58 PM   #6
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

Quote:
Originally Posted by Yanick View Post
And how to set a new buffer size? The reaper.SNM_SetIntConfigVar('asio_bsize', newvalue ) function doesn't seem to work
I think that depends on your sound card and whether or not it can accept the commands are not. I've got an rme 9652 and I'll have to give it a try to see if it likes the command or not. What sound cards are you using Yanick.
Coachz is offline   Reply With Quote
Old 10-05-2020, 02:04 PM   #7
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

And the code I posted up top work once Reaper is started but running it during startup gives me nil as I guess the sound card has not been initialized yet. I wonder if there's a way to wait for it to be initialized before running the command
Coachz is offline   Reply With Quote
Old 10-05-2020, 02:45 PM   #8
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Coachz View Post
And the code I posted up top work once Reaper is started but running it during startup gives me nil as I guess the sound card has not been initialized yet. I wonder if there's a way to wait for it to be initialized before running the command
You can put it into a defer-loop and keep that loop running until you get a valid value.

And keep in mind, that on Windows at least, the returned value can be nil, when the Prefs->Devices page is opened.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...

Last edited by Meo-Ada Mespotine; 10-05-2020 at 02:50 PM.
Meo-Ada Mespotine is offline   Reply With Quote
Old 10-05-2020, 02:48 PM   #9
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Yanick View Post
And how to set a new buffer size? The reaper.SNM_SetIntConfigVar('asio_bsize', newvalue ) function doesn't seem to work
You can't. Maybe with ugly hacks involving opening prefs, virtually clicking stuff including inserting the new buffersize and hitting ok. But this is ugly and messes with potential userinteraction.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 10-05-2020, 03:02 PM   #10
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
You can put it into a defer-loop and keep that loop running until you get a valid value.

And keep in mind, that on Windows at least, the returned value can be nil, when the Prefs->Devices page is opened.
Thanks for the reply, by defer loop do you mean something like....

repeat
statement(s)
until( condition )
Coachz is offline   Reply With Quote
Old 10-05-2020, 04:14 PM   #11
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by Coachz View Post
Thanks for the reply, by defer loop do you mean something like....

repeat
statement(s)
until( condition )
No, rather this one:

https://forum.cockos.com/showpost.ph...2&postcount=21

Other loops block Reapers Gui. Defer-loops keep Reaper's gui active.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 10-06-2020, 12:58 AM   #12
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

Thanks, that got me going and the script doesn't seem to keep running as I don't see it in the Actions menu where continuously running scripts show up. Instead of using a timer is there a way to run the script until success and then have it end ?

Code:
local desc = nil

time_start = reaper.time_precise()

local function Main()

    local elapsed = reaper.time_precise() - time_start

    if elapsed >= 1 then
        retval, desc = reaper.GetAudioDeviceInfo("BSIZE", "")
		if retval then
			if debug then Msg("buffer returned: " .. desc) end
		end


		if(tonumber(desc) < 257) then
			-- disable master fx
			reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_DISMASTERFX"), 0)
			if debug then Msg("disabled master fx") end

		else 
			-- enable master fx
			reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_ENMASTERFX"), 1)
			if debug then Msg("enabled master fx") end
		end

        return
    else
        reaper.defer(Main)
    end
    
end

Main()

Last edited by Coachz; 10-06-2020 at 01:06 AM.
Coachz is offline   Reply With Quote
Old 10-06-2020, 06:20 AM   #13
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Code:
if desc==nil
  reaper.defer(Main) 
else
  -- do your stuff here with desc
end
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 10-06-2020, 08:31 AM   #14
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

Thanks so much!
Coachz is offline   Reply With Quote
Old 10-06-2020, 09:48 AM   #15
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,769
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Code:
if desc==nil
  reaper.defer(Main) 
else
  -- do your stuff here with desc
end
What is Main in your example ?
Coachz is offline   Reply With Quote
Old 10-06-2020, 02:02 PM   #16
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Your own main function. Couldn't rewrite it accordingly as I'm afk right now and writing code on my phone is too difficult to do.

I advice you to read the post I mentioned again. The last example under PS helps you guiding through this.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine 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 05:27 AM.


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