nn.pp.audiocore

## Class AudioFormat

- java.lang.Object
- - javax.sound.sampled.AudioFormat
  - - nn.pp.audiocore.AudioFormat

- All Implemented Interfaces:
    java.lang.Comparable<AudioFormat>

      public class AudioFormat
      extends javax.sound.sampled.AudioFormat
      implements java.lang.Comparable<AudioFormat>

  Represents the audio sample format

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class javax.sound.sampled.AudioFormat

      `javax.sound.sampled.AudioFormat.Encoding`

  - ### Field Summary

    - ### Fields inherited from class javax.sound.sampled.AudioFormat

      `bigEndian, channels, encoding, frameRate, frameSize, sampleRate, sampleSizeInBits`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AudioFormat(float sampleRate, int sampleSizeInBits, int channels)` Create a new audio format

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(AudioFormat o)`
    `boolean` | `equals(java.lang.Object that)`
    `static AudioFormat` | `fromShortString(java.lang.String shortString)` Create an audio format from a string.
    `int` | `getBytesPerSecond()` Get the average number of bytes required to encode one second of audio
    `byte[]` | `getSilence(int milliseconds)` Generate some "silence" of a desired length
    `byte` | `getSilenceByte()` Get the byte which represents "silence"
    `int` | `hashCode()`
    `java.lang.String` | `toShortString()` Get a short string representation of this audio format in the format "samplerate_bits_channels" (e.g.
    `java.lang.String` | `toString()` Get the string representation of this audio format, e.g.

    - ### Methods inherited from class javax.sound.sampled.AudioFormat

      `getChannels, getEncoding, getFrameRate, getFrameSize, getProperty, getSampleRate, getSampleSizeInBits, isBigEndian, matches, properties`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### AudioFormat

          public AudioFormat(float sampleRate,
                             int sampleSizeInBits,
                             int channels)

      Create a new audio format
      Parameters:
        `sampleRate` - the sample rate in Hz - usually 48000, 44100, 22050 or 11025
        `sampleSizeInBits` - the number of bits per sample and channel - usually 8 or 18
        `channels` - the number of channels - usually 1 (mono) or 2 (stereo)

  - ### Method Detail

    - #### fromShortString

          public static AudioFormat fromShortString(java.lang.String shortString)

      Create an audio format from a string.

      The string must be in format "samplerate_bits_channels" (e.g. "44100_16_2").

      Note: this is the same format as provided by the `toShortString()` method.

      Parameters:
        `shortString` - the format string to parse
      Returns:
        the parsed audio format
      See Also:
        `toShortString()`

    - #### getBytesPerSecond

          public int getBytesPerSecond()

      Get the average number of bytes required to encode one second of audio
      Returns:
        the average number of bytes required to encode one second of audio

    - #### toString

          public java.lang.String toString()

      Get the string representation of this audio format, e.g. "stereo, 16 bit, 44100 Hz".
      Overrides:
        `toString` in class `javax.sound.sampled.AudioFormat`
      Returns:
        the string representation

    - #### toShortString

          public java.lang.String toShortString()

      Get a short string representation of this audio format in the format "samplerate_bits_channels" (e.g. "44100_16_2").
      Returns:
        the string representation

    - #### compareTo

          public int compareTo(AudioFormat o)

      Specified by:
        `compareTo` in interface `java.lang.Comparable<AudioFormat>`

    - #### equals

          public boolean equals(java.lang.Object that)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### getSilenceByte

          public byte getSilenceByte()

      Get the byte which represents "silence"
      Returns:
        the byte which represents "silence"

    - #### getSilence

          public byte[] getSilence(int milliseconds)

      Generate some "silence" of a desired length
      Parameters:
        `milliseconds` - the length (in milliseconds) of the silence to generate
      Returns:
        the samples with the "silence"

Copyright © 2025 Raritan Inc. All Rights Reserved.