TinySound stutter & pop


I have recently added the option to use TinySound instead of my own sound-system in my game because I couldn’t get sound to work right on Linux (because of limitations of how many lines can be open at the same time on Linux? I think?) anyway my own system works fine on Windows but to make my game available for Linux there’s now the option to use TinySound. However TinySound seems to have a big drawback that my system doesn’t seem to have: When there’s a lot of processing (or maybe because of Garbage collection pauses (not sure)) TinySound music occasionally stutters for a moment or pops. It also seems to happen just randomly occasionally (I’m guessing because of garbage collection). I use the ParallelGC garbage-collector. And for the music and looping sounds I use TinySound non-streaming version of music (MemMusic?).

Is this just something you have to live with, with TinySound or anybody any insight of what could be wrong?

I’ve not heard of complaints about TinySound on Linux. AFAIK, it is pretty solid.

Could you say something about how many and what type of sounds you are playing at once and if they are compressed or not?

Since there are dropouts, maybe try giving your sound thread MAX_PRIORITY. The cycles needed to process audio are usually far quicker than the time needed to play it, so the thread spends most of its time in a blocked state. Even with a priority level of 10, the cpu usually has enough time to handle the rest of the game.

You are welcome to try AudioCue as a work-around. I am staying active here at java-gaming.org and will be available (and motivated!) to work with you if problems arise.


You can use Paul Lamb 3D Sound System, it has several plug-ins including one relying on Java Sound and another one relying on JOAL.

Hi gouessej I just finished integrating Tinysound into my game so I don’t have the morale at the moment to now try and integrate another one but thanks for the tip anyway. Maybe in a few months I will give it try.

There are others who experience it just search “tinysound linux crackle” on google. I’m playing a music track and an engine sound and sometimes an ambient sound. Then there’s all kinds of little sounds like for buttons or certain events that occur throughout the game. All come from .wav files. Looking at the Tinysound source it already does it’s thing on a MAX_PRIORITY Thread.
Anyway, as with the above I’m a bit run-down on the whole getting the Linux version to work at the moment so thanks for the suggestion of using AudioCue. Maybe once I get my motivation for this back I will look at it.

Thanks a lot for the replies!

hmmm, AudioCue does look actually like the one I wanted to use but I couldn’t find it anymore for some reason. I had this idea of using a library for over a year but couldn’t remember what the library was called. All I could find in my browsing history was tinysound but it didn’t mention putting separate playbacks through as single mixer. So I was like: “Hmm must have made that up” and started using Tinysound. Now I see audiocue has that line about consolidating several cues through on single mixer…I think that’s actually the one I was thinking of.
Anyway I’m a bit done with the linux and audio for probably a good while. It was a real pain in the ass to me (build, character-encoding, file-permissions and a million other little things) and it probably will give me hardly any extra sales but a lot more support tickets. :stuck_out_tongue:

I detect a note of exhaustion in your post, but I am also quite curious if AudioCue can handle your needs.

Would you be interested in sending me the source for your sound handling? Or a copy of the cues you are playing and a list of the commands used to control them? I’d like to try recoding/executing them with AudioCue and testing on my Ubunto 18.04 desktop (has an older 6-core AMD cpu). Would be happy to send back any working code that results.

I understand reluctance if modifications would cost you a bunch of trouble due to having to repackaging your Linux distribution.

I’m game to help out if it can happen in the next few days. But I may get really busy by early-mid April, so I’d like to jump in sooner rather than later if you are willing. Can talk logistic on JGO messaging.

Just a heads up but under Linux, Java thread priorities have no actual effect, by default.

Cas :slight_smile:

