Chapter 9. Audio Effects

This chapter presents different ways of applying effects to existing audio. All of these techniques share one of the key advantages of the Sound API: the ability for a programmer to delve into the low-level details of audio files and affect (to some degree) the audio devices (e.g., the mixer, sequencer, or synthesizer).

You’ll see how audio effects can be manipulated with clip and MIDI channel controllers, via sample byte array manipulation and modification of MIDI messages. The discussion is split into two main parts: audio effects for sampled audio and effects for MIDI sequences.

Tip

All the examples can be found in the directory SoundExamps/SoundPlayer/.

Audio Effects on Sampled Audio

There are three approaches for affecting sampled audio:

Precalculation

Using this approach, you create the audio effect at development time and play the resulting sound clip at execution time.

Byte array manipulation

Here, you store the sound in a byte array at runtime, permitting it to be modified using array-based operations.

Mixer controls

A mixer control, such as gain or panning, affects the sound signal passing through the mixer’s audio line.

Precalculation

Manipulating audio inside Java can be time-consuming and complicated. If a sound effect is going to be used regularly (e.g., a fading scream, an echoing explosion), then it will probably be better to create it when the game is being developed and save the finished audio to a file for playing at runtime. This moves the overheads ...

Get Killer Game Programming in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.