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

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: 717
Joined: Fri Jan 14, 2011 1:22 am
Location: Poland
Tings: 5371

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

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

How to achieve better sound quality in Rayman 2 PC –
Restoring DirectSound by dsoal, and overwriting \DLL sound libraries.


Though Synthesis couldn’t restore 44kHz support by the sound engine, despite the fact of achieving properly decoding 44kHz custom music – but played in 22kHz:
https://raymanpc.com/forum/viewtopic.ph ... 1#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:
https://raymanpc.com/forum/viewtopic.ph ... 0#p1183649

I came up with another idea of enhancing the sound quality of Rayman 2 PC (which maybe can interfere with mentioned case). It’s restoring DirectSound, which had been deprecated since Windows Vista (by worsening overall sound quality in lots of games), and served to hardware acceleration of sound cards, it was used by many sound engines in these times (though GTA V still uses it). Sound engine of Rayman 2, by different sources, is claimed as Aureal3D (A3D). I recommending using dsoal as a tool of restoration DirectSound used by different sound engines among few others, because it restores DirectSound, and translates its calls into OpenAL (IMHO – positioning in this library sounds even better than in Alchemy, though it also translates DirectSound calls into OpenAL, but generally 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. I recommend combining these two things for better results.

Instruction (obsolete):
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).

PS. In this site, one sound library seems to be a bit newer than 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
enables A3D along with Creative Alchemy (for non-Creative cards see here: http://forums.thedarkmod.com/topic/1824 ... soundcard/). dsoal/indirect sound cause glitches in R2.
Visit the site here: http://www.rayman-fanpage.de/rayman2/ra ... nglish.htm
edit. 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 scrol lock toggling hack (details in my R2 Reshade/SweetFX thread).
From time to time, unfortunately sound disapears in the middle of the level, or certain sound.
DD library and fanpage library can be a bit less vulnerable for this bug.
Probably just A3D in this game wasn't exactly intended to work, and it's not refined.

dsoal doesn't work with this A3D library set.

Edit. New instruction for (hopefuly) crashless A3D enabling:
To restore Aureal 3D effects,
install Creative Alchemy,
then install the game in the Alchemy
(for non-Creative cards see http://forums.thedarkmod.com/topic/1824 ... soundcard/)
and copy these files into Rayman2\DLL folder
https://yadi.sk/d/qJbaZ20a3aSYLC
Then install A3D Live
http://www.worknd.ru/A3D-Live.exe
Press alt+tab to return to the game immediately after A3D splash screen to avoid game crash on startup.


So far, it's the most stable setting. It looks like it passes through the old R2\DLL library, but somehow A3D Live installed in the system, prevents from disapearing sound effects during gameplay. Ommiting R2 library straight to the A3D Live libraries (relevant entries in ini) causes better sound quality, but game crashes from time to time (esp. in the ends of the levels).

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

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.
Even Rayman Origins (and probably Legends) uses it.
The same goes for ddraw.dll in R2 (DX), dinput, or d3d8, d3d9, 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.

@down
22kHz
Last edited by deton24 on Fri Aug 24, 2018 2:17 am, edited 20 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: 26035
Joined: Sat Jan 18, 2014 7:57 pm
Location: Au pays des prouts
Tings: 1236419

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)
Image Image
boomboleros7 wrote:Harpic est imbattable. Harpic est légendaire. Harpic est divin.

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: 717
Joined: Fri Jan 14, 2011 1:22 am
Location: Poland
Tings: 5371

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.

If 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.
Last edited by deton24 on Sat Oct 27, 2018 4:41 pm, edited 2 times in total.

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

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)
Image Image
boomboleros7 wrote:Harpic est imbattable. Harpic est légendaire. Harpic est divin.

Post Reply