Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  Simple API for JavaSound use  (Read 3948 times)
0 Members and 1 Guest are viewing this topic.
Offline divxdede

Junior Devvie





« Posted 2010-09-26 19:41:26 »

Hi all,
I'm currently writing a little game in java of course  Wink

At this time, i had completed the "game-logic" and i had started an UI implementation with Java2D.
At the end, i want to use an UI implementation with Slick, but doing it with Java2D force to me to preserve game-logic from the ui implementation and it's a good exercice as well.

So, in this implementation, i'm starting to add some sounds on my game... and i'm a strong newbie on this domain.
When studying JavaSound, OpenAL, NativeFmodEx, ... my first suprise is that all of theses API are low-level and we must manage I/O buffers, decoding streams, etc...

For my game, i have simple needs like:
  - Reading compressed file format like OGG Vorbis
  - Playing multiples sounds at the same time that should be mixed inside the hardware
  - Playing mutiples times the same sound at the same time.
  - Doing fade-In fade-Out effect
  - Change speed playback of a sound. (it's seems to be complex, and i'm not be able to implement it)

So, for theses simple needs, i'm writing a simple API upon JavaSound.
I know this API can't fullfill more complex needs (like 3D sounds, sync, complex effects, ...)
But in case it can help someone else, i put it here.

As i said, i'm a newbie in sound dev, and all remarks are welcome if it can improve this basis.
But i don't want to make a full API with a billion of features !!!

Here an exemple of use:

1  
2  
3  
4  
5  
6  
7  
8  
        // create a manager that will use a dedicated thread for perform I/O
        SoundManager manager  = new SoundManager();

        // get a sound definition
        Sound        sound    = manager.getBufferedSound( getClass().getResource("/audio.ogg") );

        // start a playback from the sound
        PlayBack     playback = sound.play();


Playback can be started at any times from any sounds and there I/O will be handled by the manager.

We can by example run a sound with a fade-in like it:

1  
2  
3  
4  
5  
6  
       Sound        sound    = manager.getBufferedSound( getClass().getResource("/audio.ogg") );

       SoundEffect effect    = SoundSequence.from(sound).playback().volume(0f).setLoop(true).resume().fadeIn( 3 , TimeUnit.SECONDS );
 
       SoundTimeLine timeline = manager.getTimeLine("example");
       Future future = timeline.submit(effect);


SoundSequence is a convenient way to create delayed operations upon a sound that can be executed by a timeline sequentially.
For more information, see sources or javadoc.
 
When your application should end, don't forget to close your SoundManager (that will close the dedicated thread)

1  
2  
      
  manager.close();


PS: For using OGG Vorbis, you just need to have JOrbis and VorbisSpi on your classpath.

Best regards,
André Sébastien. 
Offline gouessej
« Reply #1 - Posted 2010-09-26 20:33:54 »

Hi

There is already this:
http://www.java-gaming.org/topics/3d-sound-engine/20271/view.html
It is fine to reinvent the wheel as it allows to learn a lot of things Wink

Offline divxdede

Junior Devvie





« Reply #2 - Posted 2010-09-26 21:49:24 »

Hi

There is already this:
http://www.java-gaming.org/topics/3d-sound-engine/20271/view.html
It is fine to reinvent the wheel as it allows to learn a lot of things Wink

Yes i saw it.
I just figure it's main purpose was 3D sound and was a little more complex that what i need.
But i will try it if i had some free time this week.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2010-09-26 22:12:49 »

Yes i saw it.
I just figure it's main purpose was 3D sound and was a little more complex that what i need.
But i will try it if i had some free time this week.
Writing your own sound API might have a pedagogical interest but nothing else as Paul (the author of the API that I quoted) has made a great job, really. I have seen lots of tiny useless wrappers of JavaSound. Paul's sound engine takes into account several known bugs of Java Sound Audio Engine. If you don't want to lose all your hairs by writing your own sound API, use his API (well documented with some examples to start very quickly) that is neither complicated nor only for 3D, you can play some samples of music without using the 3D features.

Offline zammbi

JGO Coder


Medals: 4



« Reply #4 - Posted 2010-09-27 02:03:58 »

Quote
I just figure it's main purpose was 3D sound and was a little more complex that what i need.
His sound library is the easiest and best I've ever used. Basically just works without hassle. Reading his pdf you can get it working in your game in 5 minutes.

Current project - Rename and Sort
Offline paulscode

Senior Devvie


Medals: 12


Staff Sergeant


« Reply #5 - Posted 2010-09-27 09:26:59 »

If the SoundSystem is too large for your needs, you are also free copy and paste what you need from the source code (I've basically given it a "do whatever you like" license, so feel free to hack away at it).  If you need help understanding parts of it, let me know and I can explain how different things work.

We love death.  The US loves life.  That is the difference between us.  -Osama bin Laden, mass murderer
Offline nsigma
« Reply #6 - Posted 2010-09-27 10:53:07 »

I had a quick look through your code, though haven't tried actually compiling it.  For the purpose you've got, I really like the API.  The method chaining looks clean and intuitive (reminds me of jQuery), and I like the timeline.submit() and Future mechanism.

The one thing that may let you down is the underlying JavaSound library, which can be a real PITA.  It's behaviour can be inconsistent, and the best performing mixers don't necessarily do hardware mixing or provide you with the Controls you want.  If it's working for you, great, but you might be able to get better performance by going for a software mixing strategy.  I pointed to a few projects / sources of info in another thread - http://www.java-gaming.org/topics/writing-my-own-software-audio-mixer/22847/msg/188955/view.html#msg188955  Also, if you haven't come across it yet, http://www.jsresources.org/ is quite useful even if a bit dated (well, it's about as current as JS itself!  Smiley )

Best wishes, Neil

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline divxdede

Junior Devvie





« Reply #7 - Posted 2010-09-27 16:21:31 »

Thanks Neil for your return.
Features covered by this API are quite small and my goal was to offer this small assets on a very simple design.

Java Sound was attractive for a newbie like me because it's embedded on the JVM and don't need a lot of third parties.
But i surprise to hear that this API implementation seem to be not robust as we can expect for a standard API.

So, i haven't knowledge to do more complex stuff (especially reimplementing software mixing and so one).
I will start to try this evening the SoundSystem (i'm starting to install theses projects inside my maven repository).

Sébastien.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (38 views)
2014-11-26 15:22:04

toopeicgaming1999 (33 views)
2014-11-26 15:20:36

toopeicgaming1999 (8 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (25 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!