summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorGravatarGravatar R. Belmont <rb6502@users.noreply.github.com>2019-09-25 17:01:44 -0400
committerGravatarGravatar GitHub <noreply@github.com>2019-09-25 17:01:44 -0400
commit133cbc344e2c03742d194fb7d5a6e00e1b1e4b19 (patch)
tree27b2d7f1615695a504f1d633c0316574f40bef6f /src
parent21ad25e4c4d35fd629e75f8bce01685ce27d0d41 (diff)
parent66234b509ce98b26ae776f99ae1f4910282f1557 (diff)
Merge pull request #5683 from vadosnaprimer/sound_callback
Lua callback after sound update has generated new samples
Diffstat (limited to 'src')
-rw-r--r--src/emu/main.h1
-rw-r--r--src/emu/sound.cpp3
-rw-r--r--src/frontend/mame/luaengine.cpp22
-rw-r--r--src/frontend/mame/luaengine.h1
-rw-r--r--src/frontend/mame/mame.cpp5
5 files changed, 29 insertions, 3 deletions
diff --git a/src/emu/main.h b/src/emu/main.h
index e5b0c845942..a62457a1c75 100644
--- a/src/emu/main.h
+++ b/src/emu/main.h
@@ -60,6 +60,7 @@ public:
static void draw_user_interface(running_machine& machine);
static void periodic_check();
static bool frame_hook();
+ static void sound_hook();
static void layout_file_cb(util::xml::data_node const &layout);
static bool standalone();
};
diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp
index 3ad10c6208d..805a6920fed 100644
--- a/src/emu/sound.cpp
+++ b/src/emu/sound.cpp
@@ -1152,6 +1152,9 @@ void sound_manager::update(void *ptr, int param)
for (auto &stream : m_stream_list)
stream->apply_sample_rate_changes();
+ // notify that new samples have been generated
+ emulator_info::sound_hook();
+
g_profiler.stop();
}
diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp
index 7b45fd92c59..4c5f9d0f42d 100644
--- a/src/frontend/mame/luaengine.cpp
+++ b/src/frontend/mame/luaengine.cpp
@@ -709,6 +709,11 @@ void lua_engine::on_frame_done()
execute_function("LUA_ON_FRAME_DONE");
}
+void lua_engine::on_sound_update()
+{
+ execute_function("LUA_ON_SOUND_UPDATE");
+}
+
void lua_engine::on_periodic()
{
execute_function("LUA_ON_PERIODIC");
@@ -778,6 +783,7 @@ void lua_engine::initialize()
* emu.register_resume(callback) - register callback at resume
* emu.register_frame(callback) - register callback at end of frame
* emu.register_frame_done(callback) - register callback after frame is drawn to screen (for overlays)
+ * emu.register_sound_update(callback) - register callback after sound update has generated new samples
* emu.register_periodic(callback) - register periodic callback while program is running
* emu.register_callback(callback, name) - register callback to be used by MAME via lua_engine::call_plugin()
* emu.register_menu(event_callback, populate_callback, name) - register callbacks for plugin menu
@@ -821,6 +827,7 @@ void lua_engine::initialize()
emu["register_resume"] = [this](sol::function func){ register_function(func, "LUA_ON_RESUME"); };
emu["register_frame"] = [this](sol::function func){ register_function(func, "LUA_ON_FRAME"); };
emu["register_frame_done"] = [this](sol::function func){ register_function(func, "LUA_ON_FRAME_DONE"); };
+ emu["register_sound_update"] = [this](sol::function func){ register_function(func, "LUA_ON_SOUND_UPDATE"); };
emu["register_periodic"] = [this](sol::function func){ register_function(func, "LUA_ON_PERIODIC"); };
emu["register_mandatory_file_manager_override"] = [this](sol::function func) { register_function(func, "LUA_ON_MANDATORY_FILE_MANAGER_OVERRIDE"); };
emu["register_before_load_settings"] = [this](sol::function func) { register_function(func, "LUA_ON_BEFORE_LOAD_SETTINGS"); };
@@ -1224,7 +1231,6 @@ void lua_engine::initialize()
* machine:popmessage(str) - print str as popup
* machine:popmessage() - clear displayed popup message
* machine:logerror(str) - print str to log
- *
* machine:system() - get game_driver for running driver
* machine:video() - get video_manager
* machine:sound() - get sound_manager
@@ -1410,7 +1416,6 @@ void lua_engine::initialize()
*
* debugger.consolelog[] - get consolelog text buffer (wrap_textbuf)
* debugger.errorlog[] - get errorlog text buffer (wrap_textbuf)
- *
* debugger.visible_cpu - accessor for debugger active cpu for commands, affects debug views
* debugger.execution_state - accessor for active cpu run state
*/
@@ -1722,6 +1727,7 @@ void lua_engine::initialize()
return port_table;
}));
+
/* natural_keyboard library
*
* manager:machine():ioport():natkeyboard()
@@ -1992,6 +1998,7 @@ void lua_engine::initialize()
"throttled", sol::property(&video_manager::throttled, &video_manager::set_throttled),
"throttle_rate", sol::property(&video_manager::throttle_rate, &video_manager::set_throttle_rate));
+
/* sound_manager library
*
* manager:machine():sound()
@@ -2000,7 +2007,7 @@ void lua_engine::initialize()
* sound:stop_recording() - end audio recording
* sound:ui_mute(turn_off) - turns on/off UI sound
* sound:system_mute() - turns on/off system sound
- * sound:samples() - get current frame's audio buffer contents in binary form as string
+ * sound:samples() - get current audio buffer contents in binary form as string (updates 50 times per second)
*
* sound.attenuation - sound attenuation
*/
@@ -2084,6 +2091,7 @@ void lua_engine::initialize()
return result;
}));
+
/* input_class library
*
* manager:machine():input().device_classes[devclass]
@@ -2093,6 +2101,7 @@ void lua_engine::initialize()
* devclass.multi
* devclass.devices[]
*/
+
sol().registry().new_usertype<input_class>("input_class", "new", sol::no_constructor,
"name", sol::property(&input_class::name),
"enabled", sol::property(&input_class::enabled, &input_class::enable),
@@ -2110,6 +2119,7 @@ void lua_engine::initialize()
return result;
}));
+
/* input_device library
*
* manager:machine():input().device_classes[devclass].devices[index]
@@ -2135,6 +2145,7 @@ void lua_engine::initialize()
return result;
}));
+
/* input_device_item library
*
* manager:machine():input().device_classes[devclass].devices[index].items[item_id]
@@ -2142,6 +2153,7 @@ void lua_engine::initialize()
* item.token
* item:code()
*/
+
sol().registry().new_usertype<input_device_item>("input_device_item", "new", sol::no_constructor,
"name", sol::property(&input_device_item::name),
"token", sol::property(&input_device_item::token),
@@ -2151,6 +2163,7 @@ void lua_engine::initialize()
return sol::make_user(code);
});
+
/* ui_input_manager library
*
* manager:machine():uiinput()
@@ -2514,6 +2527,7 @@ void lua_engine::initialize()
return table;
}));
+
/* memory_region library
*
* manager:machine():memory().regions[region_tag]
@@ -2524,6 +2538,7 @@ void lua_engine::initialize()
*
* region.size
*/
+
sol().registry().new_usertype<memory_region>("region", "new", sol::no_constructor,
"read_i8", &region_read<int8_t>,
"read_u8", &region_read<uint8_t>,
@@ -2543,6 +2558,7 @@ void lua_engine::initialize()
"write_u64", &region_write<uint64_t>,
"size", sol::property(&memory_region::bytes));
+
/* memory_share library
*
* manager:machine():memory().shares[share_tag]
diff --git a/src/frontend/mame/luaengine.h b/src/frontend/mame/luaengine.h
index 4315fe37aa4..820f5a0baf3 100644
--- a/src/frontend/mame/luaengine.h
+++ b/src/frontend/mame/luaengine.h
@@ -49,6 +49,7 @@ public:
std::vector<std::string> &get_menu() { return m_menu; }
void attach_notifiers();
void on_frame_done();
+ void on_sound_update();
void on_periodic();
bool on_missing_mandatory_image(const std::string &instance_name);
void on_machine_before_load_settings();
diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp
index e5a59cd6039..e0d45e504c1 100644
--- a/src/frontend/mame/mame.cpp
+++ b/src/frontend/mame/mame.cpp
@@ -413,6 +413,11 @@ bool emulator_info::frame_hook()
return mame_machine_manager::instance()->lua()->frame_hook();
}
+void emulator_info::sound_hook()
+{
+ return mame_machine_manager::instance()->lua()->on_sound_update();
+}
+
void emulator_info::layout_file_cb(util::xml::data_node const &layout)
{
util::xml::data_node const *const mamelayout = layout.get_child("mamelayout");