diff options
author | Chris Robinson <[email protected]> | 2012-01-10 02:12:54 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-01-10 02:12:54 -0800 |
commit | d4670faafdf7a44392a281b57d3c6933a6bc22ad (patch) | |
tree | abd9beaa599ae6eaf57e0639f2d0fa563868caee /examples/alhelpers.c | |
parent | e772fb7d0e1559915944de032c5fd0cb1370a8cf (diff) |
Fix compiling the example program, and support AL_SOFT_buffer_samples with it
Diffstat (limited to 'examples/alhelpers.c')
-rw-r--r-- | examples/alhelpers.c | 205 |
1 files changed, 149 insertions, 56 deletions
diff --git a/examples/alhelpers.c b/examples/alhelpers.c index ba23cabd..dbfe2383 100644 --- a/examples/alhelpers.c +++ b/examples/alhelpers.c @@ -41,13 +41,13 @@ const char *ChannelsName(ALenum chans) { switch(chans) { - case AL_MONO: return "Mono"; - case AL_STEREO: return "Stereo"; - case AL_REAR: return "Rear"; - case AL_QUAD: return "Quadraphonic"; - case AL_5POINT1: return "5.1 Surround"; - case AL_6POINT1: return "6.1 Surround"; - case AL_7POINT1: return "7.1 Surround"; + case AL_MONO_SOFT: return "Mono"; + case AL_STEREO_SOFT: return "Stereo"; + case AL_REAR_SOFT: return "Rear"; + case AL_QUAD_SOFT: return "Quadraphonic"; + case AL_5POINT1_SOFT: return "5.1 Surround"; + case AL_6POINT1_SOFT: return "6.1 Surround"; + case AL_7POINT1_SOFT: return "7.1 Surround"; } return "Unknown Channels"; } @@ -56,14 +56,14 @@ const char *TypeName(ALenum type) { switch(type) { - case AL_BYTE: return "S8"; - case AL_UNSIGNED_BYTE: return "U8"; - case AL_SHORT: return "S16"; - case AL_UNSIGNED_SHORT: return "U16"; - case AL_INT: return "S32"; - case AL_UNSIGNED_INT: return "U32"; - case AL_FLOAT: return "Float32"; - case AL_DOUBLE: return "Float64"; + case AL_BYTE_SOFT: return "S8"; + case AL_UNSIGNED_BYTE_SOFT: return "U8"; + case AL_SHORT_SOFT: return "S16"; + case AL_UNSIGNED_SHORT_SOFT: return "U16"; + case AL_INT_SOFT: return "S32"; + case AL_UNSIGNED_INT_SOFT: return "U32"; + case AL_FLOAT_SOFT: return "Float32"; + case AL_DOUBLE_SOFT: return "Float64"; } return "Unknown Type"; } @@ -73,25 +73,25 @@ ALsizei FramesToBytes(ALsizei size, ALenum channels, ALenum type) { switch(channels) { - case AL_MONO: size *= 1; break; - case AL_STEREO: size *= 2; break; - case AL_REAR: size *= 2; break; - case AL_QUAD: size *= 4; break; - case AL_5POINT1: size *= 6; break; - case AL_6POINT1: size *= 7; break; - case AL_7POINT1: size *= 8; break; + case AL_MONO_SOFT: size *= 1; break; + case AL_STEREO_SOFT: size *= 2; break; + case AL_REAR_SOFT: size *= 2; break; + case AL_QUAD_SOFT: size *= 4; break; + case AL_5POINT1_SOFT: size *= 6; break; + case AL_6POINT1_SOFT: size *= 7; break; + case AL_7POINT1_SOFT: size *= 8; break; } switch(type) { - case AL_BYTE: size *= sizeof(ALbyte); break; - case AL_UNSIGNED_BYTE: size *= sizeof(ALubyte); break; - case AL_SHORT: size *= sizeof(ALshort); break; - case AL_UNSIGNED_SHORT: size *= sizeof(ALushort); break; - case AL_INT: size *= sizeof(ALint); break; - case AL_UNSIGNED_INT: size *= sizeof(ALuint); break; - case AL_FLOAT: size *= sizeof(ALfloat); break; - case AL_DOUBLE: size *= sizeof(ALdouble); break; + case AL_BYTE_SOFT: size *= sizeof(ALbyte); break; + case AL_UNSIGNED_BYTE_SOFT: size *= sizeof(ALubyte); break; + case AL_SHORT_SOFT: size *= sizeof(ALshort); break; + case AL_UNSIGNED_SHORT_SOFT: size *= sizeof(ALushort); break; + case AL_INT_SOFT: size *= sizeof(ALint); break; + case AL_UNSIGNED_INT_SOFT: size *= sizeof(ALuint); break; + case AL_FLOAT_SOFT: size *= sizeof(ALfloat); break; + case AL_DOUBLE_SOFT: size *= sizeof(ALdouble); break; } return size; @@ -103,72 +103,154 @@ ALsizei BytesToFrames(ALsizei size, ALenum channels, ALenum type) } -ALenum GetFormat(ALenum channels, ALenum type) +ALenum GetFormat(ALenum channels, ALenum type, LPALISBUFFERFORMATSUPPORTEDSOFT palIsBufferFormatSupportedSOFT) { - ALenum format = 0; + ALenum format = AL_NONE; + + /* If using AL_SOFT_buffer_samples, try looking through its formats */ + if(palIsBufferFormatSupportedSOFT) + { + /* AL_SOFT_buffer_samples is more lenient with matching formats. The + * specified sample type does not need to match the returned format, + * but it is nice to try to get something close. */ + if(type == AL_UNSIGNED_BYTE_SOFT || type == AL_BYTE_SOFT) + { + if(channels == AL_MONO_SOFT) format = AL_MONO8_SOFT; + else if(channels == AL_STEREO_SOFT) format = AL_STEREO8_SOFT; + else if(channels == AL_QUAD_SOFT) format = AL_QUAD8_SOFT; + else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_8_SOFT; + else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_8_SOFT; + else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_8_SOFT; + } + else if(type == AL_UNSIGNED_SHORT_SOFT || type == AL_SHORT_SOFT) + { + if(channels == AL_MONO_SOFT) format = AL_MONO16_SOFT; + else if(channels == AL_STEREO_SOFT) format = AL_STEREO16_SOFT; + else if(channels == AL_QUAD_SOFT) format = AL_QUAD16_SOFT; + else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_16_SOFT; + else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_16_SOFT; + else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_16_SOFT; + } + else if(type == AL_UNSIGNED_BYTE3_SOFT || type == AL_BYTE3_SOFT || + type == AL_UNSIGNED_INT_SOFT || type == AL_INT_SOFT || + type == AL_FLOAT_SOFT || type == AL_DOUBLE_SOFT) + { + if(channels == AL_MONO_SOFT) format = AL_MONO32F_SOFT; + else if(channels == AL_STEREO_SOFT) format = AL_STEREO32F_SOFT; + else if(channels == AL_QUAD_SOFT) format = AL_QUAD32F_SOFT; + else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_32F_SOFT; + else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_32F_SOFT; + else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_32F_SOFT; + } + + if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format)) + format = AL_NONE; + + /* A matching format was not found or supported. Try 32-bit float. */ + if(format == AL_NONE) + { + if(channels == AL_MONO_SOFT) format = AL_MONO32F_SOFT; + else if(channels == AL_STEREO_SOFT) format = AL_STEREO32F_SOFT; + else if(channels == AL_QUAD_SOFT) format = AL_QUAD32F_SOFT; + else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_32F_SOFT; + else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_32F_SOFT; + else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_32F_SOFT; + + if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format)) + format = AL_NONE; + } + /* 32-bit float not supported. Try 16-bit int. */ + if(format == AL_NONE) + { + if(channels == AL_MONO_SOFT) format = AL_MONO16_SOFT; + else if(channels == AL_STEREO_SOFT) format = AL_STEREO16_SOFT; + else if(channels == AL_QUAD_SOFT) format = AL_QUAD16_SOFT; + else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_16_SOFT; + else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_16_SOFT; + else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_16_SOFT; + + if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format)) + format = AL_NONE; + } + /* 16-bit int not supported. Try 8-bit int. */ + if(format == AL_NONE) + { + if(channels == AL_MONO_SOFT) format = AL_MONO8_SOFT; + else if(channels == AL_STEREO_SOFT) format = AL_STEREO8_SOFT; + else if(channels == AL_QUAD_SOFT) format = AL_QUAD8_SOFT; + else if(channels == AL_5POINT1_SOFT) format = AL_5POINT1_8_SOFT; + else if(channels == AL_6POINT1_SOFT) format = AL_6POINT1_8_SOFT; + else if(channels == AL_7POINT1_SOFT) format = AL_7POINT1_8_SOFT; + + if(format != AL_NONE && !palIsBufferFormatSupportedSOFT(format)) + format = AL_NONE; + } + + return format; + } /* We use the AL_EXT_MCFORMATS extension to provide output of Quad, 5.1, * and 7.1 channel configs, AL_EXT_FLOAT32 for 32-bit float samples, and * AL_EXT_DOUBLE for 64-bit float samples. */ - if(type == AL_UNSIGNED_BYTE) + if(type == AL_UNSIGNED_BYTE_SOFT) { - if(channels == AL_MONO) + if(channels == AL_MONO_SOFT) format = AL_FORMAT_MONO8; - else if(channels == AL_STEREO) + else if(channels == AL_STEREO_SOFT) format = AL_FORMAT_STEREO8; else if(alIsExtensionPresent("AL_EXT_MCFORMATS")) { - if(channels == AL_QUAD) + if(channels == AL_QUAD_SOFT) format = alGetEnumValue("AL_FORMAT_QUAD8"); - else if(channels == AL_5POINT1) + else if(channels == AL_5POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_51CHN8"); - else if(channels == AL_6POINT1) + else if(channels == AL_6POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_61CHN8"); - else if(channels == AL_7POINT1) + else if(channels == AL_7POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_71CHN8"); } } - else if(type == AL_SHORT) + else if(type == AL_SHORT_SOFT) { - if(channels == AL_MONO) + if(channels == AL_MONO_SOFT) format = AL_FORMAT_MONO16; - else if(channels == AL_STEREO) + else if(channels == AL_STEREO_SOFT) format = AL_FORMAT_STEREO16; else if(alIsExtensionPresent("AL_EXT_MCFORMATS")) { - if(channels == AL_QUAD) + if(channels == AL_QUAD_SOFT) format = alGetEnumValue("AL_FORMAT_QUAD16"); - else if(channels == AL_5POINT1) + else if(channels == AL_5POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_51CHN16"); - else if(channels == AL_6POINT1) + else if(channels == AL_6POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_61CHN16"); - else if(channels == AL_7POINT1) + else if(channels == AL_7POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_71CHN16"); } } - else if(type == AL_FLOAT && alIsExtensionPresent("AL_EXT_FLOAT32")) + else if(type == AL_FLOAT_SOFT && alIsExtensionPresent("AL_EXT_FLOAT32")) { - if(channels == AL_MONO) + if(channels == AL_MONO_SOFT) format = alGetEnumValue("AL_FORMAT_MONO_FLOAT32"); - else if(channels == AL_STEREO) + else if(channels == AL_STEREO_SOFT) format = alGetEnumValue("AL_FORMAT_STEREO_FLOAT32"); else if(alIsExtensionPresent("AL_EXT_MCFORMATS")) { - if(channels == AL_QUAD) + if(channels == AL_QUAD_SOFT) format = alGetEnumValue("AL_FORMAT_QUAD32"); - else if(channels == AL_5POINT1) + else if(channels == AL_5POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_51CHN32"); - else if(channels == AL_6POINT1) + else if(channels == AL_6POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_61CHN32"); - else if(channels == AL_7POINT1) + else if(channels == AL_7POINT1_SOFT) format = alGetEnumValue("AL_FORMAT_71CHN32"); } } - else if(type == AL_DOUBLE && alIsExtensionPresent("AL_EXT_DOUBLE")) + else if(type == AL_DOUBLE_SOFT && alIsExtensionPresent("AL_EXT_DOUBLE")) { - if(channels == AL_MONO) + if(channels == AL_MONO_SOFT) format = alGetEnumValue("AL_FORMAT_MONO_DOUBLE"); - else if(channels == AL_STEREO) + else if(channels == AL_STEREO_SOFT) format = alGetEnumValue("AL_FORMAT_STEREO_DOUBLE"); } @@ -181,6 +263,17 @@ ALenum GetFormat(ALenum channels, ALenum type) } +void AL_APIENTRY wrap_BufferSamples(ALuint buffer, ALuint samplerate, + ALenum internalformat, ALsizei samples, + ALenum channels, ALenum type, + const ALvoid *data) +{ + alBufferData(buffer, internalformat, data, + FramesToBytes(samples, channels, type), + samplerate); +} + + int InitAL(void) { ALCdevice *device; |