Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (731)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (798)
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  
  Multiple clips on the same line  (Read 501 times)
0 Members and 1 Guest are viewing this topic.
Offline FabulousFellini
« Posted 2017-06-13 22:35:05 »

Is this possible?  I have been googling and javagaming.orging but I'm not sure.  Is it possible with Java sound to have multiple clips going through the same line? 

My problem is that my game has about 30-40 different sounds, and when the program initializes, I open a different line for each clip, and they remain open throughout the entire game because they all get used over and over.  This works fine on Windows systems.

However, the Raspberry Pi only has 8 lines, which throws a LineUnavailableException.  Right now, I'm re-doing the audio so all sound effects are in the same audio file, one after the other, and I have to go and figure out the frame positions for each sound and play them accordingly.  I have done this with the background music which isn't too hard.  When I go to do the sound effects, it will take a long ass time.   

So is it possible to play all the sound effects through the same line instead of opening a separate line for each sound?

-FabulousFellini
www.fabulousfellini.com
Offline philfrei
« Reply #1 - Posted 2017-06-14 02:15:04 »

Neat idea, to place several audio clips on the same audio file! I hadn't thought of doing that. How do you stop the cue at the right place? Are you counting frames somehow?

To collect all sounds and send them out a single line, you have to write a mixing algorithm yourself or make use of a library such as TinySound which does exactly this. (By mixer I mean the equivalent of an audio mixer as studio gear, not the javax.sound.sampled.Mixer class which is something different.)

To mix, it is matter of getting at the individual PCM sound frames (can be done by first loading the cues into memory arrays or using an AudioinputStream if you are playing back from a file), and summing them, then outputting the sum on a SourceDataLine.

I have been working pretty hard, actually, on a class I'm calling an AudioCue. There is a weak first pass already posted here at JGO. It will allow concurrent sound effects for any sound effect line that is "opened", where all the concurrent plays will be summed into a single output for that cue. (Example: variable number of bullets in quick succession for simulating a semi-automatic rifle, all come from one cue and all output on single line, despite the cues being played in a concurrent, overlapping fashion.) The new version I am about to post has reliable and smooth volume, pan, and frequency faders, so the same sound can be played back at different speeds at the same time and still be counted as a single output line.

I could just go ahead and post it now if it would be useful, or send you a preview, but I am still working on the JavaDocs for it and want to rewrite the panning into a lambda form, so different types of panning could be used. Also want to put in some input argument safety checks and clamping on the output. It is easy to overdrive and create wretched noises if you aren't careful. (But not so bad if you know what you are doing and understand audio.)

This class would allow you to do:
1) load all your 30--40 different sounds into memory
2) easily open and shut the lines as needed (assuming different segments of the game use different sounds).

If some of the sounds can do double duty by varying the speed or if some of your 30-40 are implementations of concurrent uses of clips, this could get you a long way towards reducing the number of lines that need to be open at once.

I haven't timed the lag for the combo open/play with this class yet as I hadn't anticipated that use. But if you can run an open method a good 100 millis prior to play as a preparatory step, that would easily be a good safety margin.  

Anyway, you probably just need to go to a library.
How far along is your game, otherwise?
Is it possible to check out what you have so far?
I do have a mixer library I wrote that does the mixing I described--maybe I can rig up a version that will handle your needs.

music and music apps: http://adonax.com
Offline FabulousFellini
« Reply #2 - Posted 2017-06-14 19:14:47 »

Yeah, I'm just using if(getFramePosition() == xxx), stop the clip (although I had to go through and figure out the start/stop frame position for the sounds.  It would be cool to try out AudioCue!  No rush though as I have some time so you can do whatever you need to before you post it.  I can post my audio class when I get home from work so you can take a look.  The game is almost done, I just need to program the last boss battle and do some bug fixes.   Thanks for the reply!  It kinda made my day that you said I have a neat idea about sound lol.

-FabulousFellini
www.fabulousfellini.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline FabulousFellini
« Reply #3 - Posted 2017-06-23 04:12:25 »

I ended up using TinySound and wow was that easy to implement.  I never really realized it would be so easy.  I learned how to use and ported all the java sound to tiny sound in about 2 hours.

@philfrei, I would still be interested in trying out AudioCue whenever you have it good and ready.  Thanks for helping me out with this!

-FabulousFellini
www.fabulousfellini.com
Offline philfrei
« Reply #4 - Posted 2017-06-23 16:59:14 »

Finished a draft of the API. Am working on html page for posting, and figuring out license (worst case scenario: requirement to post a single link on an "About" page or "Credits" page).

TinySound is a good library! Glad you gave it a try.

AudioCue will have some advantages and disadvantages. It doesn't mix everything together into a single output line (advantage TinySound) but I can't recall if TinySound has real time volume, panning and frequency changes, or if it lets you position the "playhead" to different points. I probably should have looked closely at its API before designing mine, though. I think AudioCue will be similarly easy to use (or at least in the ballpark).

All right, I actually have a hour to work on it this morning--better stop procrastinating.

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

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

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

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

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

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

Rule (973 views)
2017-03-19 12:42:17

Rule (971 views)
2017-03-19 12:36:21

theagentd (1071 views)
2017-03-16 05:07:07

theagentd (990 views)
2017-03-15 22:37:06

theagentd (760 views)
2017-03-15 22:32:18
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!