• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

AudioCue, an alternative to Clip, for 2D games

 
Ranch Hand
Posts: 137
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote an alternative to javax.sound.sampled.Clip, for the handling of sound cues in games. The license is BSD-based, the source code is viewable. To use, just add three classes to your project: AudioCue, AudioCueListener (an interface), and AudioCueInstanceEvent (used with the Listener). The API can be examined here.

This class will handle most* of the functionality that Clip provides, but with a couple useful additions:
  • concurrent playback of cues,
  • real-time fading for volume, panning and pitch, at the independent playback instance level.

  • Output is from an accessible internal float[] array via a javax.sound.sampled.SourceDataLine. Aspects like the audio playback thread priority and the internal buffer size used by the SourceDataLine are optionally configurable. The fader controls are built in, they do not make use of javax.sound.sampled.Control.

    *An important limitation, however, is that I only implemented one format so far: 44100 fps, 16-bit, stereo, little-endian (aka "CD Quality").

    I'm posting here at JavaRanch in part because I'm hoping for code review. I've had some great experiences here as a student (via the CattleDrive) and have found the feedback of excellent quality in terms of paying attention to best practices and design principles. I've made efforts to conform as best as I could to both the Javadocs API recommendations and to those of Joshua Bloch, and am wondering how code reviewers here would assess my efforts, in both the coding and the JavaDocs. Bloch says to expect that there will be things found that will need to change in the API after it is subjected to use--so, I will be appreciative of feedback and advice.

    I notice that JavaRanch now has a "blatant advertising" tag for posts. Seems like it would be appropriate here. Is there something I need to do to add that tag? I don't see anything obvious, and am assuming this is something that moderators will do.

    Additional discussion of the class and supporting downloads can be found here, including source code examples and jars. This example jar illustrates the real-time fader controls. This example jar illustrates how a single cue, (a single frog croak), might be used to build soundscape elements (a pond with many frogs). (The size of these jars comes mostly from the media content, and source is included.)

    I hope JavaRanch game programmers find this class useful for their games!

     
    He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
    Devious Experiments for a Truly Passive Greenhouse!
    https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
      Bookmark Topic Watch Topic
    • New Topic