Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sound tool recommendations and/or javax.sound problems  (Read 6933 times)
0 Members and 1 Guest are viewing this topic.
Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Posted 2017-04-03 20:05:51 »

I am presently using javax.sound for my sound needs. Is this used much? Is there any kind of community preference/standard or can you recommend anything I should use? I really just need very basic sound functions I think.

My problem with javax.sound: I have 1 serious and 1 minor problem I'm aware of with java sound.
1) It will hang my program when trying to close a large number of Clip streams. I don't know how else to play clips (like sound FX) and have them close on their own and avoid system lag.

2) It has lag on the volume change and it pops sometimes. It just seems cheap. I don't see how I'm doing it wrong code-wise, but I suppose I could be. All I do is send a float at it to change the gain:
1  
2  
3  
4  
5  
6  
      if (BGMclip != null)
      {
          FloatControl gainControl =
                  (FloatControl) BGMclip.getControl(FloatControl.Type.MASTER_GAIN);
              gainControl.setValue(volNum); // Set volume at <volNum> decibels. -10.0f
      }

It doesn't do this immediately and it sometimes pops. I can live with that, but surely I can find a sound system that can handle my very basic needs without issue (or use this one better Wink ).
Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #1 - Posted 2017-04-04 07:15:11 »

I believe this thread and nsigma answered my question. I shouldn't be using Clip as I am. I should perhaps use TinySound or OpenAL.
Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #2 - Posted 2017-04-04 11:46:56 »

"usually" it goes like .. javax.sound < tinysound < openal < fmod
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #3 - Posted 2017-04-06 05:28:20 »

Problems with closing a large number of Clips?
I'm surprised this is an issue. Could we see more?

Volume clicks:

Yes, a very real problem. I decided to write a clip-equivalent, and output the data from memory to a SourceDataLine. Volume changes are spread out over 1028 samples on a per sample basis. With a Clip, the changes can only occur with each buffer playback, and a large jump creates an audible discontinuity. You can get a bit more granularity by reducing the buffer size and spreading the changes out over time. But making the buffer too small leads to dropouts.

Design around the problem? Have your Clips only play back at fixed volumes, but maybe allow files (SourceDataLine) to be opened up and given the per-sample spread of volume changes. The code for getting at the individual sound frames can be found on the Java Tutorials in the first code example, at the point where there is a comment "//Here do something useful".

I do not know how TinySound handles this. It seems to me he has some provision for fading in and out smoothly, but I am not up on specifics of using this library.

OpenAL probably requires using a wrapper like Libgdx. if you are going to LIBGDX anyway, it makes sense to use it. There are lots of good features and some annoying liabilities and limitations. FMod is expensive if you are going commercial. There might be a free version though. I was told there is another library that is competing but I've lost my notes on this. Sorry.

music and music apps: http://adonax.com
Offline nsigma
« Reply #4 - Posted 2017-04-06 09:54:10 »

I do not know how TinySound handles this. It seems to me he has some provision for fading in and out smoothly, but I am not up on specifics of using this library.

Doesn't look like TinySound does gain interpolation either.  Sad

Other libraries to look at would be Minim and Beads, both of which are well known in the Processing community, but will work with just Java.

One day I'll get around to exporting the pure Java audio library from Praxis LIVE ...  persecutioncomplex

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #5 - Posted 2017-04-06 09:59:14 »

+1 for http://www.beadsproject.net/.

fmod is free to use for non-comercial projects. there is no "limited" version.
Offline nsigma
« Reply #6 - Posted 2017-04-06 10:11:35 »


Beads is great, but has the potential issue of being GPL, unlike Minim - http://code.compartmental.net/tools/minim/  Beads has a better architecture in my opinion, but I'm also biased because I contributed the audio IO from Praxis LIVE to it!  Wink

Also, probably better to compile Beads from source as there's been a variety of changes since the last release.  https://github.com/orsjb/beads

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline philfrei
« Reply #7 - Posted 2017-04-06 15:28:10 »

One day I'll get around to exporting the pure Java audio library from Praxis LIVE ...  persecutioncomplex
Wish to encourage this. (Not the sense of persecution/paranoia, but the release of a better Java audio library.)

Maybe it would be good to start a wish list/feature list of a minimal but genuinely useful library?

music and music apps: http://adonax.com
Offline nsigma
« Reply #8 - Posted 2017-04-06 16:45:06 »

Wish to encourage this. (Not the sense of persecution/paranoia, but the release of a better Java audio library.)

I'm going to be working full-time for a while on Praxis LIVE and related media libraries, so this just might happen!

Maybe it would be good to start a wish list/feature list of a minimal but genuinely useful library?

A none-obvious, but key one for me, is that it's lock-free.  This is one of the reasons I don't use Beads.  And also why I haven't yet extracted some of the code out of Praxis LIVE, because outside of the environment it's not so easy to work with - however, good use of lambdas / method references in an API might make this not too painful.

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #9 - Posted 2017-04-06 20:35:00 »

