viti95 / FastDoom

Doom port for DOS, optimized to be as fast as possible!
528 stars 33 forks source link

Feature Port Adlib FX to OPL[2,3]LPT #138

Closed jsmolina closed 1 year ago

jsmolina commented 1 year ago

I was wondering if it was possible to port the adlib fx to LPT version, as this device sounds good and it's an alternative for people without ISA/PCI slots.

Tried settings:

In both cases, no FX at all. I tried past weekend these changes, I checked Reset function from ns_adbfx.c uses same blocks of code, so maybe it's not feasable or not prepared for stereo.

diff --git a/FASTDOOM/ns_sbmus.c b/FASTDOOM/ns_sbmus.c
index 49e2d02..a7eedb9 100644
--- a/FASTDOOM/ns_sbmus.c
+++ b/FASTDOOM/ns_sbmus.c
@@ -110,16 +110,16 @@ static VOICELIST Voice_Pool;

 static CHANNEL Channel[NUM_CHANNELS];

-int ADLIB_PORT = 0x388;
-static int AL_LeftPort = 0x388;
-static int AL_RightPort = 0x388;
+int ADLIB_PORT = 0x378;
+static int AL_LeftPort = 0x378;
+static int AL_RightPort = 0x378;
 static int AL_Stereo = FALSE;
 static int AL_SendStereo = FALSE;
 static int AL_OPL3 = FALSE;
 static int AL_MaxMidiChannel = 16;

 static int AL_OPL2LPT = FALSE;
-static int AL_OPL3LPT = FALSE;
+static int AL_OPL3LPT = TRUE;

 void AL_SendOutputToPort_OPL2LPT(int port, int reg, int data)
 {
@@ -1213,11 +1213,12 @@ int AL_Init(int soundcard, int Address)
    {
    case Adlib:
    default:
-      AL_OPL3 = FALSE;
-      AL_Stereo = FALSE;
-      AL_LeftPort = 0x388;
-      AL_RightPort = 0x388;
-      ADLIB_PORT = 0x388;
+      AL_OPL3 = TRUE;
+      AL_Stereo = TRUE;
+      AL_LeftPort = 0x378;
+      AL_RightPort = 0x378;
+      AL_OPL3LPT = TRUE;
+      ADLIB_PORT = 0x378;
       break;
    case OPL2LPT:
       AL_OPL3 = FALSE;

Am I missing some extra declaration?

viti95 commented 1 year ago

Adlib FX is not compatible with OPLx music, because it sets the registers in an specific way and then bitbangs with attenuation commands, so only digital sound is supported. It's possible to use music though, selecting the new PCM music device (basically plays RAW music like a CD player).

To make it work I think more steps are required. _ADBFXServiceInterrupt from ns_adbfx.c should call _AL_SendOutputToPortOPLxLPT instead of outp instruction directly (this was an optimization I made to spent as little time as possible to send data to the OPL chip. Also _ADBFXInit probably needs to be changed, as it requires to wait an specific amount of time to initialize the registers (to set the highest possible frequency in one channel).

Edit: The Adlib FX code only supports 8-bit mono sound, but works on both OPL2 and OPL3 chips. Other issue is that the volume is generally low, some amplification is required to make it sound properly.

Edit 2: I could prepare a test executable to test this, probably tomorrow.

viti95 commented 1 year ago

FDOOM.zip

I've built an executable to test if these changes work, don't know really if it will work πŸ˜…

jsmolina commented 1 year ago

thanks! I'll test this afternoon and provide you feedback.

jsmolina commented 1 year ago

FDOOM.zip

I've built an executable to test if these changes work, don't know really if it will work πŸ˜…

I tried by disabling music and only setting ADLIB FX, and no FX were played at all.

Is there a way to know that the LPT port is getting data? (debug mode).

viti95 commented 1 year ago

I could modify the code to create a file based log and see what's the initialization process and what's written to the ports. I'll try to get it done this week. Also I've bought an OPL2LPT, so I will be able to test myself. Hope it delivers soon.

Edit: I'll send you a custom cfg, because the setup program is not updated and I think that is another issue. Do you have an OPL2LPT or an OPL3LPT?

jsmolina commented 1 year ago

I could modify the code to create a file based log and see what's the initialization process and what's written to the ports. I'll try to get it done this week. Also I've bought an OPL2LPT, so I will be able to test myself. Hope it delivers soon.

Edit: I'll send you a custom cfg, because the setup program is not updated and I think that is another issue. Do you have an OPL2LPT or an OPL3LPT?

I do have an OPL3LPT. they are compatible (OPL3LPT can work in OPL2LPT mode). Thanks!!

viti95 commented 1 year ago

I've received the OPL2LPT v2 from Serdaco and been able to do some testing. Here are the good news, PCM playback on OPL2LPT works, so this feature will be included in the next release πŸ˜„

jsmolina commented 1 year ago

I've received the OPL2LPT v2 from Serdaco and been able to do some testing. Here are the good news, PCM playback on OPL2LPT works, so this feature will be included in the next release πŸ˜„

that's really nice!!