I'm curious, is this a priority for anyone? The reason I ask is because I noticed that none of us in the Xbox emu author community (and I'm talking about myself also; not trying to shame anyone) except _SF_ have put much time and effort into the sound stuff. In my old branch, I was looking into adding Xbox ADPCM support for sound buffers at least, but my implementations weren't working. It should be easy enough to do, since a well written Xbox ADPCM <-> PCM encoder/decoder exists.
There's several things that have not been implemented audio wise, especially when it comes to the notification events and audio streaming not being implemented properly for most games except Panzer Dragoon ORTA and Metal Slug 3.
So unless you guys would prefer me to do something else, I'd like to look into supporting Xbox ADPCM sometime soon along with other things. So, feel free to give me a yay or nay on this one.
Shogun.
You're welcome to check it out, although I'd like to start working on an LLE implementation of audio pretty soonish.
Yeah, I'd like to make a similar attempt audio wise, but I only have a basic knowledge of how ac97 works atm, and have only seen one basic example used to get some sound bytes running from an old OpenXDK demo. It's a start though.
Shogun.
Okay, I did end up implementing the Xbox ADPCM decoder and did manage to get it to work but only with code that uses Lock, but not SetBufferData for some reason. It also wasn't very stable as it was really tricky to resize buffers without them failing constantly. I guess we are better off just focusing on the LLE audio instead because audio emulation is still kind of abysmal in the Xbox emu scene.
Shogun
Hi @blueshogun96, I actually had Xbox ADPCM decoder, third-party code, implemented about 4 months ago to verify sounds are functional for xbox audio PCM. Turn out they're unrecognizable noises no matter what. I had used dashboard and Turok Evolution game to verify it. The only problem I have with Turok Evolution is FPS are way too fast even with vsync enabled. As for dashboard, I can't identify the audio as if they're extremely quiet.
Now that's back then, to this latest Cxbx-Reloaded revision... I am not getting any xbox audio output at all. Can you please create a branch just for Xbox ADPCM implemented you did so I can verify why it's not functional at my end? I'll drop a message here of what might need to change.
Thanks
Sure thing. I'll try that when I get home or something. It's basically slapped together. Thanks for the feedback.
Shogun
Sorry it's been a while @RadWolfie , frantically looking for a job right now so I almost forgot to share this
https://pastebin.com/VXqcZneJ - EmuDSoundXbAdpcm.cpp
https://pastebin.com/HCrYDpP9 - EmuDSound.cpp (mine)
I hardly get much time to fiddle with Cxbx because of the nature of contracting, but this is my result of a weekend's worth of work on the Xbox ADPCM stuff.
Shogun
Oh... apparently I forgot to remove if & else check code out within IDirectSoundBuffer_Play function.
I am now getting distorted sounds from xbox audio. I think I do hear xbox audio is played correctly when change menu selection, enter and leaving from dashboard. Except for background music sound which is still distorted. After a lot of diagnostics of trying to get it work correctly... I realize there is no IDirectSoundBuffer_Unlock function integrated in order for xadpcm decoder to work correctly. Unlock function doesn't exist as explained by @PatrickvL's further post below.
Now, the reason for IDirectSoundBuffer_Unlock is needed due to DirectSound does not need to pause/stop the audio at any time writing a new audio bytes on currently played DirectSound buffer. Correct me if I'm wrong. I am so, so, so wrong. Thanks @PatrickvL!
@jarupxx, do you think you can find IDirectSoundBuffer_Unlock to patch? Never mind, @PatrickvL answered to my question.
P.S. Unable to get Turok Evolution's xbox audio to play, pretty sure something broke in-between 4 months ago to recent. And JSRF sound almost perfect with the current implemented I did.
@blueshogun96 Implement your decoder in play function isn't really recommended to put in case you had read above. Oh, and we're using the same decoder function by same author too. Sweet!
If audio works the same as 3d, then the Unlock function doesn't exist. In 3d, Lock just returns the memory address of the requested resource. This memory address will stay the same until the resource is deleted.
So, for 3d, we unlock the host version of each resource right before drawing occurs, and just before a new Lock is requested. This means the lock will stay open a little longer than needed, but overall it works okay
Later on, I'll remove most patches for 3d resources (like textures), so Xbox code sees what's it's supposed to see - the emulated (host) version of those resources will become a completely separate copy. I'll use a periodic hash too see if the copy needs updating (because Xbox code might have altered the contents of a resource). Those updates cost a little bit of time to re-convert from Xbox to host format again, but the benefit is less dependency on patches, and no more abuse of Xbox resources (which currently cause all sorts of problems)
Oh and with "unlock doesn't exist" I mean it's defined as an empty statement block: {}
Hmm... had been re-do the xbox audio again base on @blueshogun96 "unlock" decoder implement. It actually, in some way, works. As for Turok Evolution is not getting xbox audio... I take it back, I am getting xbox audio from it now.
@PatrickvL, if Unlock function doesn't exist. Then it wouldn't be able to play the audio in locked section, right? Ah interesting...
It starting to sound right in Turok Evolution and dashboard (almost). JSRF is quite interesting to have so much distorted audio. I'll keep working on this not to be so distorted audio.
Yes, Patrick is correct. On Xbox, you can write to memory resource pointers directly. If I were coding an Xbox title, I'd use SetBufferData over Lock though.
So, did you manage to get sounds in Turok to play correctly? Good. Let me know if you need a hand with it. I'd also like to consider 3D audio features too. Each buffer will require a separate IDirectSound3DBuffer though and a listener will need to be created at initializatiin. Although I will be busy this weekend prepping for a job interview. Fortunately everything I learned fro Cxbx helped me make it to this point, so I am greatly indebted to sir Caustik to this day.
Shogun.
@RadWolfie Could you, as soon as you've got your code playing stable, issue a pull request? It'd be nice to finally get some real improvements in audio emulation!
I would if I can get this stinky background music to play right without static noise... I wouldn't use this xbox audio experimental emulation to testers. (It will bring HUGE pain to their ears and possibility damage their speakers.)
Sounds for like walking, menu selection, etc are playing correctly. Except for... Turok Evolution's intro, it's missing a play function or we overlooked a flag triggering it to play audio automatic. Hence no audio, however if I do keep setnotification and play in hacked update audio. It does play correctly, except everything else start to become static noise and repeating same audio when shouldn't be.
Some time later on, I'll create a branch for this xbox audio experimental emulation. Once background music is playing correctly, I'll issue a pull request.
Hmm... xbox audio is detected inside Lock function, sadly we cannot decode it there since it occurred after audio has been played. I think this is the source of the static noise for background music on dashboard and Turok's gameplay. I'm gonna try something in a few days from now to see if it actually a success. I am almost there... EDIT: There's no success from this point, I thought DirectSoundDoWork might be good place to put decoder in, didn't help with Turok and dashboard issue. Though, I left it in there just in case.
@blueshogun96 I went ahead implemented most of the 3D audio features from IDirectSound3DBuffer support and the sound is much better to me, though I'll need some feedback from others to be sure. Perhaps you can fill in missing feature which aren't implemented with PC's IDirectSound3DBuffer feature later on?
P.S. I am able to hear Turok's background music correctly in-game menu. I'll post specific games which has xbox audio and what's not working properly for those games as well (perhaps in separate topic for it).
I would expect the best moment to convert buffers is when they are started for playback. As a comparison: I'm busy converting textures right before drawing occurs, which fixes various issues. Audio could be converted in a similar way, right before playing occurs.
May I urge you to fork the Cxbx reloaded repository, in there branch off your master to an ADPCM branch, and commit your progress there? When you publish and regularly sync that, we can review with your work.
I agree with @PatrickvL, it's amazing that you're working on this, but we would both like to see what you're working on!
Hmm... look like there is an audio bug somewhere for Turok Evolution on first gameplay. If you do leave to menu then re-try again, it did not return. I'll go ahead with this revision I made for now so others can review and test it out. Here's the link to XADPCM decoder branch. Before I make the pull request, I want to implement option for both developer and users to choose turn off audio either PCM or XADPCM. That way it will be easier for all of us to know which audio is causing bad noise, distortion, looping, etc. What do you guys think?
Following titles has been tested with:
Wait this c4ef88f (First audio implementation commit of yours) wrongly refers to this general emulator as "Cxbx". That is now obsolete. Instead it should be called "Cxbx-Reloaded".
These look like very highly complex pieces of audio engineering/writing, especially to a fairly non-technical user like me. We thank you (& blueshogun) very much for working on them!
I've improved a few Dsound OOVPA, here's a link to that branch for anyone to test it : https://github.com/PatrickvL/Cxbx-Reloaded/commits/DSound
Actually, I've submitted it as a pull request, so it can be merged in once tests have established there​ are no regressions
@ObiKKa, yes you are correct. Though, all files' text are still named as Cxbx. I'll leave this alone until someone else update all the files text from Cxbx to Cxbx-Reloaded. It is fairly simple to update all of the files.
It's not quite complex, just need to strip out unnecessary codes which doesn't perform the way PC's DirectSound does. Then implement proper way to mock up the way it supposedly do. :wink:
@PatrickvL I tested it out with my audio implement. I don't see any regression so far. Only thing it did regress is your HLE menu changes and inside HLEDatabase files, it means I'll have to re-implement with correct prefix you had included.
Sorry it's been a while since I've last responded. I've been trying frantically to get a new job...
Good to hear some progress on this. During my time away from the scene, I started thinking about writing an Xbox DirectSound wrapper using OpenAL-Soft instead. It seems to me that native DirectSound is causing several setbacks. On top of that, I really want to just rewrite much of that DirectSound code, especially for the sake of emulating DirectSound streams (which would be much easier to emulate and manage via OpenAL-Soft in my honest opinion). PC DirectSound is lacking several features that I believe OpenAL-Soft will give us a better deal with.
Too bad I don't really have much time to dedicate to what I'm suggesting because IRL stuff is really sucking up all my time right now. There's other things I wanted to do for the Xbox [emulation] scene (I'll probably just blog about it later once all this joblessness nonsense blows over) that will hopefully benefit Cxbx-Reloaded and xqemu too.
Shogun
@RadWolfie Yeah, renaming OOVPA will invalidate HLE caches indeed. Sorry about that. I hope people will understand that our code is still very much in motion. Thanks for working on this, and if I can do anything to help, just ask. Good luck!
Only help I need is getting DSound's OOVPA signatures either corrected or add the missing necessary patches to fix other games and dashboard audio. I have no clue how OOVPA works and not planning to learn how it works (I get a brain-freeze just for that). Only way I can assist with this is to provide correct address if I can locate its whereabouts for specific audio function caller. Then someone else will need to fix or add OOPVA for it.
@blueshogun96 You're right, I tried implement DirectSound3DListener to fix remaining missing function from Xbox DirectSound wrapper. Turns out it is only effective on primary buffer. I am confused why Xbox is allowing it when PC doesn't even allow it to happen.
P.S. I'm graceful for @LukeUsher revived HLE cache support. I can upload some correct addresses to further assist someone to fix DSound's OOVPA as well. Plus I'm not an expert with DirectSound, just a small basic understanding of how it works.
Great work so far!
Regarding OOVPA:
Can you give us a list of what functions are either not detected at all, or detected in the wrong place? That can at least give us an idea of which OOVPA need to be looked at or added
@RadWolfie yeah, that is very strange. IMHO, DirectX can be quite picky about such things. This is why I recommend writing an Xbox DirectSound wrapper that redirects to OpenAL-Soft instead. This would solve the issue a little easier. Plus OpenAL-Soft is still being updated, and supports many features that DirectSound lacks, such as environmental audio and DSP effects (of course, that's not important right now). With OpenAL-Soft, you don't have to worry about creating listeners yourself, as there is only one which is used by default (same with Xbox DirectSound) and no need to manage separate sound buffers for 3D.
Also, I took a look at your implementation(s). Are you sure it's wise to simply insert another buffer into the X_CDirectSoundBuffer and Stream classes? I thought those had to be properly aligned according to the Xbox version. Could be wrong, but that was my assumption.
Shogun
I was doing it real-time decode it while it is still locked. If you complied and tried it out with tested games, there's no issue with it. Except major issue with dashboard is making static noise in background (I believe it is OOPVA signature is incorrect for it but I'm not sure).
Concurrency between threads competing for a resource may cause issues too, so perhaps adding locks in all the right places could help.
As for OOVPA - is a bit cumbersome to maintain them, but it's not all that complicated. Just search for the symbol in the patterns archive included with the Dxbx project here in GitHub, and convert the resulting stretch of bytes into an OOVPA structure (look at others for an example). Register the OOVPA in all applicable HLE database versions for it to be used.
FYI: http://xboxdevwiki.net/Xbox_ADPCM
You might want to link that from your source so people know what's going on.
I'm still extending the article (and will test the APU HW decoder, but results will probably go into the APU article).
(I'd also appreciate it if you create an article on the wiki next time you work on something so we can all benefit from your research 😄 - even if it's just collecting links to elsewhere)
@JayFoxRox thanks for all the hard work on this documentation, I personally also keep an eye on the code you're writing. Good work all around. As for documenting the stuff we discover, most is still largely HLE related, reverse engineering DMA initialization and that sort of stuff, which is probably already emulated well enough in both xqemu and MAME. But I'll remember to document things once I've got something solid to contribute
Hi @JayFoxRox, I am progressively doing the HLE audio support in my fork. You can find it in this link. I noticed you are doing XADPCM decoder in C language in your xbox tool branch, I am quite interesting to see it to be finalize. 😃 Can you let me know when it is done? Thanks.
@RadWolfie Can you either list what issues are still left to be done, or close this issue otherwise?
We do need optimized and accurate IMA ADCPM decoder to make the sound better and less popping for certain titles.
Since XADPCM decoder support is included in master branch, there's no reason to keep this issue open. Please do close it.
@RadWolfie Could you create an issue, describing in detail which steps are still needed to get an "optimized and accurate IMA ADCPM decoder"?
Most helpful comment
Sorry it's been a while @RadWolfie , frantically looking for a job right now so I almost forgot to share this
https://pastebin.com/VXqcZneJ - EmuDSoundXbAdpcm.cpp
https://pastebin.com/HCrYDpP9 - EmuDSound.cpp (mine)
I hardly get much time to fiddle with Cxbx because of the nature of contracting, but this is my result of a weekend's worth of work on the Xbox ADPCM stuff.
Shogun