chrislo27 / PolyrhythmMania

A game that faithfully recreates the Polyrhythm minigame from Rhythm Tengoku (リズム天国), with a built-in level editor
https://polyrhythmmania.rhre.dev
GNU General Public License v3.0
237 stars 18 forks source link

[Bug]: LineUnavailableException when going from main menu to in-game #42

Closed chrislo27 closed 2 years ago

chrislo27 commented 2 years ago

Version

v1.1.1

Operating System

Linux

Problem Description

Unable to hear in-game (Polyrhythm gameplay) sounds when playing. A LineUnavailableException occurs while loading.

Steps to Reproduce Problem

  1. Load a Polyrhythm level or Endless Mode.
  2. Note that there is no game audio.
  3. Exit to main menu. Normal sounds are back.
  4. Note that some menu sounds (button noises) still play normally.

Relevant log output

==============
AUTO-GENERATED
==============

Program Specifications:
    Launch arguments: []
    Version: v1.1.2-beta_20220103a
    Application type: Desktop
    LazySound loading enabled: true

System Specifications:
    Java Version: 17.0.1
    Java Vendor: N/A
    Kotlin Version: 1.5.31
    OS Name: Linux
    OS Version: 5.15.5-223-tkg-bmq
    OS Arch: amd64
    JVM memory available: 1048576 KiB

Graphics Specifications:
    Resolution: 1280x720
    Fullscreen: false
    GL_VENDOR: X.Org
    GL_RENDERER: AMD CEDAR (DRM 2.50.0 / 5.15.5-223-tkg-bmq, LLVM 14.0.0)
    GL_VERSION: 3.1 Mesa 22.0.0-devel (git-145b0711fc)
00:00:15.342: [INFO][main] Settings persisted
00:00:19.704: [INFO][Library Search] Starting Library search in /home/e404nnf/.polyrhythmmania/Levels
00:00:19.705: [INFO][Library Search] [Library Search] Possible files found: 5
00:00:19.739: [INFO][Library Search] [Library Search] Levels read: 5 (took 34.32304 ms)
00:00:31.847: [DEBUG][main] Changed screens from polyrhythmmania.screen.mainmenu.MainMenuScreen to paintbox.transition.TransitionScreen
00:00:00.546: [INFO][main] Initialized all 8 fonts in 0.023835 ms
00:00:00.596: [INFO][main] [Settings] Migrated old setting settings_onlyDefaultPalette, previously was false
00:00:00.640: [INFO][main] Attaching to mixer from settings: Generic [plughw:1,0]
00:00:00.646: [DEBUG][main] Changed screens from null to polyrhythmmania.init.AssetRegistryLoadingScreen
00:00:00.793: [INFO][main] [DiscordCore] Loaded successfully.
00:00:01.377: [INFO][GitHub version checker] Got version from server: v1.1.1
00:00:01.431: [INFO][main] Supported mixer: HDMI [plughw:0,3]
00:00:01.431: [INFO][main] Supported mixer: Generic [plughw:1,0]
00:00:01.512: [DEBUG][Main Menu music decoder] Starting main menu music decode
00:00:01.516: [DEBUG][main] Updated main menu framebuffers to be backbuffer 1600x900 (logical 1600x900)
00:00:01.540: [DEBUG][main] Changed screens from polyrhythmmania.init.AssetRegistryLoadingScreen to paintbox.transition.TransitionScreen
00:00:01.951: [DEBUG][main] Changed screens from paintbox.transition.TransitionScreen to polyrhythmmania.screen.mainmenu.MainMenuScreen
00:00:02.194: [DEBUG][main] Updated main menu framebuffers to be backbuffer 1280x720 (logical 1280x720)
00:00:02.449: [DEBUG][Main Menu music decoder] Finished main menu music decode
Exception in thread "DaemonJavaSoundAudioIO" javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian not supported.
    at java.desktop/com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:484)
    at java.desktop/com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:115)
    at polyrhythmmania.soundsystem.beads.DaemonJavaSoundAudioIO.create(DaemonJavaSoundAudioIO.kt:62)
    at polyrhythmmania.soundsystem.beads.DaemonJavaSoundAudioIO.access$create(DaemonJavaSoundAudioIO.kt:23)
    at polyrhythmmania.soundsystem.beads.DaemonJavaSoundAudioIO$start$1.invoke(DaemonJavaSoundAudioIO.kt:170)
    at polyrhythmmania.soundsystem.beads.DaemonJavaSoundAudioIO$start$1.invoke(DaemonJavaSoundAudioIO.kt:169)
    at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
00:00:32.168: [DEBUG][main] Changed screens from paintbox.transition.TransitionScreen to polyrhythmmania.screen.PlayScreen
00:00:41.360: [INFO][main] Starting dispose call
00:00:41.364: [INFO][main] Dispose call finished, goodbye!

(Optional) Other useful information

This issue was split off from #41 created by @E404NNF.

