Aureal 3D (A3D) restoration/achieving better (3D) sound quality in Rayman 2 and Tonic Trouble (SE) | UPDATE! 3

Discuss tools to aid in the modification and running of Rayman games.

Moderators: English moderators, Modding and utilities team

Post Reply
deton24
Dora Dodemer
Posts: 787
Joined: Fri Jan 14, 2011 1:22 am
Location: Poland
Tings: 5721

Aureal 3D (A3D) restoration/achieving better (3D) sound quality in Rayman 2 and Tonic Trouble (SE) | UPDATE! 3

Post by deton24 » Fri Apr 06, 2018 11:09 pm

How to achieve better sound quality in Rayman 2 PC –
Restoring Aureal 3D (A3D) by Alchemy,

and/or alternatively with DirectSound (w/o music) by DSOAL, and overwriting \DLL sound libraries.


New instruction for (I think) crashless A3D enabling:

To restore Aureal 3D effects in Rayman 2:
1. Install Creative Alchemy
(dsoal didn't work for me with this A3D library set, but the guy here https://www.youtube.com/watch?v=3CvgxWhZhXUfound a workaround)
2. Then install the game in the Alchemy (or make sure that dsound.dll and dsound.ini are present in R2 root folder)
(for non-Creative cards check Alchemy for all tool
http://forums.thedarkmod.com/topic/1824 ... soundcard/)
3. Copy these files into Rayman2\DLL folder
https://yadi.sk/d/qJbaZ20a3aSYLC
4. Then install A3D Live
http://www.worknd.ru/A3D-Live.exe (mirror: https://yadi.sk/d/6T0eYWdQ15Tx6A)
5. Probably game will crash on splash sound, so navigate to Windows folder and search for a3dsplhs.exe and delete it.

Now the game should work with A3D enabled. In some cases you must load the game fast to avoid crash.

Files from step 3:

Code: Select all

Snd_Cpa.ini:
[Options]
Sound_ON_OFF=ON
MPEG_ON_OFF=ON
WAV_ON_OFF=ON
ADPCM_ON_OFF=ON
CD_ON_OFF=OFF
SUPERVISATER_ON_OFF=ON
SXD_DIST_SATUR=8
SXD_DIST_FADE=30
FORCE_LOAD_BANKS=ON

[DLL_Test]
File0=WAVa1

[DLL_Sxd]
Unconditionnal=WAVa1
File0=WAVa1
Test0=_SND_fn_bIsDirect3DOptimum@0
File1=WAVMW
Test1=_SND_fn_bTestSnd_MMX@0
Default=WAVMW

[DLL_Adpcm]
Unconditionnal=None
File0=APMMX
Test0=_SND_fn_bTestSnd_MMX@0
Default=APMP5
[Directx3D Options]
GUID for WinNT=Primary Sound Driver
Disable A3D=No
Speakers Configuration=Stereo
Nb Voices=64
and WAVa1BVR.dll was taken from Donald Duck; for better performance use original R2 file when using my Reshade/SweetFX mod.

For Tonic Trouble (Special Edition):
Use the same steps as above, but in the end, use this ini:
https://yadi.sk/d/4-E0nyOsxLmTvw

Sometimes it may happen that error about outdated A3D library error will be shown instead of splash. If sound won't disaper, you can ignore it, and press alt+tab to return to the game immediately after A3D splash screen to avoid game crash on startup if you will wait to long. If sound disappears, and error shows, try installing A3D Live again.

From my previous testing looked like achieving splash/no error, instead of error on startup, caused the game to crash from time to time (esp. in the ends of the levels). So be aware. You can also try to uninstall A3D Live in this case.

In other case during testing, it looked like the game passed through the old R2\DLL library, not A3D Live (no splash - but error) and somehow A3D Live installed in the system, prevented from disappearing sound effects during gameplay, but without showing splash - actually using newer A3D drivers from the system which caused crashes.
It was the most stable setting with using A3D, and I don't know how to reproduce this state since it looks now like ini was the same all the time. Or who knows, maybe the truth lurks somewhere in combination of my old inis and Donald Duck/fanpage libraries:
https://yadi.sk/d/x49SKzs2-Spw4Q


Donald Duck game sound library sounds a bit better vs stock, but in cost of certain performance loss while using e.g. SweetFX.

Tested on GOG version, nGlide, and W10.


In case of unbearable crashes of the game, check out this method listed in description of the video:
https://www.youtube.com/watch?v=3CvgxWhZhXU


Notes
Synthesis couldn’t restore 44kHz support by the sound engine, despite the fact of achieving properly decoding 44kHz custom music – but played in 22kHz:
viewtopic.php?f=66&t=4782&p=1151131#p1147786

Even when he overwrote sound libraries from Donald Duck Quack Attack (2000) which actually helped kooz in Tonic Trouble to actually change engine’s sample rate:
viewtopic.php?f=66&t=5981&start=80#p1183649

Enabling A3D also didn't solve the problem. Full 44kHz can't be played by the game even with 44kHz game music files. The game still lowers sample rate.


Instruction about enhancing sound quality without using A3D

What is the purpose of Alchemy/DSOAL dsound.dll
It’s restoring DirectSound, which had been deprecated since Windows Vista (by worsening overall sound quality in lots of older games), and served to hardware acceleration of sound cards, it was used by many sound engines in these times.

Sound engine of Rayman 2 has 2D driver (default), Aureal3D (A3D), and buggy DirectSound (no music; or I failed with ini editing).
Alchemy/DSOAL is still required to make A3D work.
In R2, in scenario without using A3D, I recommend using DSOAL as a tool of restoration DirectSound (IMHO – positioning in this library is better than in Alchemy, which is not using HRTF, though general sound quality is better in Alchemy for me).
For even better sound quality I also prefer overwriting sound libraries to these used in Donald Duck Quack Attack. Then I recommend combining DSOAL with DD libraries for better results.
For A3D - Alchemy and stock library (or DD if you don't notice performance difference - but I didn't test it entirely in matter of crashes, bugs, sound disappearing [though without A3D Live, DD library may behave better].

Instruction without Alchemy and A3D:
1. Copy dsoal (dsound.dll and openal32.dll) to root game directory (\Rayman 2)
http://kcat.strangesoft.net/dsoal.zip
2. Overwrite sound libraries from Donald Duck in folder Rayman 2\DLL
https://yadi.sk/d/McvOBFGk3U6Tdz (R2 only)
3. Speaker configuration (2.0, 5.1) may have an influence on sound quality (look dsoal readme).
4. Music may become quieter (if so, just adjust it in game options).
5. The game stops using injected dsound.dll/OpenAL32 after you press Alt+Tab (e.g. during using Reshade/SweetFX dll injector, the game completely stops working after alt tabbing – not all injected dll’s starts to work again then).

Note
In below site, uploaded sound library seems to be a bit newer than that from Donald Duck. You can find it here:
http://www.rayman-fanpage.de/rayman2/ra ... ysound.exe
Attached ini in link, or at least this one https://yadi.sk/i/owh-f8QH3ZYDiB
It is another OpenSpace engine library responsible for enabling A3D along with Creative Alchemy (dsoal/indirect sound cause glitches in R2).
Claimed to fix sound disappearing issues, although it didn't when I tested. You can try out.
Main page: http://www.rayman-fanpage.de/rayman2/ra ... nglish.htm
Original library has the best performance during recording via Windows DVR when using Reshade/SweetFX.
Donald Duck maybe sounds a bit better, and that from the fanpage prevents from achieving 60 FPS while using fast scroll lock toggling hack (details in my R2 Reshade/SweetFX thread).
From time to time, unfortunately sound disappears in the middle of the level, or certain sound (currently I don't have this issue, don't know whether it was from game library, A3D installation, or something else).
DD library and fanpage library can be a bit less vulnerable for the bug with disapearing sound.
Probably just A3D in this game wasn't exactly intended to work, and it's not refined.
And there are some sound distortions introduced, like change of pitch of some jingles during movement.

Another interesting bunch of information about sound drivers in the game:
https://tcrf.net/Proto:Rayman_2:_The_Gr ... und_Script

_______________________________________________________________________________________

down @Synthesis
Thanks a lot for your exhaustive answers in the case.
dsound.dll almost never exists nearby any game files, but it doesn't mean that they won't be used if present (it's easy to check it in Process Explorer.

The same goes for ddraw.dll in R2 (when DX6 is set), dinput, or d3d8, d3d9, dxgi (when nGlide reroots it to dxgi) used in other games.

I think that Rayman 2 itself, apart from Tonic Trouble, causes just specific problems with getting work 44kHz. dsoal only changes the way of mixing the sound, not really a sample rate. In dsoal readme we can also find that 5.1 configuration can force the library to use WASAPI (so speaker level in control panel wouldn't be visible). That's the last thing which comes to my mind about library itself which may change anything in this case.

More information about A3D wrapping here:
https://docs.google.com/document/d/1SyO ... Tpyhc/edit


@down
22kHz
Last edited by deton24 on Fri Sep 27, 2019 7:59 am, edited 46 times in total.

WizardMinecraft
Électoon
Posts: 502
Joined: Wed Nov 15, 2017 4:53 am
Location: DEATH HILL
Tings: 7

Re: How to achieve better sound quality in Rayman 2 PC – restoring DirectSound by dsoal, and overwriting other sound DLL

Post by WizardMinecraft » Fri Apr 06, 2018 11:11 pm

Wait, wasn't the PC version of R2's audio quality good enough?
Image

Synthesis
Garatta Ciatik
Posts: 47
Joined: Fri Jan 02, 2009 7:48 pm
Location: France
Tings: 10235

Re: How to achieve better sound quality in Rayman 2 PC – restoring DirectSound by dsoal, and overwriting other sound DLL

Post by Synthesis » Sun Apr 08, 2018 7:58 pm

Alright... I have to admit I didn't start taking the time to experiment what you suggested, because I noticed something wrong with my encoded 44k tracks.

Actually, the DC offset that was slowly building up over time was not at all due to the downsampling... in fact it's my compression tool itself.
Here's my thought process: if the DC offset buildup is caused by downsampling, I'll just mark my custom files as 22kHz in their header. That way, the game will play them twice slower, but they should be decoded just fine. Turns out I was wrong, the DC offset was still there.

Which means I must have gotten something wrong somewhere, my (IMA-ADPCM-based) APM decoder doesn't seem to behave quite like Rayman 2's.
Which also means I'll have to investigate further on that, and the thought of having to load up the code in a debugger (if I'm lucky enough to make it work at all), locate the piece of code that decodes an apm file, try to understand what the heck it does and figure out the actual instructions that generated the asm code, so I can eventually make up an algorithm that would do the reversed process... is really overwhelming, not gonna lie.

And as a matter of fact, my knowledge of ADPCM and its variations is pretty limited. I hit a brick wall with Ray3Get, and Ray2Get is merely a C implementation of some algorithm in pseudo-code I had read on MultimediaWiki without really trying to understand its ins and outs back then. I was fumbling around blindly, and eventually managed to make its output files sound pretty darn close to what could be heard in-game, but I never did proper comparisons (ie. phase-cancellation tests); and today I have become pretty confident that it isn't as accurate as it could be.

I think I understand how ADPCM works, but there are still a lot of details that elude me, particularly about the APM format. Here's what I inferred from what I observed in the APM file header:

Code: Select all

Offset | Size    | Type   | Information
-------|---------|--------|----------------------------------------------------
0x0    | 2       | short  | Format tag (0x0020 for Ubisoft ADPCM)
0x2    | 2       | short  | Channel count
0x4    | 4       | int    | Sample rate
0x8    | 4       | int    | Byte rate, as if it were uncompressed 16-bit PCM
0xC    | 2       | short  | Block alignment (usually = 1)
0xE    | 2       | short  | Bits per sample
0x10   | 4       | int    | Size of the next APM description chunk (including
       |         |        | this value) ; should be 0x50 (80 in decimal)
0x14   | 4       | char*4 | APM signature/version number? (default value is
       |         |        | "vs12")
0x18   | 4       | int    | Total file size, in bytes
0x1C   | 4       | int    | Audio data length, in nibbles
0x20   | 4       | ?      | ?? (four consecutive 0xFF bytes)
0x24   | 4       | int    | ?? (four consecutive null bytes)
0x28   | 4       | int    | Odd/even nibble indicator (*real-time, see below)
0x2C   | 12*chan | -      | For each channel, last to first:
       |         |        |     (eg. stereo files stores right channel first)
       |   4     | int    | Initial PCM value (with 16-bit sign extension)
       |   4     | int    | Initial ADPCM step index
       |   4     | byte*4 | Beginning of the APM data (wtf?) (**see below)
0x38   |         |        | and so on...
...    | ?       | -      | Null bytes for padding
0x60   | 4       | char*4 | Data chunk header ("DATA")
0x64   | ?       | char*? | APM audio data

The APM audio data is stored as follows: the channels are interleaved, and
since each sample takes only 4 bytes, they are stored in pairs. For example,
the beginning of a stereo file would look like
    0xAB 0xCD 0xEF 0xGH ...
A: left channel, 1st APM sample
B: left channel, 2nd sample
C: right channel, 1st sample
D: right channel, 2nd sample
E: left channel, 3rd sample
F: left channel, 4th sample
G: right channel, 3rd sample
H: right channel, 4th sample, and so on.

If the total number of sample is odd, then for each channel, the last byte will
be filled halfway. The least significant bits are left to 0. For example, the
end of a stereo file would look like
    ... 0xY0 0xZ0
with Y and Z being the last samples of respectively the left and right
channels.

(*) At address 0x28, there's a 4-bit reserved value which should be equal to 0.
This is because the header is copied in memory while the game runs, and some
areas of the header are actually used (but the file itself is untouched).
This particular value is an even/odd indicator: since ADPCM is 4-bit, there are
two samples per byte; this value is used in the decoding algorithm to indicate
if it is currently processing the odd (most significant) or even (least
significant) nibble.

(**) For some reason, the beginning of the APM chunk is stored in the header in
an unusual way: the 4-byte value corresponds to the first four bytes of the
(multi-channel interleaved) APM data, starting from the byte corresponding to
the channel. Say we have a stereo file. In the header appears the following
sequence:
0x2C   | 4       | int    | Initial PCM value for right channel
0x30   | 4       | int    | Initial ADPCM step index for right channel
0x34   | 4       | byte*4 | Bytes 2 through 5 of the APM data chunk     <---
0x38   | 4       | int    | Initial PCM value for left channel
0x3C   | 4       | int    | Initial ADPCM step index for left channel
0x40   | 4       | byte*4 | First four bytes of APM data                <---
0x44   | 28      | -      | Null bytes for padding

Note: there are 52 bytes for storing the initial ADPCM variables, which means
that the APM format could support up to 4 channels, leaving 4 null bytes for
padding.
There's still a lot of data which I don't know what it is used for. Furthermore, the initial ADPCM index values are just blind guesses, and I'm not sure if the channels are actually in reverse order. I have no idea why it would be the case. Let alone why the beginning of the audio data would be copied in the header.

Edit: just thought of another reason why my tool would produce inaccurate files: maybe the game uses a slightly different ADPCM step table, which could result in decoded PCM values being slightly off.
Edit 2: I just compared, my ADPCM table and the one in Rayman 2's DLL (APMmxBVR.dll) are identical. Other hypothesis: some values in the APM header aren't exactly what I think they are, and I got the initial values wrong.
Edit 3: Oooooh! I just stumbled upon OpenRayman, which is an open source reimplementation of the Rayman 2 engine. It's hosted on GitHub, and the code provides some more info about the APM file format! I just updated my current description above.
Edit 4: Finally! I found what the error was in my own decoder. There's a variable which, for some reason, has its least significant 3 bits masked in the decoding process, while those bits are left in their original states in the standard ADPCM algorithm.
Last edited by Synthesis on Sun Apr 15, 2018 8:00 pm, edited 4 times in total.

Harpic fraîcheur
Rayman Origins
Posts: 26122
Joined: Sat Jan 18, 2014 7:57 pm
Location: Au pays des prouts
Tings: 1028334

Re: How to achieve better sound quality in Rayman 2 PC – restoring DirectSound by dsoal, and overwriting other sound DLL

Post by Harpic fraîcheur » Mon Apr 09, 2018 1:44 pm

Hello détron24! :)
Une nouvelle vague de fraîcheur, Harpic fraîcheur verte ! 8)
ImageImage
boomboleros7 wrote:Harpic est imbattable. Harpic est légendaire. Harpic est divin.
Sanhedrin wrote:“Il est autorisé d’avoir des rapports sexuels avec une fille de trois ans et un jour »

Synthesis
Garatta Ciatik
Posts: 47
Joined: Fri Jan 02, 2009 7:48 pm
Location: France
Tings: 10235

Re: How to achieve better sound quality in Rayman 2 PC – restoring DirectSound by dsoal, and overwriting other sound DLL

Post by Synthesis » Sun Apr 15, 2018 10:15 pm

Welp... sounds like bad news. I followed your steps and didn't manage to set the game's sample rate to 44100Hz. Even worse, I noticed that there's no anti-aliasing before downsampling, so any 44100Hz audio file will have the upper half of its spectrum folded back into the lower, audible, half.

Here's what I did:
1. Downloaded the zip files you provided for the dsoal library and the DLL folder.
2. Copied dsound.dll and openal32.dll to the game root directory, next to the Rayman2 executable. Surprisingly there didn't seem to be any already existing file called dsound.dll. So I assume the game wouldn't do any DirectSound call in the first place, which would make dsoal essentially useless in our case.
3. Renamed the DLL directory to prev_DLL (in case of screw-ups, so I still have a backup copy).
4. Copied the DLL folder you provided.

I tried with both the Rayman2 and Quack Attack "Snd_cpa.ini" and "GliVd1vf.dll" files. In both cases, the audio engine still would run at 22050 Hz with aliasing.

I must have missed something...?

But in other (related) news... something really cool is about to be released.

Edit: Interesting... the game engine doesn't seem to support mono APM files. I tried that by replacing MM01.apm (the beginning of the Hall of Doors music, which happens to be used for the main menu) with outro1.apm (the only mono file provided with the game); it just isn't played at all. Good to know.

deton24
Dora Dodemer
Posts: 787
Joined: Fri Jan 14, 2011 1:22 am
Location: Poland
Tings: 5721

Re: Aureal 3D (A3D) restoration / achieving better sound quality in Rayman 2 | UPDATE!

Post by deton24 » Tue Aug 28, 2018 12:09 am

Update. I managed to set Aureal 3D (A3D) in ini:

To restore Aureal 3D in the game:

1. install Creative Alchemy,
2. install the game in the Alchemy
(for non-Creative cards see http://forums.thedarkmod.com/topic/1824 ... soundcard/)
3. copy these files into Rayman2\DLL folder
https://yadi.sk/d/qJbaZ20a3aSYLC
4. Then install A3D Live
http://www.worknd.ru/A3D-Live.exe
5. Press alt+tab to return to the game immediately after A3D splash screen to avoid game crash on startup.
6. If game will crash on splash sound, navigate to Windows folder and search for a3dsplhs.exe and delete it.

If all above only gives you crashes, look for this video description (alternative method):
https://www.youtube.com/watch?v=3CvgxWhZhXU



Rayman 2 with 3D sound is really cool... :>

Looks like RibShark knows how to enable A3D in Tonic Trouble.
edit.
Use the same steps like above, but in the end, use this ini:
https://yadi.sk/d/4-E0nyOsxLmTvw
Last edited by deton24 on Sun Sep 08, 2019 8:28 pm, edited 5 times in total.

Harpic fraîcheur
Rayman Origins
Posts: 26122
Joined: Sat Jan 18, 2014 7:57 pm
Location: Au pays des prouts
Tings: 1028334

Re: Aureal 3D (A3D) restoration / achieving better sound quality in Rayman 2 | UPDATE!

Post by Harpic fraîcheur » Tue Aug 28, 2018 12:26 pm

Wow, it's been so long détron24! It's nice to see you're still up to bring the best shit to us. :)
Une nouvelle vague de fraîcheur, Harpic fraîcheur verte ! 8)
ImageImage
boomboleros7 wrote:Harpic est imbattable. Harpic est légendaire. Harpic est divin.
Sanhedrin wrote:“Il est autorisé d’avoir des rapports sexuels avec une fille de trois ans et un jour »

Post Reply