Yeh, I am a bit exhausted because I was going to work on more content last week but then one night I decided to lookup “that sound-library” I had considered about a year ago and found Tinysound. Then after only an hour of work I had it pretty much integrated into my game where I can simply switch between using different sound-systems by a configuration-file setting. (I basically wrapped Java Clip in my own Clip interface MClip and have different implementation depending on whether you wrap Tinysound Music, Sound or a Java Clip. It ran fine on Windows.
Anyway that prompted me to seriously go for making my game available on Linux (because the sound problems were what kept me away from it). But originally I wasn’t going to do this now but work on content instead. The build threw up a couple of days worth of it’s own little but time consuming nags (e.g. character encoding stuff (ISO-8859-1 -> UTF-8)), zip files that can’t keep permissions on files so I couldn’t set my main game file to be executable if I publish it as a zip file (which seems to be what’s done on Itch.io), etc., etc.
It was all kind of annoying and time consuming. Every time I thought I was done, something popped up. So then I started to notice this stuff with the sound and tried all kinds of work-arounds and fixes.

So now I’m getting a bit tired of it, having spend 7 days on this thing that I shouldn’t really be working on because it probably will do little for sales and more for bug reports (let alone potentially breaking something for the Windows crowd who already had working sound).

Of course like most of us here probably: I can’t let it go now… So, for some reason whenever I start the game and use Tinysound the first while sound crackles and pops. After a while it goes away. I noticed it does seem to coincide with the delta-time in Tinysound’s UpdateRunner.run() to be larger (e.g. > 4ms). During development I have, in my game, the ‘G’ key invoke “System.gc()”, it’s just for testing things or figuring out roughly where the problem of something lies. So the crackle can go on for quite a while but if I invoke the garbage-collector (by pressing ‘G’) it is always immediately gone.
It can popup later again and seems to coincide with when the game is doing a lot of work. After a lot of thinkering last night I’ve now noticed that if I call flush() on the outLine (in UpdateRunner.run()) whenever outLine.available() returns 0. It does stop the crackle: You will still hear one or two crackles initially but then it stops. Same with it happening in the middle of the game, you hear it a bit but then it quickly stops so it is by far less annoying. I could live with some crackle in the Linux version and I guess Linux users would just have to live with it (I’ll make it clear before they buy the thing that the sound possibly has some crackle sometimes).

Very kind of you @philfrei to offer to help me but I don’t have the energy to make use of your kind offer at the moment. I’ll think about it but probably will just go with what I’ve got. Once I have it up on itch.io I can send you a free key if you want and you can see what it does on your Linux system (I’m on Ubuntu 18.04 myself).

EDIT: If you want I can send you some of the source that pertains to the sound and some of the sound-files (*.wav) I use. Just let me know how to send them.

Thanks for the heads-up about the Thread priorities.

Just for those still following this: Doing outLine.flush() in UpdateRunner.run() when outLIne.available() returns zero doesn’t work.
The results seem to vary over time. For example at the moment I now have delayed sound when using TinySound…there seems to be rime nor reason to it.

Interesting to hear what you are going through with the Linux packaging. I took a pass on that when I posted a sound-based app on itch.io. I only packaged for Windows and Mac. If you get it working, I may pick your brains on what all was needed to make it work on itch. The info would be a useful tutorial or wiki contribution.

One thing I’m not clear on: when packaging for Linux, is it necessary to include the source code?

There are often be problems with the first sounds played, even on Windows. There just doesn’t see to be enough of a priority to get this handled. I kind of threw up my hands and haven’t been monitoring bug reports on the issue. My work-around is to immediately start playing a “silent” sound, and thus get the code running for a short while before opening up the volume.

I do appreciate having the chance to investigate this further. I’d like to be able to say with some assurance whether my AudioCue works on Linux systems or not. I’m going to go retest the test programs I made for AudioCue on my Linux system right now.

The simplest thing for me would be to have source and resources (sound files) in a zip or jar. In Eclipse, I use Export -> Jar File -> Export Java source files and resources.

You can email me at phil at adonax dot com.

There may be a way to deal with thread priorities in Linux. I haven’t digested this yet. The info could be stale as it is from 2010. It requires running the program as root and a adding a directive: “-XX:ThreadPriorityPolicy=42” among other things/limitations. This is more than I want to hassle with, though, if at all possible to avoid.

I understand your position but Paul Lamb 3D Sound System just works under GNU Linux, I have used it in my game without any trouble for many years, I tested it under Windows and OS X too. Integrating this library isn’t very difficult, you need to add at least 2 JARs into your classpath (the exact number depends on the plug-ins you use) and this is how I use it:

When I decided to drop Java Sound in favour of JOAL, I had some problems with very short sound samples. It was probably fixed in the meantime but as JOAL with OpenAL-Soft works better (in my humble opinion), I don’t want to give another change to Java Sound and Paul Lamb 3D Sound System doesn’t force you to abandon Java Sound if you want to stick to it at least as a first step. I understand your frustration as I had the same feelings at the very beginning. Each time I thought a problem was solved, I saw another one happening. I had to abandon applets first. Then, I had to abandon Java2D in favour of JOGL. I abandoned raycasting, I wrote my own 3D engine. I abandoned Java Sound in favour of JOAL. After that, I dropped my own engine to use JMonkeyEngine, I paid someone to fix its JOGL backend and I abandoned JMonkeyEngine in favour of Ardor3D, I contributed a lot to it but its main developer decided to abandon it for a few years so I had to create a fork and maintain it on my side. I had to abandon Java Webstart too, I wrote my own tool that has some advantages over Oracle Java JPackage (the former can build a native installer for Windows under GNU Linux and vice versa whereas the latter can’t). Don’t give up.

By the way, Paul Lamb wrote that, maybe it can help you, it’s a workaround for a bug that might me familiar to you:

[quote]Known bug: quickPlaying sounds will begin playing them at full volume for a split second, before switching to the correct volume. This is a bug with the Java Sound API itself, and therefore beyond my control to correct. An easy workaround is to add 0.02 seconds of silence to the beginning of each sound effect (the free Audacity sound editor works well for this).