Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change FFDShow DPL2 decoder to FreeSurround #5235

Merged
merged 5 commits into from
Feb 14, 2019

Conversation

LAGonauta
Copy link
Contributor

@LAGonauta LAGonauta commented Apr 9, 2017

Added the FreeSurround decoder to the mixer, and removed the legacy FFDShow decoder.
The decoding is done through the new SurroundDecoder class using a FixedSizeQueue as a ring buffer as the decoder needs a fixed amount of frames to be able to decode the surround information.

Tested on XAudio2 (with PR #6171), OpenAL, and Cubeb on Windows.
Also tested on OpenAL, Cubeb, and PulseAudio on Ubuntu, but Cubeb seems to be downmixing the surround information to stereo. Works on Windows, so maybe there is a bug in Cubeb library associated with Linux.

The upmix works really well, but I am not sure if we should set SURROUND_BLOCK_SIZE to 1024, 512, or even 256. All work, but the algorithm has more quality with 1024, less steering glitches and less crosstalk. For now I set it to 512 for an OK mix of quality and latency. The best quality is with SURROUND_FRAMES_PER_CALL set to 4096, but the latency seems to be equivalent to time-stretching with a buffer size of 80 ms.

Fixes bug #9047.

The new decoder seems to have some kind of incompatibility with some distros (Ubuntu 16.04, for example) as it causes glitches on decode. I will investigate the glitches later.
It seems that a fully updated Ubuntu 16.04 distro does not show this behaviour anymore.

Any suggestion is greatly appreciated :)

@lioncash
Copy link
Member

lioncash commented Apr 9, 2017

All of this external library code should likely be placed into Externals, rather than AudioCommon, especially the FreeSurround stuff.

@LAGonauta LAGonauta changed the title Changed FFDShow DPL2 decoder to FreeSurround. Change FFDShow DPL2 decoder to FreeSurround Apr 9, 2017
@LAGonauta
Copy link
Contributor Author

Just moved everything to Externals.

@Orphis
Copy link
Member

Orphis commented Apr 9, 2017

Where is the CMakeLists.txt for non-Visual Studio platforms?

CMakeLists.txt Outdated
endif()
message(STATUS "Using static FreeSurround from Externals")
add_subdirectory(Externals/FreeSurround)
include_directories(Externals)

This comment was marked as off-topic.

FreeSurroundDecoder.cpp
)

add_library(FreeSurround STATIC ${SRCS})

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@LAGonauta LAGonauta force-pushed the fs-dplii-decoder branch 2 times, most recently from c834012 to 02d066e Compare April 11, 2017 19:03
@LAGonauta
Copy link
Contributor Author

I noticed that I had forgotten to update the References on the Debug build for Visual Studio. Now everything should compile fine there.

I am doing experiments on padding the values to not only be able to use SoundTouch but also to allow its use on other backends. I noticed that PulseAudio, for example, rarely returns the desired 512 samples, it oscillates over it (505-520).
Sadly still no go, you can see my "progress" here: https://github.com/LAGonauta/dolphin/tree/fs-buffer-tests

Even though some days ago SoundTouch had horrible latency when forcing the output of 512 samples (for me), I found out the latency is bearable when changing the default periods and period size on OpenAL Soft's config file to small numbers like 3 and 128, respectively. Maybe on the OpenAL backend we can just do that? Personally I prefer to use OpenAL's frequency-shifter.

@LAGonauta LAGonauta force-pushed the fs-dplii-decoder branch 2 times, most recently from f37f0e1 to 1f0aaa4 Compare April 13, 2017 00:41
@LAGonauta
Copy link
Contributor Author

Just rebased this PR with the changes from merry's audio-stretching PR.
Now just need to find a way to make the buildbot not get stuck while trying to compile...

@BhaaLseN
Copy link
Member

Nothing you can do on your end, buildbot has a size limit on patches it can receive, and it seems our monkey-patch for that got lost in the upgrade. delroth knows, but he's on vacation and probably won't work on it until he's back.

CMakeLists.txt Outdated
@@ -650,6 +650,10 @@ else()
endif()

find_package(OpenAL)
if(OPENAL_FOUND)

This comment was marked as off-topic.

This comment was marked as off-topic.

@LAGonauta LAGonauta force-pushed the fs-dplii-decoder branch 3 times, most recently from 418cf32 to e6b3785 Compare May 9, 2017 23:40

add_library(FreeSurround STATIC ${SRCS})
target_include_directories(FreeSurround PUBLIC include)
add_definitions(-w)

This comment was marked as off-topic.

source/KissFFT.cpp
source/KissFFTR.cpp
source/FreeSurroundDecoder.cpp
)

This comment was marked as off-topic.

@LAGonauta LAGonauta force-pushed the fs-dplii-decoder branch 2 times, most recently from 4af908b to 8742ff6 Compare May 28, 2017 23:20
@LAGonauta
Copy link
Contributor Author

Just rebased because of Cubeb. I will also try to add support for FreeSurround on Cubeb, but right now it is not respecting how many frames I ask for.

@ligfx
Copy link
Contributor

ligfx commented Jun 5, 2017

@LAGonauta I said a few things on IRC before I realized you were gone :)

