Switch to out own audio format defines

This commit is contained in:
Erik Hofman
2016-05-27 11:58:01 +02:00
parent b05488649a
commit c5a94e8899
4 changed files with 16 additions and 72 deletions

View File

@@ -30,12 +30,14 @@
#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;
@@ -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);

View File

@@ -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"

View File

@@ -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

View File

@@ -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 );