#include <simgear/misc/stdint.hxx>
#include <simgear/structure/exception.hxx>
+#include "sample_openal.hxx"
+
namespace
{
class Buffer {
public:
ALvoid* data;
- ALenum format;
+ unsigned int format;
ALsizei length;
ALfloat frequency;
SGPath path;
}
};
- 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
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);
{
ALuint buffer = -1;
#ifdef ENABLE_SOUND
- ALenum format;
+ unsigned int format;
ALsizei size;
ALfloat sampleFrequency;
ALvoid* data = loadWAVFromFile(path, format, size, sampleFrequency);
_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"
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
_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
}
sample->set_frequency( freq );
- sample->set_format_AL( format );
+ sample->set_format( format );
sample->set_size( size );
} else {
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 );