Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (734)
Games in Android Showcase (222)
games submitted by our members
Games in WIP (811)
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  
  prevent a clip get closed  (Read 521 times)
0 Members and 1 Guest are viewing this topic.
Offline pavul

Junior Devvie


Medals: 2
Exp: 4 years



« Posted 2017-08-10 19:54:40 »

java sound cannot play after is closed!.

im using clips to play .wav files on raspberry pi device, I checked that on windows laptop and was working without issue, but when I run the game in raspberry, after a time or after play like 6-times the sounds, I got an error of LineException, I checked the state of the clip and every time im receiving those exceptions the clip is closed, I would like to know how to prevent that, the code im using is the next one:

https://github.com/pavul/ilusion2/blob/develop/src/main/java/com/ilusion2/audio/Sound.java

on branch develop, and im also using the first play method. As I said work in windows but not all the time on RPI, Im gonna check this week on Linux mint and macos

its better not know why it works, that know why is not working
Offline FabulousFellini
« Reply #1 - Posted 2017-08-10 20:07:14 »

I think I can actually answer this one correctly!  As I had the same problem.  It seems like Windows has unlimited lines (or as many as you would ever need).  However, the PI only has 8 lines.  For me that's why it was throwing the LineUnavailableException, because I was trying to open more lines than the PI had.  Here is a thread I started about it:

http://www.java-gaming.org/topics/multiple-clips-on-the-same-line/38273/view.html

I got around the issue by using TinySound, which is 95% easier than using JavaSound anyway, and it sends all the sound output through the same lines (so basically only 2, for left and right), regardless of how many different sounds you're using.   Also, @philfrei will probably be able to help you out as well, as he is building an awesome sound tool.

-FabulousFellini
www.fabulousfellini.com
Offline philfrei
« Reply #2 - Posted 2017-08-10 23:20:54 »

Thanks for the ping!

The code looks fine, so I'm guessing you ran into the 8-output-line limit on PI. You might try closing any sound that is not being used. (Close both the AudioInputStream and the Clip.)

TinySound is a good solution. This library mixes all sounds into a single output line.

The code I wrote is called AudioCue. It has a smaller footprint than TinySound, and you can do some extra things, like real-time pitch variation, volume fading and panning. You'll probably only be able to load 8 AudioCues at one time, but the way the class is made, you can play as many instances of those sounds (with pitch variations) as your cpu can handle. In other words, 5 gunshot bullets made and heard at the same time 9rapid succession) will only count as a single output.

I'm working on (and off) on figuring out how to create an option for mixing AudioCue's together, letting them share an output line. It is a little tricky. I could hack something out in a day, but I'm trying to get the API to make sense rather than have it be kind of cloojy. Juggling a lot of things at the moment and might not figure it out for a while.

music and music apps: http://adonax.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pavul

Junior Devvie


Medals: 2
Exp: 4 years



« Reply #3 - Posted 2017-08-11 00:08:45 »

i am totally interested on this, i was about to implement tinySound but yesterday i asked to the creator if he has that jar on maven repository to add that dependency to gradle, i didnt know about those 8 lines but now that u are telling me that it makes sense, so are u using RPI to run the games there, because im using pi4j as well to create some kind of control, with a protoboard and that stuff, how can i send private messages, tried before with no luck at all.

its better not know why it works, that know why is not working
Offline pavul

Junior Devvie


Medals: 2
Exp: 4 years



« Reply #4 - Posted 2017-08-11 00:11:02 »

thanks so much, i can try to implement this if you want, just you have to pass me some documentatio of how to do it.

its better not know why it works, that know why is not working
Offline nsigma
« Reply #5 - Posted 2017-08-11 09:40:58 »

Your first play method is opening a new Clip every time you want to play a sound, even if it's the same file?  You're also never closing the Clips after playback.  Basically, this code is all wrong, and you'll eventually run out of resources on any platform, just much quicker on the Pi.

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

Junior Devvie


Medals: 2
Exp: 4 years



« Reply #6 - Posted 2017-08-11 15:27:11 »

I think so, I thougth that when a clip reaches the end of the line it states changes to STOP, so I tought they were closed alone, and because I was using local variables, do you have any idea of what can I do properly?

its better not know why it works, that know why is not working
Offline nsigma
« Reply #7 - Posted 2017-08-11 16:04:16 »

I think so, I thougth that when a clip reaches the end of the line it states changes to STOP, so I tought they were closed alone, and because I was using local variables, do you have any idea of what can I do properly?

Yes, stop using Clip!  Grin

However, if you just have a few sounds / don't want the hassle of a proper sound system, make sure you only have one Clip per sound file - you seem to have a Map set up for this already?  Then just replay the existing Clip, probably rewinding it each time (frame position).  You'll probably still be limited to the number of available sounds you can have on the Pi though.

If the limits on number of sounds is still a problem after this approach, then you're either going to have to start using listeners to close the clips when they've finished playing, or decide that really isn't worth the effort and pick one of the multiple libraries that can do software mixing (TinySound, Minim and JSyn being obvious ones that have a usable license)

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

Junior Devvie


Medals: 2
Exp: 4 years



« Reply #8 - Posted 2017-08-11 19:50:19 »

ajjaja tnx man, I was about to implement that way but I was not aware of many things that's I came with that naïve approach I had, yesterday implemented TinySound, I have to check if that works on RPI.

its better not know why it works, that know why is not working
Offline philfrei
« Reply #9 - Posted 2017-08-11 22:37:34 »

Your first play method is opening a new Clip every time you want to play a sound, even if it's the same file?  You're also never closing the Clips after playback.  Basically, this code is all wrong, and you'll eventually run out of resources on any platform, just much quicker on the Pi.

When I saw that the start method call that is at the end of the play method in the code was commented out, I forgot that there was still a start method call embedded in with the load and open sections. So nsigma is right and I blew it by saying "the code looks fine." Combining a Clip load, open and start in one code block is likely always the wrong way to do things.

If you only need 8 different sounds, load and open each and hold them as ready to go as instance variables or something. Then you can use the start() method call on an as-needed basis and the sound will play with a minimum of latency.

A clip does not close when it reaches the end of a playback. You can take that same clip, and replay it by setting the framePosition to 0 and then calling start again.

Garbage collection for Line (Clip extends Line) is different than other classes. "Resources" obtained by the line need to be closed before the instance is garbage-collected. If you are done with a Clip, it is important to close it. Stopping and Closing are not the same!

The Sound Tutorial that Oracle provides is not very clear at all on demonstrating simple use cases. Lots of people get messed up and discouraged trying to make sound work as a result.

music and music apps: http://adonax.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pavul

Junior Devvie


Medals: 2
Exp: 4 years



« Reply #10 - Posted 2017-08-12 19:07:56 »

i tried TinySound and is working well, i checked on Windows and Mac OS X, but wen i ran the game in RPI, it sound the effect but with a delay i mean it does not sound when i hit the enemy but later like a second later, i dont know if that is normal or if i have to configure something else.

its better not know why it works, that know why is not working
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

Archive (489 views)
2017-04-27 17:45:51

buddyBro (637 views)
2017-04-05 03:38:00

CopyableCougar4 (1117 views)
2017-03-24 15:39:42

theagentd (1126 views)
2017-03-24 15:32:08

Rule (1101 views)
2017-03-19 12:43:22

Rule (1078 views)
2017-03-19 12:42:17
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!