Class Encodings

  extended byjavax.sound.sampled.AudioFormat.Encoding
      extended byorg.tritonus.share.sampled.Encodings

public class Encodings
extends AudioFormat.Encoding

This class is a proposal for generic handling of encodings. The main purpose is to provide a standardized way of implementing encoding types. Like this, encodings are only identified by their String name, and not, as currently, by their object instance.

A registry of standard encoding names will be maintained by the Tritonus team.

In a specification request to JavaSoft, the static method getEncoding should be integrated into AudioFormat.Encoding(String name) (possibly renamed to getInstance(String name).
The static instances of ULAW, ALAW PCM_UNSIGNED and PCM_SIGNED encodings in that class should be retrieved using that function, too (internally).
At best, the protected constructor of that class should also be replaced to be a private constructor. Like this it will be prevented that developers create their own instances of Encoding, which causes problems with the equals method. In fact, the equals method should be redefined anyway so that it compares the names and not the objects.

Also, a specification request should be made to integrate getEncodings() into AudioSystem (this is especially annoying as the relevant methods already exist in the provider interfaces of file readers, file writers and converters).

Florian Bomers

Field Summary
Fields inherited from class javax.sound.sampled.AudioFormat.Encoding
Constructor Summary
Encodings(String name)
Method Summary
static boolean equals(AudioFormat.Encoding e1, AudioFormat.Encoding e2)
          Tests for equality of 2 encodings.
static AudioFormat.Encoding getEncoding(String name)
          Use this method for retrieving an instance of AudioFormat.Encoding of the specified name.
static AudioFormat.Encoding[] getEncodings()
          Returns all "supported" encodings.
Methods inherited from class javax.sound.sampled.AudioFormat.Encoding
equals, hashCode, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructor Detail


Encodings(String name)
Method Detail


public static AudioFormat.Encoding getEncoding(String name)
Use this method for retrieving an instance of AudioFormat.Encoding of the specified name. A standard registry of encoding names will be maintained by the Tritonus team.

Every file reader, file writer, and format converter provider should exclusively use this method for retrieving instances of AudioFormat.Encoding.


public static boolean equals(AudioFormat.Encoding e1,
                             AudioFormat.Encoding e2)
Tests for equality of 2 encodings. They are equal when their strings match.

This function should be AudioFormat.Encoding.equals and must be considered as a temporary work around until it flows into the JavaSound API.


public static AudioFormat.Encoding[] getEncodings()
Returns all "supported" encodings. Supported means that it is possible to read or write files with this encoding, or that a converter accepts this encoding as source or target format.

Currently, this method returns a best guess and the search algorithm is far from complete: with standard methods of AudioSystem, only the target encodings of the converters can be retrieved - neither the source encodings of converters nor the encodings of file readers and file writers cannot be retrieved.