From d5daaaab3544d9af49056f57a1fcf53abef17deb Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * The resulting {@link AudioFormat} uses {@link AudioFormat#planar} = false and {@link AudioFormat#littleEndian} = true.
+ * hasSOFTBufferSamples
is true,
+ * Returns a compatible AL buffer format given the {@link 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_SOFT_buffer_samples
.
+ * AL_EXT_MCFORMATS
or AL_SOFT_buffer_samples
.
+ *
* Returns {@link ALConstants#AL_NONE} if no supported format can be found. *
+ *+ * Function uses {@link AL#alIsExtensionPresent(String)}, which might be context dependent, + * otherwise function is context independent. + *
* - * @param alChannelLayout AL channel layout, see {@link #getDefaultALChannelLayout(int)} - * @param alSampleType AL sample type, see {@link #getALSampleType(int, boolean, boolean)}. + * @param audioFormat used to derive AL channel layout {@link #getDefaultALChannelLayout(int)} + * and AL sample type {@link #getALSampleType(int, boolean, boolean)} + * @param al AL instance + * @param alExt ALExt instance + * @return AL buffer format + */ + public static int getALFormat(final AudioFormat audioFormat, + final AL al, final ALExt alExt) { + final int alChannelLayout = ALHelpers.getDefaultALChannelLayout(audioFormat.channelCount); + final int alSampleType = ALHelpers.getALSampleType(audioFormat.sampleSize, audioFormat.signed, audioFormat.fixedP); + if( ALConstants.AL_NONE != alChannelLayout && ALConstants.AL_NONE != alSampleType ) { + return ALHelpers.getALFormat(alChannelLayout, alSampleType, al, alExt); + } else { + return ALConstants.AL_NONE; + } + } + + /** + * Returns a compatible AL buffer format given the {@link 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 {@link ALConstants#AL_NONE} if no supported format can be found. + *
+ *+ * Function is context independent. + *
+ * + * @param audioFormat used to derive AL channel layout {@link #getDefaultALChannelLayout(int)} + * and AL sample type {@link #getALSampleType(int, boolean, boolean)} + * @param al AL instance + * @param alExt ALExt instance * @param hasSOFTBufferSamples true if having extensionAL_SOFT_buffer_samples
, otherwise false
* @param hasEXTMcFormats true if having extension AL_EXT_MCFORMATS
, otherwise false
* @param hasEXTFloat32 true if having extension AL_EXT_FLOAT32
, otherwise false
* @param hasEXTDouble true if having extension AL_EXT_DOUBLE
, otherwise false
+ * @return AL buffer format
+ */
+ public static int getALFormat(final AudioFormat audioFormat,
+ final AL al, final ALExt alExt,
+ final boolean hasSOFTBufferSamples,
+ final boolean hasEXTMcFormats,
+ final boolean hasEXTFloat32, final boolean hasEXTDouble) {
+ final int alChannelLayout = ALHelpers.getDefaultALChannelLayout(audioFormat.channelCount);
+ final int alSampleType = ALHelpers.getALSampleType(audioFormat.sampleSize, audioFormat.signed, audioFormat.fixedP);
+ final int alFormat;
+ if( ALConstants.AL_NONE != alChannelLayout && ALConstants.AL_NONE != alSampleType ) {
+ alFormat = ALHelpers.getALFormat(alChannelLayout, alSampleType, al, alExt,
+ hasSOFTBufferSamples, hasEXTMcFormats,
+ hasEXTFloat32, hasEXTDouble);
+ } else {
+ alFormat = ALConstants.AL_NONE;
+ }
+ return alFormat;
+ }
+
+ /**
+ * 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 {@link ALConstants#AL_NONE} if no supported format can be found. + *
+ *+ * Function uses {@link AL#alIsExtensionPresent(String)}, which might be context dependent, + * otherwise function is context independent. + *
+ * + * @param alChannelLayout AL channel layout, see {@link #getDefaultALChannelLayout(int)} + * @param alSampleType AL sample type, see {@link #getALSampleType(int, boolean, boolean)}. * @param al AL instance * @param alExt ALExt instance * @return AL buffer format */ public static final int getALFormat(final int alChannelLayout, final int alSampleType, + final AL al, final ALExt alExt) { + final boolean hasSOFTBufferSamples = al.alIsExtensionPresent(AL_SOFT_buffer_samples); + final boolean hasEXTMcFormats = al.alIsExtensionPresent(AL_EXT_MCFORMATS); + final boolean hasEXTFloat32 = al.alIsExtensionPresent(AL_EXT_FLOAT32); + final boolean hasEXTDouble = al.alIsExtensionPresent(AL_EXT_DOUBLE); + return ALHelpers.getALFormat(alChannelLayout, alSampleType, al, alExt, + hasSOFTBufferSamples, hasEXTMcFormats, + hasEXTFloat32, 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 {@link ALConstants#AL_NONE} if no supported format can be found. + *
+ *+ * Function is context independent. + *
+ * + * @param alChannelLayout AL channel layout, see {@link #getDefaultALChannelLayout(int)} + * @param alSampleType AL sample type, see {@link #getALSampleType(int, boolean, boolean)}. + * @param al AL instance + * @param alExt ALExt instance + * @param hasSOFTBufferSamples true if having extensionAL_SOFT_buffer_samples
, otherwise false
+ * @param hasEXTMcFormats true if having extension AL_EXT_MCFORMATS
, otherwise false
+ * @param hasEXTFloat32 true if having extension AL_EXT_FLOAT32
, otherwise false
+ * @param hasEXTDouble true if having extension AL_EXT_DOUBLE
, otherwise false
+ * @return AL buffer format
+ */
+ public static final int getALFormat(final int alChannelLayout, final int alSampleType,
+ final AL al, final ALExt alExt,
final boolean hasSOFTBufferSamples,
final boolean hasEXTMcFormats,
- final boolean hasEXTFloat32,
- final boolean hasEXTDouble,
- final AL al, final ALExt alExt) {
+ final boolean hasEXTFloat32, final boolean hasEXTDouble) {
int format = AL_NONE;
/* If using AL_SOFT_buffer_samples, try looking through its formats */
@@ -261,6 +410,22 @@ public class ALHelpers {
return "Unknown AL-Channel-Layout 0x"+Integer.toHexString(alChannelLayout);
}
+ /**
+ * Returns the channel count of the given AL channel layout
+ */
+ public static final int getALChannelLayoutChannelCount(final int alChannelLayout) {
+ switch(alChannelLayout) {
+ case AL_MONO_SOFT: return 1;
+ case AL_STEREO_SOFT: return 2;
+ case AL_REAR_SOFT: return 2;
+ case AL_QUAD_SOFT: return 4;
+ case AL_5POINT1_SOFT: return 6;
+ case AL_6POINT1_SOFT: return 7;
+ case AL_7POINT1_SOFT: return 8;
+ }
+ return 0;
+ }
+
/**
* Returns the AL sample type matching the given audio type attributes, or {@link ALConstants#AL_NONE}.
* @param sampleSize sample size in bits
@@ -310,6 +475,45 @@ public class ALHelpers {
return "Unknown AL-Type 0x"+Integer.toHexString(alSampleType);
}
+ /**
+ * Returns whether the given AL sample type is signed
+ */
+ public static final boolean isALSampleTypeSigned(final int alSampleType) {
+ switch(alSampleType) {
+ case AL_BYTE_SOFT:
+ case AL_SHORT_SOFT:
+ case AL_INT_SOFT:
+ case AL_FLOAT_SOFT:
+ case AL_DOUBLE_SOFT:
+ return true;
+ case AL_UNSIGNED_BYTE_SOFT:
+ case AL_UNSIGNED_SHORT_SOFT:
+ case AL_UNSIGNED_INT_SOFT:
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Returns true if the given AL sample type is a fixed point (byte, short, int, ..)
+ * or false if a floating point type (float, double).
+ */
+ public static final boolean isALSampleTypeFixed(final int alSampleType) {
+ switch(alSampleType) {
+ case AL_BYTE_SOFT:
+ case AL_SHORT_SOFT:
+ case AL_INT_SOFT:
+ case AL_UNSIGNED_BYTE_SOFT:
+ case AL_UNSIGNED_SHORT_SOFT:
+ case AL_UNSIGNED_INT_SOFT:
+ return true;
+ case AL_FLOAT_SOFT:
+ case AL_DOUBLE_SOFT:
+ default:
+ return false;
+ }
+ }
+
/**
* Returns the byte size of the given AL sample type
* @throws IllegalArgumentException for unknown alChannelLayout
or alSampleType
values.
--
cgit v1.2.3