ligfx 7:11pm: LAGonauta does it alway ask for exactly 480 frames? is there maybe one callback at the beginning that asks for the full amount you requested (512)?
ligfx 7:13pm: I'm thinking it might be correctly honoring the request for a larger buffer, but then the callbacks get scheduled at the same time as the audio engine (every 480 frames), which leaves 32 frames unread / only 480 writable frames

<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Lib>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -78,6 +88,9 @@
<ProjectReference Include="$(CoreDir)Common\Common.vcxproj">
<Project>{2e6c348c-c75c-4d94-8d1e-9c1fcbf3efe4}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\Externals\FreeSurround\FreeSurround.vcxproj">

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -35,6 +35,16 @@
<Import Project="..\..\VSProps\PCHUse.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<AdditionalIncludeDirectories>$(ExternalsDir)FreeSurround\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

This comment was marked as off-topic.

This comment was marked as off-topic.

@LAGonauta
Copy link
Contributor Author

@ligfx No, the first callback asks for 960 frames while all other callback asks for 480 (may depend on the CPU usage, I guess). No callback ever asks for 512 frames.

@LAGonauta
Copy link
Contributor Author

Anything I can do to make this PR move forward for merge?

@LAGonauta
Copy link
Contributor Author

After extensive testing I found that it is still needed to clamp some rare samples depending on the game, re-added that function for better user experience.

Also rebased the branch to the current master.

@LAGonauta
Copy link
Contributor Author

Recently had the time try to find out what caused the glitches on Ubuntu 16.04 and they seem to have been fixed when using a fully updated distro. Yay! I guess?

@LAGonauta
Copy link
Contributor Author

@lioncash @JMC47 @ligfx @shuffle2
Anything I can do to make this PR move forward?

@shuffle2
Copy link
Contributor

This PR seems fine to me, tbh my guess would be that people aren't merging it just because not many people have a way to test it...

@weihuoya
Copy link
Contributor

it's work fine on android, thx.

@DanLaRoche
Copy link

It's a shame that the reviewers are ignoring this PR, some of us would love to get surround sound working correctly without having to rely on inconsistent pro logic support on modern HTIB systems and sound bars. In the meantime, LAGonauta, could you do a pull from master to keep your fork up to date? I'll be testing this soon on my HTPC that is connected to a surround sound system.

@LAGonauta
Copy link
Contributor Author

@DanLaRoche Just rebased and pushed.
Remember to use Cubeb or OpenAL on Windows and PulseAudio on Linux. Other backends do not support surround sound yet.

@stenzek
Copy link
Contributor

stenzek commented Jan 30, 2019

The code seems fine to me, aside from a few small nitpicks (e.g. replace the clamping by if/else with MathUtil::Clamp). But I'm not very familiar with the audio side of Dolphin, so I'm probably not the best person to review it.

But it's a shame for this to be sitting around, so unless anyone has any better ideas, I could merge it as-is and deal with any regressions later.

@ghost
Copy link

ghost commented Feb 8, 2019

@LAGonauta Needs another rebase. I have a 5.1 setup my self and I'm sad at the gaming/PC HW audio industry, audio is extremely underappreciated in general, so my hat off for this PR.

Also cleaned up its source code to support only 5.1 and 7.1 setups.
Added class in AudioCommon for the surround decoder
Also removed minimum number of frames needed when decoding DPL2, and use
std::numeric_limits to clamp the samples when needed.

Clamping is still needed, but those samples are much rarer now and depend
on the game.
@LAGonauta
Copy link
Contributor Author

@ghost
Just rebased.

Copy link
Contributor

@stenzek stenzek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this has been tested, and so far there's no objections to it being merged as-is. Had a quick look through the code again and can't see any major issues.

@stenzek stenzek merged commit 326d727 into dolphin-emu:master Feb 14, 2019
@retrue
Copy link

retrue commented Feb 14, 2019

Hi
I have noticed problems with this change.
I am playing Resident Evil 4, with Surround activated. Before this pull request, sound was perfect. Now, it is choppy. If I disable Dolby Pro Logic II Decoder in Sound Settings, the sound is clean again.
My computer; i7 4770, 16 GB RAM, Nvidia 1060 6GB, SSD. Integrated sound chip Realtek High Definition Audio. OS, Windows 10 Pro 64bit.
My sound settings, in the image.
soundconfigdolby

@retrue
Copy link

retrue commented Feb 14, 2019

Hi, I have made more tests. With the above settings, using HLE and LLE Interpreter I get bad sound too.
If I disable Audio Stretching with Dolby Pro Logic enabled, sound is much better, but not so good as before this PR.

@LAGonauta LAGonauta deleted the fs-dplii-decoder branch February 16, 2019 09:44
@LAGonauta
Copy link
Contributor Author

Investigated a little bit and it seems this is happening and it seems that the non-uniform number of samples output from SoundTouch might be doing that... I need to investigate more.
However, what do you mean with not as good as before the PR without audio stretching? Is it stuttering for you? Or just different?
The older decoder did not really do any decoding, so with FreeSurround the sound placement will be really different.

@retrue
Copy link

retrue commented Feb 16, 2019

Hi
What I meant is that it seems FreeSurround and audio stretching are not working well together and produces bad sound.
If I disable audio stretching the audio improves a lot but there is a little bit of stuttering. My opinion (I can be wrong) is that you are simply losing the fluidity in the sound you would get with audio stretching enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet