Switch to out own audio format defines
This commit is contained in:
+10
-20
@@ -30,12 +30,14 @@
|
|||||||
#include <simgear/misc/stdint.hxx>
|
#include <simgear/misc/stdint.hxx>
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
|
#include "sample_openal.hxx"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
ALvoid* data;
|
ALvoid* data;
|
||||||
ALenum format;
|
unsigned int format;
|
||||||
ALsizei length;
|
ALsizei length;
|
||||||
ALfloat frequency;
|
ALfloat frequency;
|
||||||
SGPath path;
|
SGPath path;
|
||||||
@@ -50,24 +52,12 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ALenum formatConstruct(ALint numChannels, ALint bitsPerSample)
|
unsigned int formatConstruct(ALint numChannels, ALint bitsPerSample)
|
||||||
{
|
{
|
||||||
switch (numChannels)
|
unsigned int rv = 0;
|
||||||
{
|
if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MONO8;
|
||||||
case 1:
|
if (numChannels == 1 && bitsPerSample == 16) rv = SG_SAMPLE_MONO16;
|
||||||
switch (bitsPerSample) {
|
return rv;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// function prototype for decoding audio data
|
// function prototype for decoding audio data
|
||||||
@@ -255,7 +245,7 @@ namespace
|
|||||||
namespace simgear
|
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()) {
|
if (!path.exists()) {
|
||||||
throw sg_io_exception("loadWAVFromFile: file not found", path);
|
throw sg_io_exception("loadWAVFromFile: file not found", path);
|
||||||
@@ -285,7 +275,7 @@ ALuint createBufferFromFile(const SGPath& path)
|
|||||||
{
|
{
|
||||||
ALuint buffer = -1;
|
ALuint buffer = -1;
|
||||||
#ifdef ENABLE_SOUND
|
#ifdef ENABLE_SOUND
|
||||||
ALenum format;
|
unsigned int format;
|
||||||
ALsizei size;
|
ALsizei size;
|
||||||
ALfloat sampleFrequency;
|
ALfloat sampleFrequency;
|
||||||
ALvoid* data = loadWAVFromFile(path, format, size, sampleFrequency);
|
ALvoid* data = loadWAVFromFile(path, format, size, sampleFrequency);
|
||||||
|
|||||||
@@ -82,48 +82,6 @@ SGSoundSampleInfo::SGSoundSampleInfo() :
|
|||||||
_pos_prop[2] = 0;
|
_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()
|
std::string SGSoundSampleInfo::random_string()
|
||||||
{
|
{
|
||||||
static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz"
|
static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz"
|
||||||
|
|||||||
@@ -61,12 +61,6 @@ public:
|
|||||||
SGSoundSampleInfo();
|
SGSoundSampleInfo();
|
||||||
~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.
|
* Returns the format of this audio sample.
|
||||||
* @return SimGear format-id
|
* @return SimGear format-id
|
||||||
@@ -438,8 +432,6 @@ public:
|
|||||||
_tracks = fmt & 0x3; _bits = fmt & 0x1C; _compressed = fmt & 0x100;
|
_tracks = fmt & 0x3; _bits = fmt & 0x1C; _compressed = fmt & 0x100;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_format_AL( int fmt );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the frequency (in Herz) of this audio sample.
|
* Set the frequency (in Herz) of this audio sample.
|
||||||
* @param freq Frequency
|
* @param freq Frequency
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sample->set_frequency( freq );
|
sample->set_frequency( freq );
|
||||||
sample->set_format_AL( format );
|
sample->set_format( format );
|
||||||
sample->set_size( size );
|
sample->set_size( size );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -562,7 +562,11 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
|
|||||||
if ( !testForALError("generate buffer") ) {
|
if ( !testForALError("generate buffer") ) {
|
||||||
// Copy data to the internal OpenAL 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 size = sample->get_size();
|
||||||
ALsizei freq = sample->get_frequency();
|
ALsizei freq = sample->get_frequency();
|
||||||
alBufferData( buffer, format, sample_data, size, freq );
|
alBufferData( buffer, format, sample_data, size, freq );
|
||||||
|
|||||||
Reference in New Issue
Block a user