0 users browsing Emulation. | 2 guests | 1 bot  
Main » Emulation » Help wanted: Windows dynamic rate control support
Pages: 1
Posted on 19-04-03, 02:42
Burned-out Genius Developer
Post: #21 of 48
Since: 10-30-18

Last post: 221 days
Last view: 8 days
Pretty much the last major feature I've wanted for years but still can't pull off is DRC.

Thanks to BearOso's code, I was able to manage this for OSS on FreeBSD. But that's a pretty niche OS. I'd really like to get this into bsnes on Windows.

I attempted the same with XAudio2, but it failed:
https://gitlab.com/higan/higan/blob/master/ruby/audio/xaudio2.cpp#L55

Talarubi gave debugging it hir all, but it would appear that the issue is XAudio2 has a minimum buffer size that is too large, and requesting a smaller size just gives you a larger buffer anyway. I don't know how to square that away with Snes9X purportedly supporting DRC with XAudio2, but maybe it's due to emulation core differences.

I saw that Snes9X recently implemented DRC through waveOut to avoid the limitations of DirectSound and DRC, so I tried the same:
https://gitlab.com/higan/higan/blob/master/ruby/audio/waveout.cpp

But unfortunately, I'm at a loss as to how Snes9X is implementing its DRC through their driver. Specifically, I'm not sure how to create the required level() function in the waveOut driver.

With any luck, it'll only be five or six lines of code. Would anyone with some spare time be up for lending a hand with this?
Posted on 19-04-03, 16:03
Post: #19 of 58
Since: 10-29-18

Last post: 25 days
Last view: 1 day
Is it possible you're overthinking it? It shouldn't matter how small the buffer is, AFAIK, just whether it's more than half-full or less than half-empty.

That is, since you already have your resampler, you just need to specify a "max timing skew" (how much you're going to resample up or down; 0.005 is the default in RetroArch) and then check your buffer on each frame. Is it more than half full? resample down. Is it less than half-empty? resample up.

Disclaimer: I've never implemented it myself, but I've spoken with themaister about it conceptually many times.
Posted on 19-04-04, 03:24 (revision 1)

Post: #68 of 158
Since: 10-30-18

Last post: 1 day
Last view: 11 hours
I think the level function should just be ((blockQueue * frameCount) + frameIndex) / (blockCount * frameCount)

You could try filling the buffer halfway with silence when detecting it’s empty (on initialization and underruns).

*edit*
It looks like you’ve inverted the level in the xaudio driver. In the OSS level is reporting % filled, but xaudio is reporting % empty.
Posted on 19-04-05, 19:41

Post: #69 of 158
Since: 10-30-18

Last post: 1 day
Last view: 11 hours
Something like this should work for XAudio2:
  auto level() -> double override {
XAUDIO2_VOICE_STATE state{};
self.sourceVoice->GetState(&state);
uint level = state.BuffersQueued * self.period + self.buffers[self.index].size() - state.SamplesPlayed % self.period;
uint limit = Buffers * self.period;
return (double)level / limit;
}
and this for WaveOut:
  auto level() -> double override {
return (double)((blockQueue * frameCount) + frameIndex) / (blockCount * frameCount);
}
Posted on 19-04-06, 05:17
Burned-out Genius Developer
Post: #22 of 48
Since: 10-30-18

Last post: 221 days
Last view: 8 days
Oh no, my naming choice came back to bite me.

I should have named the functions available() or remaining() to avoid inverting what they return and not realizing it.

Thank you so, so much! ^-^ I will test this out and report back.
Posted on 19-04-09, 09:38
Burned-out Genius Developer
Post: #23 of 48
Since: 10-30-18

Last post: 221 days
Last view: 8 days
It turns out I can't test XAudio 2.1 because it's just not available on Windows 10.

But for waveOut, I had to patch the processing code around a bit, and increase the buffer count, but ...... it works!! :D

Hooray, thank you so much!!
Posted on 19-04-09, 09:57
Custom title here

Post: #395 of 866
Since: 10-30-18

Last post: 1 day
Last view: 6 hours
Hooray!

--- In UTF-16, where available. ---
Posted on 19-04-12, 02:38
Post: #4 of 6
Since: 10-31-18

Last post: 254 days
Last view: 2 days
Posted by byuu
It turns out I can't test XAudio 2.1
Does the DirectX SDK for XAudio 2.7 not install on Windows 10 any more?

If it really doesn't, then maybe my 6 year old patch to xaudio2.hpp and ruby makefile to make it use XAudio 2.8 (the Windows 8 version that your Windows 10 should definitely already have) instead is finally of some use to you, just to let you be able to test it.

https://helmet.kafuka.org/byuubackup/viewtopic.php@f=3&t=3633.html long post most of the way down that link. Yes, that's the older archive, that's how old that is.
Posted on 19-04-12, 06:23
Post: #182 of 353
Since: 10-30-18

Last post: 46 min.
Last view: 46 min.
User is online
I believe he wants XAudio v2.1 to retain support for Windows 7, Vista and maybe XP. Newer versions are restricted to Windows 8 and newer. Byuu, during your current installation of the O/S have you run the DirectX Web Updater? It installs a bunch of stuff that the June 2010 Redistributable Package doesn't.

AMD Ryzen 3700X | MSI Gamer Geforce 1070Ti 8GB | 16GB 3600MHz DDR4 RAM | ASUS Crosshair VIII Hero (WiFi) Motherboard | Windows 10 x64
Posted on 19-04-12, 16:40
Burned-out Genius Developer
Post: #28 of 48
Since: 10-30-18

Last post: 221 days
Last view: 8 days
I specifically want to maintain Windows 7 support.

I realize its days are numbered, but a lot of people (including myself) dislike Windows 10.

If we can offer 2.1 and 2.8 simultaneously, with 2.8 simply not being available on 7, that could work.

Then again, waveOut, DirectSound, and XAudio2 all use the same backend anyway. There's not really a lot of point to using XAudio when waveOut is perfectly fine.

Microsoft, like me, just likes to keep reinventing things constantly.
Pages: 1
Main » Emulation » Help wanted: Windows dynamic rate control support
Yes, it's an ad.