Changing FCEUX's sound with Lua scripts?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
BioMechanical Dude
Formerly AlienX
Posts: 137
Joined: Fri Apr 18, 2014 7:41 am
Location: Bulgaria

Changing FCEUX's sound with Lua scripts?

Post by BioMechanical Dude »

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.
Greetings! I'm That Bio Mechanical Dude and I like creating various stuff like movies, games and of course chiptunes!
You can check out my YouTube Channel.
You can also follow me on Twitter.
User avatar
rainwarrior
Posts: 8763
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Changing FCEUX's sound with Lua scripts?

Post by rainwarrior »

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.
User avatar
Dwedit
Posts: 5126
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Changing FCEUX's sound with Lua scripts?

Post by Dwedit »

Might be possible to inject timed writes into the RAW PCM channel, but that would be slow.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
feos
Posts: 108
Joined: Tue Apr 19, 2011 11:26 am
Location: RU

Re: Changing FCEUX's sound with Lua scripts?

Post by feos »

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
User avatar
Dwedit
Posts: 5126
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Changing FCEUX's sound with Lua scripts?

Post by Dwedit »

Lua also has "loadlib" for loading arbitrary DLL files.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
BioMechanical Dude
Formerly AlienX
Posts: 137
Joined: Fri Apr 18, 2014 7:41 am
Location: Bulgaria

Re: Changing FCEUX's sound with Lua scripts?

Post by BioMechanical Dude »

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.
Greetings! I'm That Bio Mechanical Dude and I like creating various stuff like movies, games and of course chiptunes!
You can check out my YouTube Channel.
You can also follow me on Twitter.
Post Reply