Class ALHelpers


  • public class ALHelpers
    extends Object
    • Constructor Detail

      • ALHelpers

        public ALHelpers()
    • Method Detail

      • getAudioFormat

        public static AudioFormat getAudioFormat​(int alChannelLayout,
                                                 int alSampleType,
                                                 int alFormat,
                                                 int sampleRate,
                                                 int sampleSize)
        Returns a compatible AudioFormat based on given OpenAL channel-layout, sample-type and format, as well as the generic sample-rate and sample-size.

        The resulting AudioFormat uses AudioFormat.planar = false and AudioFormat.littleEndian = true.

        Parameters:
        alChannelLayout - OpenAL channel layout
        alSampleType - OpenAL sample type
        alFormat - OpenAL format
        sampleRate - sample rate, e.g. 44100
        sampleSize - sample size in bits, e.g. 16
        Returns:
        a new AudioFormat instance or null if parameter are not conclusive or invalid.
      • getALFormat

        public static int getALFormat​(AudioFormat audioFormat,
                                      AL al,
                                      ALExt alExt)
        Returns a compatible AL buffer format given the AudioFormat, which determines the AL channel layout and AL sample type.

        If hasEXTMcFormats or hasSOFTBufferSamples is true, it will be called to find the closest-matching format from AL_EXT_MCFORMATS or AL_SOFT_buffer_samples.

        Returns ALConstants.AL_NONE if no supported format can be found.

        Function uses AL.alIsExtensionPresent(String), which might be context dependent, otherwise function is context independent.

        Parameters:
        audioFormat - used to derive AL channel layout getDefaultALChannelLayout(int) and AL sample type getALSampleType(int, boolean, boolean)
        al - AL instance
        alExt - ALExt instance
        Returns:
        AL buffer format
      • getALFormat

        public static int getALFormat​(AudioFormat audioFormat,
                                      AL al,
                                      ALExt alExt,
                                      boolean hasSOFTBufferSamples,
                                      boolean hasEXTMcFormats,
                                      boolean hasEXTFloat32,
                                      boolean hasEXTDouble)
        Returns a compatible AL buffer format given the AudioFormat, which determines the AL channel layout and AL sample type.

        If hasEXTMcFormats or hasSOFTBufferSamples is true, it will be called to find the closest-matching format from AL_EXT_MCFORMATS or AL_SOFT_buffer_samples.

        Returns ALConstants.AL_NONE if no supported format can be found.

        Function is context independent.

        Parameters:
        audioFormat - used to derive AL channel layout getDefaultALChannelLayout(int) and AL sample type getALSampleType(int, boolean, boolean)
        al - AL instance
        alExt - ALExt instance
        hasSOFTBufferSamples - true if having extension AL_SOFT_buffer_samples, otherwise false
        hasEXTMcFormats - true if having extension AL_EXT_MCFORMATS, otherwise false
        hasEXTFloat32 - true if having extension AL_EXT_FLOAT32, otherwise false
        hasEXTDouble - true if having extension AL_EXT_DOUBLE, otherwise false
        Returns:
        AL buffer format
      • getALFormat

        public static final int getALFormat​(int alChannelLayout,
                                            int alSampleType,
                                            AL al,
                                            ALExt alExt)
        Returns a compatible AL buffer format given the AL channel layout and AL sample type.

        If hasEXTMcFormats or hasSOFTBufferSamples is true, it will be called to find the closest-matching format from AL_EXT_MCFORMATS or AL_SOFT_buffer_samples.

        Returns ALConstants.AL_NONE if no supported format can be found.

        Function uses AL.alIsExtensionPresent(String), which might be context dependent, otherwise function is context independent.

        Parameters:
        alChannelLayout - AL channel layout, see getDefaultALChannelLayout(int)
        alSampleType - AL sample type, see getALSampleType(int, boolean, boolean).
        al - AL instance
        alExt - ALExt instance
        Returns:
        AL buffer format
      • getALFormat

        public static final int getALFormat​(int alChannelLayout,
                                            int alSampleType,
                                            AL al,
                                            ALExt alExt,
                                            boolean hasSOFTBufferSamples,
                                            boolean hasEXTMcFormats,
                                            boolean hasEXTFloat32,
                                            boolean hasEXTDouble)
        Returns a compatible AL buffer format given the AL channel layout and AL sample type.

        If hasEXTMcFormats or hasSOFTBufferSamples is true, it will be called to find the closest-matching format from AL_EXT_MCFORMATS or AL_SOFT_buffer_samples.

        Returns ALConstants.AL_NONE if no supported format can be found.

        Function is context independent.

        Parameters:
        alChannelLayout - AL channel layout, see getDefaultALChannelLayout(int)
        alSampleType - AL sample type, see getALSampleType(int, boolean, boolean).
        al - AL instance
        alExt - ALExt instance
        hasSOFTBufferSamples - true if having extension AL_SOFT_buffer_samples, otherwise false
        hasEXTMcFormats - true if having extension AL_EXT_MCFORMATS, otherwise false
        hasEXTFloat32 - true if having extension AL_EXT_FLOAT32, otherwise false
        hasEXTDouble - true if having extension AL_EXT_DOUBLE, otherwise false
        Returns:
        AL buffer format
      • getDefaultALChannelLayout

        public static final int getDefaultALChannelLayout​(int channelCount)
        Returns the default AL channel layout matching the given channel count, or ALConstants.AL_NONE.
        Parameters:
        channelCount - number of channels
        signed - true if signed number, false for unsigned
        fixedP - true for fixed point value, false for floating point value with a sampleSize of 32 (float) or 64 (double)
      • alChannelLayoutName

        public static final String alChannelLayoutName​(int alChannelLayout)
        Returns the readable name of the given AL channel layout
      • getALChannelLayoutChannelCount

        public static final int getALChannelLayoutChannelCount​(int alChannelLayout)
        Returns the channel count of the given AL channel layout
      • getALSampleType

        public static final int getALSampleType​(int sampleSize,
                                                boolean signed,
                                                boolean fixedP)
        Returns the AL sample type matching the given audio type attributes, or ALConstants.AL_NONE.
        Parameters:
        sampleSize - sample size in bits
        signed - true if signed number, false for unsigned
        fixedP - true for fixed point value, false for floating point value with a sampleSize of 32 (float) or 64 (double)
      • alSampleTypeName

        public static final String alSampleTypeName​(int alSampleType)
        Returns the readable name of the given AL sample type
      • isALSampleTypeSigned

        public static final boolean isALSampleTypeSigned​(int alSampleType)
        Returns whether the given AL sample type is signed
      • isALSampleTypeFixed

        public static final boolean isALSampleTypeFixed​(int alSampleType)
        Returns true if the given AL sample type is a fixed point (byte, short, int, ..) or false if a floating point type (float, double).
      • sizeOfALSampleType

        public static final int sizeOfALSampleType​(int alSampleType)
                                            throws IllegalArgumentException
        Returns the byte size of the given AL sample type
        Throws:
        IllegalArgumentException - for unknown alChannelLayout or alSampleType values.
      • samplesToByteCount

        public static final int samplesToByteCount​(int sampleCount,
                                                   int alChannelLayout,
                                                   int alSampleType)
                                            throws IllegalArgumentException
        Parameters:
        sampleCount - number of samples per channel
        alChannelLayout - AL channel layout
        alSampleType - AL sample type
        Returns:
        bytes count required
        Throws:
        IllegalArgumentException - for unknown alChannelLayout or alSampleType values.
      • bytesToSampleCount

        public static final int bytesToSampleCount​(int byteCount,
                                                   int alChannelLayout,
                                                   int alSampleType)