We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3228

Summary: Regression: Bad/Crackling audio with pcsx2 (spu2x) using pulseaudio since 2.0.4
Product: SDL Reporter: zilla
Component: audioAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED ABANDONED QA Contact: Ryan C. Gordon <icculus>
Severity: blocker    
Priority: P2 CC: gregory.hainaut, philipp.wiesemann, slouken
Version: 2.0.4Keywords: target-2.0.6
Hardware: x86_64   
OS: Linux   
Attachments: screenshot of spu2-x settings

Description zilla 2016-01-09 10:28:03 UTC
Created attachment 2359 [details]
screenshot of spu2-x settings

Probably this will be for Ryan :)

Description/context: pcsx2 uses a plugin system, the plugin for sound is spu2x. The plugin uses SDL2. When using pulseaudio backend in SDL2, the sound is very bad (sound artefacts / crackling) since 2.0.4. If I switch to alsa backend, sound is fine. If I reinstall 2.0.3 lib32-sdl2 then sound is fine, as before, even when using the pulseaudio backend.

Reproduce: Not sure if it's system specific, but (assuming one is familiar with pcsx2) all you have to do is configure spu2x to use SDL audio & pulseaudio backend. I'll add a screenshot of the spu2x settings menu. The crackling is noticeable even from the bootup of the PS2 bios, so it's not game specific. I'm using PCSX2 built from git (1.3.1-20160105063026).

I tried to narrow it down a bit, reverse patching from 2.0.4 source and recompiling SDL2 but alas I didn't get very far, probably because I'm not familiar with Mercurial and didn't know exactly what patches or patchsets to use. I'm no programmer but if you have patches for me to test, I'll be glad to try them out!

--- System info ---

$ uname -r ; glxinfo | grep 'OpenGL version'
4.3.3-2-ARCH
OpenGL version string: 4.5.0 NVIDIA 358.16

$ sudo lshw -short
[sudo] password for x: 
H/W path         Device  Class       Description
================================================
                         system      P55-USB3
/0                       bus         P55-USB3
/0/0                     memory      128KiB BIOS
/0/4                     processor   Intel(R) Core(TM) i5 CPU         750  @ 2.67GHz
/0/4/a                   memory      64KiB L1 cache
/0/4/b                   memory      8MiB L2 cache
/0/1a                    memory      4GiB System Memory
/0/1a/0                  memory      2GiB DIMM 1520 MHz (0.7 ns)
/0/1a/1                  memory      DIMM [empty]
/0/1a/2                  memory      2GiB DIMM 1520 MHz (0.7 ns)
/0/1a/3                  memory      DIMM [empty]
/0/100                   bridge      Core Processor DMI
/0/100/3                 bridge      Core Processor PCI Express Root Port 1
/0/100/3/0               display     GF104 [GeForce GTX 460]
/0/100/3/0.1             multimedia  GF104 High Definition Audio Controller
/0/100/8                 generic     Core Processor System Management Registers
/0/100/8.1               generic     Core Processor Semaphore and Scratchpad Registers
/0/100/8.2               generic     Core Processor System Control and Status Registers
/0/100/8.3               generic     Core Processor Miscellaneous Registers
/0/100/10                generic     Core Processor QPI Link
/0/100/10.1              generic     Core Processor QPI Routing and Protocol Registers
/0/100/1a                bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1a/1      usb1    bus         UHCI Host Controller
/0/100/1a/1/2            input       USB Keyboard
/0/100/1a.1              bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1a.1/1    usb2    bus         UHCI Host Controller
/0/100/1a.2              bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1a.2/1    usb3    bus         UHCI Host Controller
/0/100/1a.2/1/1          input       Xornet gaming mouse
/0/100/1a.7              bus         5 Series/3400 Series Chipset USB2 Enhanced Host Controller
/0/100/1a.7/1    usb7    bus         EHCI Host Controller
/0/100/1a.7/1/4          multimedia  Webcam C270
/0/100/1b                multimedia  5 Series/3400 Series Chipset High Definition Audio
/0/100/1c                bridge      5 Series/3400 Series Chipset PCI Express Root Port 1
/0/100/1c/0              storage     JMB363 SATA/IDE Controller
/0/100/1c/0.1            storage     JMB363 SATA/IDE Controller
/0/100/1c.1              bridge      5 Series/3400 Series Chipset PCI Express Root Port 2
/0/100/1c.1/0    enp3s0  network     RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
/0/100/1c.2              bridge      5 Series/3400 Series Chipset PCI Express Root Port 3
/0/100/1c.2/0            bus         uPD720200 USB 3.0 Host Controller
/0/100/1c.2/0/0  usb6    bus         xHCI Host Controller
/0/100/1c.2/0/1  usb5    bus         xHCI Host Controller
/0/100/1d                bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1d/1      usb4    bus         UHCI Host Controller
/0/100/1d/1/2            generic     Xbox 360 Wireless Receiver for Windows
/0/100/1d.1              bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1d.1/1    usb9    bus         UHCI Host Controller
/0/100/1d.2              bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1d.2/1    usb10   bus         UHCI Host Controller
/0/100/1d.3              bus         5 Series/3400 Series Chipset USB Universal Host Controller
/0/100/1d.3/1    usb11   bus         UHCI Host Controller
/0/100/1d.7              bus         5 Series/3400 Series Chipset USB2 Enhanced Host Controller
/0/100/1d.7/1    usb8    bus         EHCI Host Controller
/0/100/1e                bridge      82801 PCI Bridge
/0/100/1f                bridge      5 Series Chipset LPC Interface Controller
/0/100/1f.2              storage     5 Series/3400 Series Chipset 6 port SATA AHCI Controller
/0/100/1f.3              bus         5 Series/3400 Series Chipset SMBus Controller
/0/101                   bridge      Core Processor QuickPath Architecture Generic Non-Core Registers
/0/102                   bridge      Core Processor QuickPath Architecture System Address Decoder
/0/103                   bridge      Core Processor QPI Link 0
/0/104                   bridge      Core Processor QPI Physical 0
/0/105                   bridge      Core Processor Integrated Memory Controller
/0/106                   bridge      Core Processor Integrated Memory Controller Target Address Decoder
/0/107                   bridge      Core Processor Integrated Memory Controller Test Registers
/0/108                   bridge      Core Processor Integrated Memory Controller Channel 0 Control Registers
/0/109                   bridge      Core Processor Integrated Memory Controller Channel 0 Address Registers
/0/10a                   bridge      Core Processor Integrated Memory Controller Channel 0 Rank Registers
/0/10b                   bridge      Core Processor Integrated Memory Controller Channel 0 Thermal Control Registers
/0/10c                   bridge      Core Processor Integrated Memory Controller Channel 1 Control Registers
/0/10d                   bridge      Core Processor Integrated Memory Controller Channel 1 Address Registers
/0/10e                   bridge      Core Processor Integrated Memory Controller Channel 1 Rank Registers
/0/10f                   bridge      Core Processor Integrated Memory Controller Channel 1 Thermal Control Registers
Comment 1 zilla 2016-01-11 13:27:53 UTC
Additional info: 

