Hey, guys! In my "Changing FCEUX's sound with Lua scripts?" thread, I discussed the idea of FCEUX, playing the games' audio, using sound samples, which will allow for a variety of new sounds. After a few days of hard work, I have finished a Lua script, which will do just that. This is...
THE NES SAMPLE-BASED SOUND SYSTEM
This script uses the proteaAudio sound library by Gerald Franz. It reads the NES's sound data, using FCEUX's sound.get() function and recreates it, using files in the .ogg format. As you might have guessed, this can make NES audio sound like something out of a MIDI device, a Sega Genesis, a SNES, a Commodore 64, whatever.
The sample set, I've made, uses edited MIDI instrument samples and some custom ones too. Both Pulse Wave channels have different instruments for each pulse-width. Here's a list of the different instruments:
Square 1
Duty 0 - Tuba
Duties 1 and 3 - Overdriven Guitar
Duty 2 - Flute
Square 2
Duty 0 - Distortion Guitar
Duties 1 and 3 - String Ensemble
Duty 2 - Rock Organ
The Triangle Wave channel uses a custom sample of a square wave, combined with a triangle wave and some effects added in. The Noise channel uses four different samples for the different notes.
You can make your own sample sets too! If you're interested in this project, then I would like to see what ideas you have for different NES sounds. You can post your sample sets on this thread. When making the samples, however, you must follow certain rules:
All samples' frequencies(not including the noise channel ones) must be set to 440Hz(the frequency of an A-4 note). This is because the script takes the channels' frequency and divides it to 440, to get the pitch values for the samples.
All samples must have a "static" sound. This means, that there cannot be any changes in the volume or pitch. Otherwise, they will clash with the NES's own volume and pitch changes and the audio will be pretty crappy. So, no fade-ins, vibratos, etc. You may use filters and cutoff rate changes, but make sure, that the end of the sample sounds like the beginning. The samples are looped and are not replayed with each note, so if, for example, you have a sample, that starts with low cutoff rate and ends with a high one, the sound will probably be jerky, when being played.
FCEUX USAGE: This script generates the sounds on its own, so if you don't want to hear the original NES Audio, disable the Square 1, Square 2, Triangle and Noise channels in FCEUX's sound settings. DO NOT disable the DPCM channel. As of now, the script cannot recreate the DPCM channel, so it won't play it.
Currently, there's support only for the core 2A03 chip, but you can play games, that use additional sound chips and the Audio will still be fine. I will probably add support for the VRC6, the MMC5, the Sunsoft 5B and the FDS(that one, however will require different one for each game).
There are still some flaws, that I hope you can help me iron out. For instance, if you try to stop or restart the script, FCEUX will crash, so the only way to stop the script is to turn off FCEUX itself. Also, the script cannot yet detect whether emulation is paused or not, so when you pause FCEUX, use the menus or try to load a new game, the sound will be sustained.
Check out this script and, please, tell me what you think. I hope you enjoy using it.
*EDIT: Here are some recorded music samples, to showcase what this script can do
THE NES SAMPLE-BASED SOUND SYSTEM
This script uses the proteaAudio sound library by Gerald Franz. It reads the NES's sound data, using FCEUX's sound.get() function and recreates it, using files in the .ogg format. As you might have guessed, this can make NES audio sound like something out of a MIDI device, a Sega Genesis, a SNES, a Commodore 64, whatever.
The sample set, I've made, uses edited MIDI instrument samples and some custom ones too. Both Pulse Wave channels have different instruments for each pulse-width. Here's a list of the different instruments:
Square 1
Duty 0 - Tuba
Duties 1 and 3 - Overdriven Guitar
Duty 2 - Flute
Square 2
Duty 0 - Distortion Guitar
Duties 1 and 3 - String Ensemble
Duty 2 - Rock Organ
The Triangle Wave channel uses a custom sample of a square wave, combined with a triangle wave and some effects added in. The Noise channel uses four different samples for the different notes.
You can make your own sample sets too! If you're interested in this project, then I would like to see what ideas you have for different NES sounds. You can post your sample sets on this thread. When making the samples, however, you must follow certain rules:
All samples' frequencies(not including the noise channel ones) must be set to 440Hz(the frequency of an A-4 note). This is because the script takes the channels' frequency and divides it to 440, to get the pitch values for the samples.
All samples must have a "static" sound. This means, that there cannot be any changes in the volume or pitch. Otherwise, they will clash with the NES's own volume and pitch changes and the audio will be pretty crappy. So, no fade-ins, vibratos, etc. You may use filters and cutoff rate changes, but make sure, that the end of the sample sounds like the beginning. The samples are looped and are not replayed with each note, so if, for example, you have a sample, that starts with low cutoff rate and ends with a high one, the sound will probably be jerky, when being played.
FCEUX USAGE: This script generates the sounds on its own, so if you don't want to hear the original NES Audio, disable the Square 1, Square 2, Triangle and Noise channels in FCEUX's sound settings. DO NOT disable the DPCM channel. As of now, the script cannot recreate the DPCM channel, so it won't play it.
Currently, there's support only for the core 2A03 chip, but you can play games, that use additional sound chips and the Audio will still be fine. I will probably add support for the VRC6, the MMC5, the Sunsoft 5B and the FDS(that one, however will require different one for each game).
There are still some flaws, that I hope you can help me iron out. For instance, if you try to stop or restart the script, FCEUX will crash, so the only way to stop the script is to turn off FCEUX itself. Also, the script cannot yet detect whether emulation is paused or not, so when you pause FCEUX, use the menus or try to load a new game, the sound will be sustained.
Check out this script and, please, tell me what you think. I hope you enjoy using it.
*EDIT: Here are some recorded music samples, to showcase what this script can do