Problems with closing a large number of Clips?
I'm surprised this is an issue. Could we see more?

This is my method for playing a sound effect:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
   //start clip play
   public synchronized void play(final String fileName)
   {
       if(!muted && !FXmuted)
       {
          try {
               AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(fileName));
              Clip FXclip = AudioSystem.getClip();
              FXclip.open(inputStream);
             
               FloatControl gainControl =
                      (FloatControl) FXclip.getControl(FloatControl.Type.MASTER_GAIN);
                  gainControl.setValue(FXvc); // Set volume at <vc> decibels. -10.0f
             
                       //listener for closing clip when done
                  FXclip.addLineListener(new LineListener() {
                      public void update(LineEvent myLineEvent) {
                        if (myLineEvent.getType() == LineEvent.Type.STOP)
                          FXclip.close();
                      }  
                    });
                 
              FXclip.start();
          } catch (Exception e) {
             System.out.println("play FX error: " + e.getMessage() + " for " + fileName);
              System.err.println(e.getMessage());
          }
       }  
   }


I can't always get it to lag. I can't always replicate the problem, but it seems related to the sound. In a prior attempt at using sound, it had clearly been the case (that closing was the problem). This newest version works a lot of the time, but under heavy load it hangs until it can catch up.

It could be an issue with *making* too many sounds now rather than closing?

For a test I just set a sound effect to run 6 times per click. After clicking very rapidly, this eventually made it hang. It shows no signs of stress until seizing up.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline philfrei
« Reply #10 - Posted 2017-04-07 02:38:50 »

The good news is that you can improve your performance a couple orders of magnitude over what you have coded.

Clips were designed to be loaded separately from the act of playing them. If you combine loading and playing, the playing won't even commence until after the slower process of loading the sound file into memory completes.

There's other code that looks kind of superfluous as well (surely there is a way to avoid having to do any synchronization), but I'm not able to straighten it all out by eyeballing. My brain is too full of other stuff at the moment.

When you want to play a clip, do only two things:
1) set the cursor back to 0, as in clip.setFramePosition(0);
2) then call clip.play.

Things like hooking up the volume line and loading the data (you only have to do this once) can be part of the construction/instantiation process of whatever class you are using to wrap the clip.

****

I am going to tinker with maybe making an open source SoundCue class that combines elements of Clip and SourceDataLine. I'm thinking it should be able to do the following:

play on demand, play from a given position within the cue, loop (n times or continuously), loop with overlap-smoothing at the edges, play concurrently (up to n copies), play at different velocities (faster or slower, using linear interpolation), continuous/smooth volume, velocity, and pan controls, and a customized Listener that can send notifications when the cue starts or stops (and no blocks or synchronization)

If it works, it might serve as a intermediate/stopgap step to making use of nsigma's forthcoming library. If it shows up before 4/15 it means I am procrastinating dangerously on finishing taxes and other deadlines that seem to be besieging me at the moment.

music and music apps: http://adonax.com
Offline Optimo

Junior Devvie




I'm gon have to know, how ya garden grow


« Reply #11 - Posted 2017-04-07 02:54:43 »

Quote
Clips were designed to be loaded separately from the act of playing them.
When you want to play a clip, do only two things:
1) set the cursor back to 0, as in clip.setFramePosition(0);
2) then call clip.play.
Sounds like the same mentality I've had to learn to use for my images in OpenGL. Load them at startup and just reuse those textures.

I reckon if I wanted the same sound effect to play before one play of that track had finished, I'd need another Clip for that? But just keep a Clip pool (LinkedList or some data structure of Clips) and add on to that as I need. Reuse where I can, add on where needed.

Thanks for the help! Better make sure The Man gets his money.  Cool
Offline philfrei
« Reply #12 - Posted 2017-05-16 02:57:23 »

@Optimo -- I started work on a Clip that allows concurrent playback. You can download it from the SharedCode area.

I think the next step will be providing a way to do normal Clip things like position the cursor and loop. Then I'll get a real-time volume control working based on one I've used before. It spreads the volume change out over 1024 frames which is quick enough for most perceptions where fading is occurring and small enough increments to prevent zippering. Will try to find time to do this before end of May.

music and music apps: http://adonax.com
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (17 views)
2017-11-21 16:21:00

xxMrPHDxx (11 views)
2017-11-21 16:14:31

xxMrPHDxx (14 views)
2017-11-21 16:10:57

Ecumene (114 views)
2017-09-30 02:57:34

theagentd (148 views)
2017-09-26 18:23:31

cybrmynd (248 views)
2017-08-02 12:28:51

cybrmynd (247 views)
2017-08-02 12:19:43

cybrmynd (244 views)
2017-08-02 12:18:09

Sralse (258 views)
2017-07-25 17:13:48

Archive (878 views)
2017-04-27 17:45:51
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!