25package com.jogamp.openal.util;
27import com.jogamp.openal.AL;
28import com.jogamp.openal.ALConstants;
29import static com.jogamp.openal.ALConstants.*;
30import com.jogamp.openal.ALExt;
31import static com.jogamp.openal.ALExtConstants.*;
33import com.jogamp.common.av.AudioFormat;
75 public static AudioFormat
getAudioFormat(
final int alChannelLayout,
final int alSampleType,
final int alFormat,
76 final int sampleRate,
final int sampleSize) {
82 if( 0 == channelCount ) {
87 return new AudioFormat(sampleRate, sampleSize, channelCount,
signed, fixedP,
115 final AL al,
final ALExt alExt) {
152 final AL al,
final ALExt alExt,
153 final boolean hasSOFTBufferSamples,
154 final boolean hasEXTMcFormats,
155 final boolean hasEXTFloat32,
final boolean hasEXTDouble) {
161 hasSOFTBufferSamples, hasEXTMcFormats,
162 hasEXTFloat32, hasEXTDouble);
190 public static final int getALFormat(
final int alChannelLayout,
final int alSampleType,
191 final AL al,
final ALExt alExt) {
197 hasSOFTBufferSamples, hasEXTMcFormats,
198 hasEXTFloat32, hasEXTDouble);
225 public static final int getALFormat(
final int alChannelLayout,
final int alSampleType,
226 final AL al,
final ALExt alExt,
227 final boolean hasSOFTBufferSamples,
228 final boolean hasEXTMcFormats,
229 final boolean hasEXTFloat32,
final boolean hasEXTDouble) {
230 int format = AL_NONE;
233 if(hasSOFTBufferSamples)
238 if(alSampleType == AL_UNSIGNED_BYTE_SOFT || alSampleType == AL_BYTE_SOFT)
240 if(alChannelLayout == AL_MONO_SOFT) format = AL_MONO8_SOFT;
241 else if(alChannelLayout == AL_STEREO_SOFT) format = AL_STEREO8_SOFT;
242 else if(alChannelLayout == AL_QUAD_SOFT) format = AL_QUAD8_SOFT;
243 else if(alChannelLayout == AL_5POINT1_SOFT) format = AL_5POINT1_8_SOFT;
244 else if(alChannelLayout == AL_6POINT1_SOFT) format = AL_6POINT1_8_SOFT;
245 else if(alChannelLayout == AL_7POINT1_SOFT) format = AL_7POINT1_8_SOFT;
247 else if(alSampleType == AL_UNSIGNED_SHORT_SOFT || alSampleType == AL_SHORT_SOFT)
249 if(alChannelLayout == AL_MONO_SOFT) format = AL_MONO16_SOFT;
250 else if(alChannelLayout == AL_STEREO_SOFT) format = AL_STEREO16_SOFT;
251 else if(alChannelLayout == AL_QUAD_SOFT) format = AL_QUAD16_SOFT;
252 else if(alChannelLayout == AL_5POINT1_SOFT) format = AL_5POINT1_16_SOFT;
253 else if(alChannelLayout == AL_6POINT1_SOFT) format = AL_6POINT1_16_SOFT;
254 else if(alChannelLayout == AL_7POINT1_SOFT) format = AL_7POINT1_16_SOFT;
256 else if(alSampleType == AL_UNSIGNED_BYTE3_SOFT || alSampleType == AL_BYTE3_SOFT ||
257 alSampleType == AL_UNSIGNED_INT_SOFT || alSampleType == AL_INT_SOFT ||
258 alSampleType == AL_FLOAT_SOFT || alSampleType == AL_DOUBLE_SOFT)
260 if(alChannelLayout == AL_MONO_SOFT) format = AL_MONO32F_SOFT;
261 else if(alChannelLayout == AL_STEREO_SOFT) format = AL_STEREO32F_SOFT;
262 else if(alChannelLayout == AL_QUAD_SOFT) format = AL_QUAD32F_SOFT;
263 else if(alChannelLayout == AL_5POINT1_SOFT) format = AL_5POINT1_32F_SOFT;
264 else if(alChannelLayout == AL_6POINT1_SOFT) format = AL_6POINT1_32F_SOFT;
265 else if(alChannelLayout == AL_7POINT1_SOFT) format = AL_7POINT1_32F_SOFT;
272 if(format == AL_NONE)
274 if(alChannelLayout == AL_MONO_SOFT) format = AL_MONO32F_SOFT;
275 else if(alChannelLayout == AL_STEREO_SOFT) format = AL_STEREO32F_SOFT;
276 else if(alChannelLayout == AL_QUAD_SOFT) format = AL_QUAD32F_SOFT;
277 else if(alChannelLayout == AL_5POINT1_SOFT) format = AL_5POINT1_32F_SOFT;
278 else if(alChannelLayout == AL_6POINT1_SOFT) format = AL_6POINT1_32F_SOFT;
279 else if(alChannelLayout == AL_7POINT1_SOFT) format = AL_7POINT1_32F_SOFT;
285 if(format == AL_NONE)
287 if(alChannelLayout == AL_MONO_SOFT) format = AL_MONO16_SOFT;
288 else if(alChannelLayout == AL_STEREO_SOFT) format = AL_STEREO16_SOFT;
289 else if(alChannelLayout == AL_QUAD_SOFT) format = AL_QUAD16_SOFT;
290 else if(alChannelLayout == AL_5POINT1_SOFT) format = AL_5POINT1_16_SOFT;
291 else if(alChannelLayout == AL_6POINT1_SOFT) format = AL_6POINT1_16_SOFT;
292 else if(alChannelLayout == AL_7POINT1_SOFT) format = AL_7POINT1_16_SOFT;
298 if(format == AL_NONE)
300 if(alChannelLayout == AL_MONO_SOFT) format = AL_MONO8_SOFT;
301 else if(alChannelLayout == AL_STEREO_SOFT) format = AL_STEREO8_SOFT;
302 else if(alChannelLayout == AL_QUAD_SOFT) format = AL_QUAD8_SOFT;
303 else if(alChannelLayout == AL_5POINT1_SOFT) format = AL_5POINT1_8_SOFT;
304 else if(alChannelLayout == AL_6POINT1_SOFT) format = AL_6POINT1_8_SOFT;
305 else if(alChannelLayout == AL_7POINT1_SOFT) format = AL_7POINT1_8_SOFT;
317 if(alSampleType == AL_UNSIGNED_BYTE_SOFT)
319 if(alChannelLayout == AL_MONO_SOFT)
320 format = AL_FORMAT_MONO8;
321 else if(alChannelLayout == AL_STEREO_SOFT)
322 format = AL_FORMAT_STEREO8;
323 else if( hasEXTMcFormats )
325 if(alChannelLayout == AL_QUAD_SOFT)
326 format = AL_FORMAT_QUAD8;
327 else if(alChannelLayout == AL_5POINT1_SOFT)
328 format = AL_FORMAT_51CHN8;
329 else if(alChannelLayout == AL_6POINT1_SOFT)
330 format = AL_FORMAT_61CHN8;
331 else if(alChannelLayout == AL_7POINT1_SOFT)
332 format = AL_FORMAT_71CHN8;
335 else if(alSampleType == AL_SHORT_SOFT)
337 if(alChannelLayout == AL_MONO_SOFT)
338 format = AL_FORMAT_MONO16;
339 else if(alChannelLayout == AL_STEREO_SOFT)
340 format = AL_FORMAT_STEREO16;
341 else if( hasEXTMcFormats )
343 if(alChannelLayout == AL_QUAD_SOFT)
344 format = AL_FORMAT_QUAD16;
345 else if(alChannelLayout == AL_5POINT1_SOFT)
346 format = AL_FORMAT_51CHN16;
347 else if(alChannelLayout == AL_6POINT1_SOFT)
348 format = AL_FORMAT_61CHN16;
349 else if(alChannelLayout == AL_7POINT1_SOFT)
350 format = AL_FORMAT_71CHN16;
353 else if(alSampleType == AL_FLOAT_SOFT && hasEXTFloat32)
355 if(alChannelLayout == AL_MONO_SOFT)
356 format = AL_FORMAT_MONO_FLOAT32;
357 else if(alChannelLayout == AL_STEREO_SOFT)
358 format = AL_FORMAT_STEREO_FLOAT32;
359 else if( hasEXTMcFormats )
361 if(alChannelLayout == AL_QUAD_SOFT)
362 format = AL_FORMAT_QUAD32;
363 else if(alChannelLayout == AL_5POINT1_SOFT)
364 format = AL_FORMAT_51CHN32;
365 else if(alChannelLayout == AL_6POINT1_SOFT)
366 format = AL_FORMAT_61CHN32;
367 else if(alChannelLayout == AL_7POINT1_SOFT)
368 format = AL_FORMAT_71CHN32;
371 else if(alSampleType == AL_DOUBLE_SOFT && hasEXTDouble)
373 if(alChannelLayout == AL_MONO_SOFT)
374 format = AL_FORMAT_MONO_DOUBLE_EXT;
375 else if(alChannelLayout == AL_STEREO_SOFT) {
376 format = AL_FORMAT_STEREO_DOUBLE_EXT;
396 switch(channelCount) {
397 case 1:
return AL_MONO_SOFT;
398 case 2:
return AL_STEREO_SOFT;
400 case 4:
return AL_QUAD_SOFT;
401 case 6:
return AL_5POINT1_SOFT;
402 case 7:
return AL_6POINT1_SOFT;
403 case 8:
return AL_7POINT1_SOFT;
412 switch(alChannelLayout) {
413 case AL_MONO_SOFT:
return "Mono";
414 case AL_STEREO_SOFT:
return "Stereo";
415 case AL_REAR_SOFT:
return "Rear";
416 case AL_QUAD_SOFT:
return "Quad";
417 case AL_5POINT1_SOFT:
return "5.1";
418 case AL_6POINT1_SOFT:
return "6.1";
419 case AL_7POINT1_SOFT:
return "7.1";
421 return "Unknown AL-Channel-Layout 0x"+Integer.toHexString(alChannelLayout);
428 switch(alChannelLayout) {
429 case AL_MONO_SOFT:
return 1;
430 case AL_STEREO_SOFT:
return 2;
431 case AL_REAR_SOFT:
return 2;
432 case AL_QUAD_SOFT:
return 4;
433 case AL_5POINT1_SOFT:
return 6;
434 case AL_6POINT1_SOFT:
return 7;
435 case AL_7POINT1_SOFT:
return 8;
446 public static final int getALSampleType(
final int sampleSize,
final boolean signed,
final boolean fixedP) {
449 switch( sampleSize ) {
450 case 8:
return AL_BYTE_SOFT;
451 case 16:
return AL_SHORT_SOFT;
452 case 32:
return AL_INT_SOFT;
455 switch( sampleSize ) {
456 case 8:
return AL_UNSIGNED_BYTE_SOFT;
457 case 16:
return AL_UNSIGNED_SHORT_SOFT;
458 case 32:
return AL_UNSIGNED_INT_SOFT;
463 switch( sampleSize ) {
464 case 32:
return AL_FLOAT_SOFT;
465 case 64:
return AL_DOUBLE_SOFT;
476 switch(alSampleType) {
477 case AL_BYTE_SOFT:
return "s8";
478 case AL_UNSIGNED_BYTE_SOFT:
return "u8";
479 case AL_SHORT_SOFT:
return "s16";
480 case AL_UNSIGNED_SHORT_SOFT:
return "u16";
481 case AL_INT_SOFT:
return "s32";
482 case AL_UNSIGNED_INT_SOFT:
return "u32";
483 case AL_FLOAT_SOFT:
return "f32";
484 case AL_DOUBLE_SOFT:
return "f64";
486 return "Unknown AL-Type 0x"+Integer.toHexString(alSampleType);
493 switch(alSampleType) {
500 case AL_UNSIGNED_BYTE_SOFT:
501 case AL_UNSIGNED_SHORT_SOFT:
502 case AL_UNSIGNED_INT_SOFT:
513 switch(alSampleType) {
517 case AL_UNSIGNED_BYTE_SOFT:
518 case AL_UNSIGNED_SHORT_SOFT:
519 case AL_UNSIGNED_INT_SOFT:
533 switch(alSampleType) {
535 case AL_UNSIGNED_BYTE_SOFT:
538 case AL_UNSIGNED_SHORT_SOFT:
541 case AL_UNSIGNED_INT_SOFT:
547 throw new IllegalArgumentException(
"Unknown al-type 0x"+Integer.toHexString(alSampleType));
558 public static final int samplesToByteCount(
int sampleCount,
final int alChannelLayout,
final int alSampleType)
559 throws IllegalArgumentException
561 switch(alChannelLayout) {
562 case AL_MONO_SOFT: sampleCount *= 1;
break;
563 case AL_STEREO_SOFT: sampleCount *= 2;
break;
564 case AL_REAR_SOFT: sampleCount *= 2;
break;
565 case AL_QUAD_SOFT: sampleCount *= 4;
break;
566 case AL_5POINT1_SOFT: sampleCount *= 6;
break;
567 case AL_6POINT1_SOFT: sampleCount *= 7;
break;
568 case AL_7POINT1_SOFT: sampleCount *= 8;
break;
569 default:
throw new IllegalArgumentException(
"Unknown al-channel-layout 0x"+Integer.toHexString(alChannelLayout));
572 switch(alSampleType) {
574 case AL_UNSIGNED_BYTE_SOFT:
577 case AL_UNSIGNED_SHORT_SOFT:
581 case AL_UNSIGNED_INT_SOFT:
589 throw new IllegalArgumentException(
"Unknown al-type 0x"+Integer.toHexString(alSampleType));
595 public static final int bytesToSampleCount(
final int byteCount,
final int alChannelLayout,
final int alSampleType) {
601 switch( sourceState ) {
602 case AL_INITIAL:
return "initial";
603 case AL_PLAYING:
return "playing";
604 case AL_PAUSED:
return "paused";
605 case AL_STOPPED:
return "stopped";
606 default:
return "invalid";
static int getALFormat(final AudioFormat audioFormat, final AL al, final ALExt alExt)
Returns a compatible AL buffer format given the AudioFormat, which determines the AL channel layout a...
static final String ALC_EXT_debug
static final String alChannelLayoutName(final int alChannelLayout)
Returns the readable name of the given AL channel layout.
static final String AL_SOFT_events
static final String AL_EXT_DOUBLE
static final String ALC_EXT_thread_local_context
static final int sizeOfALSampleType(final int alSampleType)
Returns the byte size of the given AL sample type.
static final String ALC_ENUMERATION_EXT
static final String AL_SOFT_buffer_samples
openal-soft >= 1.18.0
static int getALFormat(final AudioFormat audioFormat, final AL al, final ALExt alExt, final boolean hasSOFTBufferSamples, final boolean hasEXTMcFormats, final boolean hasEXTFloat32, final boolean hasEXTDouble)
Returns a compatible AL buffer format given the AudioFormat, which determines the AL channel layout a...
static final String ALC_ENUMERATE_ALL_EXT
static final int getALChannelLayoutChannelCount(final int alChannelLayout)
Returns the channel count of the given AL channel layout.
static final int getALFormat(final int alChannelLayout, final int alSampleType, final AL al, final ALExt alExt)
Returns a compatible AL buffer format given the AL channel layout and AL sample type.
static final String alSampleTypeName(final int alSampleType)
Returns the readable name of the given AL sample type.
static final boolean isALSampleTypeSigned(final int alSampleType)
Returns whether the given AL sample type is signed.
static final boolean isALSampleTypeFixed(final int alSampleType)
Returns true if the given AL sample type is a fixed point (byte, short, int, ..) or false if a floati...
static final String AL_EXT_MCFORMATS
static final String alSourceStateString(final int sourceState)
Returns given ALConstants#AL_SOURCE_STATE AL#alGetSourcei(int, int, int[], int)} value as a string.
static final int samplesToByteCount(int sampleCount, final int alChannelLayout, final int alSampleType)
static final String AL_EXT_FLOAT32
static final String AL_EXT_debug
static final String ALC_SOFT_system_events
static AudioFormat getAudioFormat(final int alChannelLayout, final int alSampleType, final int alFormat, final int sampleRate, final int sampleSize)
Returns a compatible AudioFormat based on given OpenAL channel-layout, sample-type and format,...
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)
Returns a compatible AL buffer format given the AL channel layout and AL sample type.
static final int getDefaultALChannelLayout(final int channelCount)
Returns the default AL channel layout matching the given channel count, or ALConstants#AL_NONE.
static final int bytesToSampleCount(final int byteCount, final int alChannelLayout, final int alSampleType)
static final int getALSampleType(final int sampleSize, final boolean signed, final boolean fixedP)
Returns the AL sample type matching the given audio type attributes, or ALConstants#AL_NONE.
static final int AL_NONE
Define "AL_NONE" with expression '0', CType: int.
boolean alIsBufferFormatSupportedSOFT(int format)
Entry point (through function pointer) to C language function: ALboolean alIsBufferFormatSupportedS...
boolean alIsExtensionPresent(String extname)
Entry point (through function pointer) to C language function: ALboolean alIsExtensionPresent(const...