AudioFormat.Encoding (Java SE 26 & JDK 26)
Description: declaration: module: java.desktop, package: javax.sound.sampled, class: AudioFormat, class: Encoding
Keywords: javax.sound.sampled.AudioFormat.Encoding class

# Class AudioFormat.Encoding

java.lang.Object
javax.sound.sampled.AudioFormat.Encoding

Enclosing class:
  `AudioFormat`

public static class AudioFormat.Encoding extends Object
The `Encoding` class names the specific type of data representation used for an audio stream. The encoding includes aspects of the sound format other than the number of channels, sample rate, sample size, frame rate, frame size, and byte order.

One ubiquitous type of audio encoding is pulse-code modulation (PCM), which is simply a linear (proportional) representation of the sound waveform. With PCM, the number stored in each sample is proportional to the instantaneous amplitude of the sound pressure at that point in time. The numbers may be signed or unsigned integers or floats. Besides PCM, other encodings include mu-law and a-law, which are nonlinear mappings of the sound amplitude that are often used for recording speech.

You can use a predefined encoding by referring to one of the static objects created by this class, such as `PCM_SIGNED` or `PCM_UNSIGNED`. Service providers can create new encodings, such as compressed audio formats, and make these available through the `AudioSystem` class.

The `Encoding` class is static, so that all `AudioFormat` objects that have the same encoding will refer to the same object (rather than different instances of the same class). This allows matches to be made by checking that two format's encodings are equal.

Since:
  1.3
See Also:
  - `AudioFormat`
  - `FormatConversionProvider`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final AudioFormat.Encoding`
  `ALAW`
  Specifies a-law encoded data.
  `static final AudioFormat.Encoding`
  `PCM_FLOAT`
  Specifies floating-point PCM data.
  `static final AudioFormat.Encoding`
  `PCM_SIGNED`
  Specifies signed, linear PCM data.
  `static final AudioFormat.Encoding`
  `PCM_UNSIGNED`
  Specifies unsigned, linear PCM data.
  `static final AudioFormat.Encoding`
  `ULAW`
  Specifies u-law encoded data.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Encoding(String name)`
  Constructs a new encoding.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final boolean`
  `equals(Object obj)`
  Indicates whether the specified object is equal to this encoding, returning `true` if the objects are equal.
  `final int`
  `hashCode()`
  Returns a hash code value for this encoding.
  `final String`
  `toString()`
  Returns encoding's name as the string representation of the encoding.

  ### Methods declared in class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Field Details

  - ### PCM_SIGNED

    public static final AudioFormat.Encoding PCM_SIGNED
    Specifies signed, linear PCM data.

  - ### PCM_UNSIGNED

    public static final AudioFormat.Encoding PCM_UNSIGNED
    Specifies unsigned, linear PCM data.

  - ### PCM_FLOAT

    public static final AudioFormat.Encoding PCM_FLOAT
    Specifies floating-point PCM data.
    Since:
      1.7

  - ### ULAW

    public static final AudioFormat.Encoding ULAW
    Specifies u-law encoded data.

  - ### ALAW

    public static final AudioFormat.Encoding ALAW
    Specifies a-law encoded data.

- ## Constructor Details

  - ### Encoding

    public Encoding(String name)
    Constructs a new encoding.
    Parameters:
      `name` - the name of the new type of encoding

- ## Method Details

  - ### equals

    public final boolean equals(Object obj)
    Indicates whether the specified object is equal to this encoding, returning `true` if the objects are equal.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - the reference object with which to compare
    Returns:
      `true` if the specified object is equal to this encoding; `false` otherwise
    See Also:
      - `Object.hashCode()`
      - `HashMap`

  - ### hashCode

    public final int hashCode()
    Returns a hash code value for this encoding.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash code value for this encoding
    See Also:
      - `Object.equals(java.lang.Object)`
      - `System.identityHashCode(Object)`

  - ### toString

    public final String toString()
    Returns encoding's name as the string representation of the encoding. For the predefined encodings, the name is similar to the encoding's variable (field) name. For example, `PCM_SIGNED.toString()` returns the name "PCM_SIGNED".
    Overrides:
      `toString` in class `Object`
    Returns:
      a string representation of the encoding