Class AudioFormat

java.lang.Object
org.openhab.core.audio.AudioFormat

@NonNullByDefault public class AudioFormat extends Object
An audio format definition
Author:
Harald Kuhn - Initial contribution, Kelly Davis - Modified to match discussion in #584, Kai Kreuzer - Moved class, included constants, added toString, Miguel Álvarez Díez - Add pcm signed format
  • Field Details

  • Constructor Details

    • AudioFormat

      public AudioFormat(@Nullable String container, @Nullable String codec, @Nullable Boolean bigEndian, @Nullable Integer bitDepth, @Nullable Integer bitRate, @Nullable Long frequency)
      Constructs an instance with the specified properties. Note that any properties that are null indicate that the corresponding AudioFormat allows any value for the property. Concretely this implies that if, for example, one passed null for the value of frequency, this would mean the created AudioFormat allowed for any valid frequency.
      Parameters:
      container - The container for the audio
      codec - The audio codec
      bigEndian - If the audo data is big endian
      bitDepth - The bit depth of the audo data
      bitRate - The bit rate of the audio
      frequency - The frequency at which the audio was sampled
    • AudioFormat

      public AudioFormat(@Nullable String container, @Nullable String codec, @Nullable Boolean bigEndian, @Nullable Integer bitDepth, @Nullable Integer bitRate, @Nullable Long frequency, @Nullable Integer channels)
      Constructs an instance with the specified properties. Note that any properties that are null indicate that the corresponding AudioFormat allows any value for the property. Concretely this implies that if, for example, one passed null for the value of frequency, this would mean the created AudioFormat allowed for any valid frequency.
      Parameters:
      container - The container for the audio
      codec - The audio codec
      bigEndian - If the audo data is big endian
      bitDepth - The bit depth of the audo data
      bitRate - The bit rate of the audio
      frequency - The frequency at which the audio was sampled
      channels - The number of channels
  • Method Details

    • getCodec

      public @Nullable String getCodec()
      Gets codec
      Returns:
      The codec
    • getContainer

      public @Nullable String getContainer()
      Gets container
      Returns:
      The container
    • isBigEndian

      public @Nullable Boolean isBigEndian()
      Is big endian?
      Returns:
      If format is big endian
    • getBitDepth

      public @Nullable Integer getBitDepth()
      Gets bit depth
      Returns:
      Bit depth
      See Also:
    • getBitRate

      public @Nullable Integer getBitRate()
      Gets bit rate
      Returns:
      Bit rate
      See Also:
    • getFrequency

      public @Nullable Long getFrequency()
      Gets frequency
      Returns:
      The frequency
    • getChannels

      public @Nullable Integer getChannels()
      Gets channel number
      Returns:
      The number of channels
    • isCompatible

      public boolean isCompatible(@Nullable AudioFormat audioFormat)
      Determines if the passed AudioFormat is compatible with this AudioFormat. This AudioFormat is compatible with the passed AudioFormat if both have the same value for all non-null members of this instance.
    • getBestMatch

      public static @Nullable AudioFormat getBestMatch(Set<AudioFormat> inputs, Set<AudioFormat> outputs)
      Determines the best match between a list of audio formats supported by a source and a sink.
      Parameters:
      inputs - the supported audio formats of an audio source
      outputs - the supported audio formats of an audio sink
      Returns:
      the best matching format or null, if source and sink are incompatible
    • getPreferredFormat

      public static @Nullable AudioFormat getPreferredFormat(Set<AudioFormat> audioFormats)
      Gets the first concrete AudioFormat in the passed set or a preferred one based on 16bit, 16KHz, big endian default
      Parameters:
      audioFormats - The AudioFormats from which to choose
      Returns:
      The preferred AudioFormat or null if none could be determined. A passed concrete format is preferred adding default values to an abstract AudioFormat in the passed set.
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object