Here is the relevant code in PCSX2:

https://github.com/PCSX2/pcsx2/blob/master/plugins/spu2-x/src/SndOut_SDL.cpp
Comment 2 zilla 2016-01-24 12:12:31 UTC
We are trying to debug this, with regards to behaviour change in 2.0.3 vs 2.0.4 and a question has come up by one of the PCSX2 devs:

"User requests a 1024 samples of 16 bits on 2 channel. Therefore a sample frame is sizeof(u16) * 2 = 4.

But the len of callback buffer is only 2048. And therefore it could only contain 2048/4=512 samples instead of the 1024 requested.

I just want to know if it is done on purpose or if it's a not-expected side effect of another change?"

Could you give us some insight in this? Thank you.
Comment 3 zilla 2016-01-24 15:03:56 UTC
More on this @ https://github.com/PCSX2/pcsx2/issues/1095

Specifically:

"So the bug (probably) is (2.0.4):

id = open_audio_device(NULL, 0, desired, NULL, 0, 1);

and 2.0.3:

id = open_audio_device(NULL, 0, desired, desired, 0, 1);

So it is better to use obtained in PCSX2, because 2.0.4 has a bug (or 2.0.4 doc has a bug)..."
Comment 4 Philipp Wiesemann 2016-01-24 16:28:07 UTC
See bug #2467 for this change.
Comment 5 gregory.hainaut 2016-01-24 17:14:14 UTC
Hello,

I understand this change was done to correct a bug but it introduces a change on the API.

Quoting the wiki (I don't know if it is the official doc)
https://wiki.libsdl.org/SDL_OpenAudio?highlight=%28\bCategoryAPI\b%29|%28SDLFunctionTemplate%29

Section: Return Value
   If obtained is NULL, ...... If obtained is NULL, *desired will have fields modified*.


I think, we will rewrite the code to avoid this pitfall in the future. But it is annoying for already released version. And it might impact others project too.
Comment 6 Ryan C. Gordon 2017-08-13 04:23:43 UTC
> If obtained is NULL, *desired will have fields modified*.

This phrase is bad in the wiki, but it does explain later on the page that it will only update fields like "silence" to be correct, and not actually change anything about the requested format. The intention was and always will be that if you specify "obtained" as NULL, you're saying "I _must_ get the format requested in 'desired' because I can't handle anything but that format, so if you can't give me that format, pretend you did and have SDL convert for me transparently."

I have to look at the code to see if we're failing to do it this way, but that's the idea.

--ryan.
Comment 7 Ryan C. Gordon 2017-08-13 19:56:03 UTC
I'm not marking it as a duplicate yet, but Bug #3749 is probably also a victim of this confusion.

--ryan.
Comment 8 Ryan C. Gordon 2017-08-13 20:47:18 UTC
> I'm not marking it as a duplicate yet, but Bug #3749 is probably also a
> victim of this confusion.

Also Bug #3710.

--ryan.
Comment 9 gregory.hainaut 2017-08-14 19:05:19 UTC
Hello,

> you're saying "I _must_ get the format requested in 'desired' because
> I can't handle anything but that format, so if you can't give me that
> format, pretend you did and have SDL convert for me transparently."

Yes it makes sense. It would be nice to update the wiki to state clearly the behavior of "NULL obtained" and which field is updated.

I think the confusion also came from SDL 2.0.3 which updated all desired field value.
Comment 10 Ryan C. Gordon 2018-08-06 21:20:21 UTC
Hello, and sorry if you're getting dozens of copies of this message by email.

We are closing out bugs that appear to be abandoned in some form. This can happen for lots of reasons: we couldn't reproduce it, conversation faded out, the bug was noted as fixed in a comment but we forgot to mark it resolved, the report is good but the fix is impractical, we fixed it a long time ago without realizing there was an associated report, etc.

Individually, any of these bugs might have a better resolution (such as WONTFIX or WORKSFORME or INVALID) but we've added a new resolution of ABANDONED to make this easily searchable and make it clear that it's not necessarily unreasonable to revive a given bug report.

So if this bug is still a going concern and you feel it should still be open: please feel free to reopen it! But unless you respond, we'd like to consider these bugs closed, as many of them are several years old and overwhelming our ability to prioritize recent issues.

(please note that hundred of bug reports were sorted through here, so we apologize for any human error. Just reopen the bug in that case!)

Thanks,
--ryan.