From 86a86b06a20208aef652da0af184349312f576c0 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Fri, 27 May 2016 11:58:01 +0200 Subject: [PATCH] Switch to out own audio format defines --- simgear/sound/readwav.cxx | 30 ++++++++-------------- simgear/sound/sample_openal.cxx | 42 ------------------------------- simgear/sound/sample_openal.hxx | 8 ------ simgear/sound/soundmgr_openal.cxx | 8 ++++-- 4 files changed, 16 insertions(+), 72 deletions(-) diff --git a/simgear/sound/readwav.cxx b/simgear/sound/readwav.cxx index ec1e597b..30429bd2 100644 --- a/simgear/sound/readwav.cxx +++ b/simgear/sound/readwav.cxx @@ -30,12 +30,14 @@ #include #include +#include "sample_openal.hxx" + namespace { class Buffer { public: ALvoid* data; - ALenum format; + unsigned int format; ALsizei length; ALfloat frequency; SGPath path; @@ -50,24 +52,12 @@ namespace } }; - ALenum formatConstruct(ALint numChannels, ALint bitsPerSample) + unsigned int formatConstruct(ALint numChannels, ALint bitsPerSample) { - switch (numChannels) - { - case 1: - switch (bitsPerSample) { - case 8: return AL_FORMAT_MONO8; - case 16: return AL_FORMAT_MONO16; - } - break; - case 2: - switch (bitsPerSample) { - case 8: return AL_FORMAT_STEREO8; - case 16: return AL_FORMAT_STEREO16; - } - break; - } - return AL_NONE; + unsigned int rv = 0; + if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MONO8; + if (numChannels == 1 && bitsPerSample == 16) rv = SG_SAMPLE_MONO16; + return rv; } // function prototype for decoding audio data @@ -255,7 +245,7 @@ namespace namespace simgear { -ALvoid* loadWAVFromFile(const SGPath& path, ALenum& format, ALsizei& size, ALfloat& freqf) +ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size, ALfloat& freqf) { if (!path.exists()) { throw sg_io_exception("loadWAVFromFile: file not found", path); @@ -285,7 +275,7 @@ ALuint createBufferFromFile(const SGPath& path) { ALuint buffer = -1; #ifdef ENABLE_SOUND - ALenum format; + unsigned int format; ALsizei size; ALfloat sampleFrequency; ALvoid* data = loadWAVFromFile(path, format, size, sampleFrequency); diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 4abd27e0..0c613d52 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -82,48 +82,6 @@ SGSoundSampleInfo::SGSoundSampleInfo() : _pos_prop[2] = 0; } -void SGSoundSample::set_format_AL( int fmt ) -{ - switch(fmt) - { - case AL_FORMAT_MONO8: - _tracks = 1; _bits = 8; _compressed = false; - break; - case AL_FORMAT_MONO16: - _tracks = 1; _bits = 16; _compressed = false; - break; -#ifdef AL_EXT_MULAW_MCFORMATS - case AL_FORMAT_MONO_MULAW: - _tracks = 1; _bits = 8; _compressed = true; - break; -#endif -#ifdef AL_EXT_IMA4 - case AL_EXT_IMA4: - _tracks = 1; _bits = 4; _compressed = true; - break; -#endif - default: - break; - } -} - -unsigned int SGSoundSampleInfo::get_format_AL() -{ - unsigned int rv = AL_FORMAT_MONO16; - - if (_tracks == 1 && _bits == 8) rv = AL_FORMAT_MONO8; -#ifdef AL_EXT_MULAW_MCFORMATS - else if (_tracks == 1 && _bits == 8 && _compressed) - rv = AL_FORMAT_MONO_MULAW; -#endif -#ifdef AL_EXT_IMA4 - else if (_tracks == 1 && _bits == 4 && _compressed) - rv = AL_EXT_IMA4; -#endif - - return rv; -} - std::string SGSoundSampleInfo::random_string() { static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz" diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 286379fa..91e2b2ac 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -61,12 +61,6 @@ public: SGSoundSampleInfo(); ~SGSoundSampleInfo() {} - /** - * Returns the format of this audio sample. - * @return SimGear format-id - */ - unsigned int get_format_AL(); - /** * Returns the format of this audio sample. * @return SimGear format-id @@ -438,8 +432,6 @@ public: _tracks = fmt & 0x3; _bits = fmt & 0x1C; _compressed = fmt & 0x100; } - void set_format_AL( int fmt ); - /** * Set the frequency (in Herz) of this audio sample. * @param freq Frequency diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index d4c62582..a931cd0d 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -550,7 +550,7 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample) } sample->set_frequency( freq ); - sample->set_format_AL( format ); + sample->set_format( format ); sample->set_size( size ); } else { @@ -562,7 +562,11 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample) if ( !testForALError("generate buffer") ) { // Copy data to the internal OpenAL buffer - ALenum format = sample->get_format_AL(); + ALenum format = AL_NONE; + unsigned int fmt = sample->get_format(); + if (fmt == SG_SAMPLE_MONO8) format = AL_FORMAT_MONO8; + if (fmt == SG_SAMPLE_MONO16) format = AL_FORMAT_MONO16; + ALsizei size = sample->get_size(); ALsizei freq = sample->get_frequency(); alBufferData( buffer, format, sample_data, size, freq ); -- 2.39.5