Changing FCEUX's sound with Lua scripts?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Changing FCEUX's sound with Lua scripts?
by on (#149591)
This should've been a part of the "About FCEUX's sound" thread, I made a year ago, but it's long dead, so I made another one, specifically for this question.
Is it possible to play different waveforms in FCEUX using Lua scripts? FCEUX basically uses specific algorithms to generate the different waveforms, the NES produces (particularly the ones, that the core 2A03 chip uses). So is it possible to recreate these algorithms with Lua scripts and then alter them a bit to create different sounds? For instance, at one point Channel 1 is playing a 25% Square wave. The code in the Lua script is sort of a counterpart of FCEUX's own sound script, so the script reads the data in the addresses for Channel 1 and it plays that channel, but instead of a pulse wave, it's playing a saw wave.
Sure, the sound may play separately from FCEUX's own audio, but that doesn't matter. If this is possible, without modifying FCEUX's code code, some interesting stuff can be created with that. Useless, but still interesting. And if Lua scripts allow for playing sound files, a sample based NES Audio system could be created.
This all seems a bit far-fetched, but it might be possible. Is it? I'd like to know.
Thanks.
Re: Changing FCEUX's sound with Lua scripts?
by on (#149592)
Correct me if I'm wrong, but I don't think the LUA embedded in FCEUX has any direct access to sound output.

Why exactly do you want to do it in LUA, anyway? It would be a lot easier just to modify FCEUX, I think.
Re: Changing FCEUX's sound with Lua scripts?
by on (#149597)
Might be possible to inject timed writes into the RAW PCM channel, but that would be slow.
Re: Changing FCEUX's sound with Lua scripts?
by on (#149631)
Lua has read-only access to fceux sound. So if you really need, you may plug something to lua itself and use it to output your sound separately. You can't edit how it's generated in the core, and you're unlikely to ever be able to.

http://www.fceux.com/web/help/LuaFunctionsList.html
Re: Changing FCEUX's sound with Lua scripts?
by on (#149647)
Lua also has "loadlib" for loading arbitrary DLL files.
Re: Changing FCEUX's sound with Lua scripts?
by on (#149649)
Well, as I said, the sound from the Lua script could play separately, meaning it won't modify FCEUX itself. I just want to know if it's possible to produce sounds with Lua Script. External program... that might work.
Why Lua? Because, if I wanted to just modify FCEUX, I'd have to spend a month or two, learning C++, then finding FCEUX's source code, picking out the sound-generating algorithm and finally modify it. I think it's much faster to use a scripting language, that probably doesn't take that long to get the hang of.