From preliminary investigation, this is an edge case where exactly one line is permitted to be opened on the sound system. Most systems will allow more than one line to be open at a time. In certain cases in Polyrhythm Mania, more than one line is open at a time, such as during the loading transition from the main menu to gameplay, or in the editor when loading a project.

chrislo27 commented 2 years ago

The scope of this "bugfix" is much larger than I initially thought and I'd like to do it right. This fix is planned for the v1.2 feature version release and will have a significant internal audio overhaul to improve audio interfacing and to ensure only one line is used at a time by the entire game.

chrislo27 commented 2 years ago

The audio refactor is on branch audio_refactor and has already been merged into the v1.2 branch. The new default audio system will be "OpenAL", since that has the most compatibility. The legacy sound system (JavaSound-based) will still be available in v1.2, but will not be enabled by default and may be fully removed in a future release.

As an added bonus, the OpenAL audio system has less internal latency -- around 24ms (9 buffers of 128 samples each at 48kHz) down from 43ms (2 buffers of 1024 samples each, also at 48kHz). It also uses less CPU time processing (around 25% less).

The audio is still mixed as usual, but is output via OpenAL (libGDX's AudioDevice) instead of through JavaSound mixers.

Saraistupid commented 2 years ago

The switch to OpenAL fixes my issue #41 Though the main menu music and in-game music/audio is choppy, but I assume it's because this branch is probably still in development (or my game for some reason being laggy)

Question, will you also move RHRE3 to OpenAL?

chrislo27 commented 2 years ago

Though the main menu music and in-game music/audio is choppy

Thank you for testing; I would like to resolve this before the official release. Would you mind making a video demonstrating the problem? You can also try the launch parameter --audio-device-buffer-count and increasing from 9 to, say, 18, and see if that resolves your problem. Try finding the smallest value that produces the correct audio. Example of usage: java -jar PolyrhythmMania.jar --audio-device-buffer-count 18

Question, will you also move RHRE3 to OpenAL?

No, RHRE3 has not been in development since Oct 25, 2020 and will not receive future updates. Source

Saraistupid commented 2 years ago

here's a vid: https://cdn.discordapp.com/attachments/862760859318485032/929912149185265724/2022-01-10_03-35-11.mp4

for my RHRE3 question, yeah i know that the development stopped, i meant the next major revision or whatever you called it (if there's going to be one anyways), but thanks :D

btw, i don't seem to be able to compile the game, i tried what i usually do with gradle projects and use gradlew build but that just doesn't work


[e404nnf@ryzengf PolyrhythmMania-audio_refactor]$ ./gradlew :desktop:build
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* Where:
Build file '/home/e404nnf/PolyrhythmMania-audio_refactor/desktop/build.gradle' line: 40

* What went wrong:
Could not determine the dependencies of task ':desktop:jar'.
> Resolving dependency configuration 'implementation' is not allowed as it is defined as 'canBeResolved=false'.
  Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'implementation' should be resolved.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 610ms```
chrislo27 commented 2 years ago

Please use the v1.2 branch since the audio refactor branch has already been merged into it, I won't update the audio_refactor branch again. As for the Gradle compilation: try running ./gradlew :desktop:shadowJar instead since it packs all the dependencies into one jar file; this is the same as how I compile the release builds. I also pushed a commit to the v1.2 branch that should fix the :desktop:jar task not working -- but as I previously mentioned you should use the shadowJar task instead. You can find the fat-jar file in the desktop/build/libs/ directory and run it using java -jar.

Saraistupid commented 2 years ago

tried --audio-device-buffer-count, the smallest i could get to is 18 without audio sounding choppy or glitchy

chrislo27 commented 2 years ago

You can also tweak --audio-device-buffer-size. It starts at 512 and should be a power of two. I would recommend trying a buffer size of 1024 and keeping the buffer count at 9, then slowly decrementing the buffer count while keeping the 1024 buffer size. In this case the goal is to reduce audio latency while not having it be distorted.

I would like to try to find a decent set of parameters that works with the most people. The default values for the buffer size and count may be too small (they are libGDX defaults).

Saraistupid commented 2 years ago

the numbers you suggested 1024 and 9 give distorted audio, increasing buffer count to 10 with the buffer size staying at 1024 gives normal audio i tried decreasing the buffer size to 768, 13 buffer count was the lowest i could go to with that buffer size

chrislo27 commented 2 years ago

I've pushed some commits to the v1.2 branch that has improved advanced audio settings for tweaking the buffer count in-game. The default buffer count on Windows will be 6 and on other platforms it is 10. The default buffer size has also been raised to 1024 bytes. I opted not to add buffer size changes in the settings since that gets more complicated with respect to the sound system mixer.

As an aside, I tried tweaking the buffer settings on a Ubuntu 20.04 VM and found that a buffer count of 9 was the minimum for it to work stably -- note that it was on a VM so I would take its results with a grain of salt.