Merge branch 'aeonwave' into next

This commit is contained in:
Erik Hofman
2016-06-01 23:13:09 +02:00
5 changed files with 61 additions and 48 deletions
+28 -1
View File
@@ -43,6 +43,33 @@ static void print_openal_error( ALuint error ) {
} }
} }
ALuint createBufferFromFile(const SGPath& path)
{
ALuint buffer = -1;
#ifdef ENABLE_SOUND
unsigned int format;
unsigned int block_align;
ALsizei size;
ALfloat sampleFrequency;
ALvoid* data = loadWAVFromFile(path, format, size, sampleFrequency, block_align);
assert(data);
alGenBuffers(1, &buffer);
if (alGetError() != AL_NO_ERROR) {
free(data);
throw sg_io_exception("OpenAL buffer allocation failed", sg_location(path.str()));
}
alBufferData (buffer, format, data, size, (ALsizei) sampleFrequency);
if (alGetError() != AL_NO_ERROR) {
alDeleteBuffers(1, &buffer);
free(data);
throw sg_io_exception("OpenAL setting buffer data failed", sg_location(path.str()));
}
#endif
return buffer;
}
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
@@ -111,7 +138,7 @@ int main( int argc, char *argv[] )
source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0; source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0;
// Load the sample file // Load the sample file
buffer = simgear::createBufferFromFile(SGPath(AUDIOFILE)); buffer = createBufferFromFile(SGPath(AUDIOFILE));
if (buffer == AL_NONE) { if (buffer == AL_NONE) {
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data."); SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data.");
} }
+3 -31
View File
@@ -291,9 +291,9 @@ namespace
!wavReadLE (fd, byteRate) || !wavReadLE (fd, byteRate) ||
!wavReadLE (fd, blockAlign) || !wavReadLE (fd, blockAlign) ||
!wavReadLE (fd, bitsPerSample)) !wavReadLE (fd, bitsPerSample))
{ {
throw sg_io_exception("corrupt or truncated WAV data", b->path); throw sg_io_exception("corrupt or truncated WAV data", b->path);
} }
if (!gzSkip(fd, chunkLength - 16)) if (!gzSkip(fd, chunkLength - 16))
throw sg_io_exception("corrupt or truncated WAV data", b->path); throw sg_io_exception("corrupt or truncated WAV data", b->path);
@@ -319,7 +319,7 @@ namespace
compressed = true; compressed = true;
codec = codecLinear; codec = codecLinear;
} else { } else {
bitsPerSample *= 4; /* uLaw is 16-bit packed into 8 bits */ bitsPerSample *= 4; /* adpcm is 16-bit packed into 4 bits */
codec = codecIMA4; codec = codecIMA4;
} }
@@ -389,32 +389,4 @@ ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size,
return data; return data;
} }
ALuint createBufferFromFile(const SGPath& path)
{
ALuint buffer = -1;
#ifdef ENABLE_SOUND
unsigned int format;
unsigned int block_align;
ALsizei size;
ALfloat sampleFrequency;
ALvoid* data = loadWAVFromFile(path, format, size, sampleFrequency, block_alight);
assert(data);
alGenBuffers(1, &buffer);
if (alGetError() != AL_NO_ERROR) {
free(data);
throw sg_io_exception("OpenAL buffer allocation failed", sg_location(path.str()));
}
alBufferData (buffer, format, data, size, (ALsizei) sampleFrequency);
alBufferi (buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, block_align);
if (alGetError() != AL_NO_ERROR) {
alDeleteBuffers(1, &buffer);
free(data);
throw sg_io_exception("OpenAL setting buffer data failed", sg_location(path.str()));
}
#endif
return buffer;
}
} // of namespace simgear } // of namespace simgear
+3 -2
View File
@@ -14,11 +14,12 @@
// forward decls // forward decls
class SGPath; class SGPath;
#define DEFAULT_IMA4_BLOCKSIZE 36
#define BLOCKSIZE_TO_SMP(a) ((a) > 1) ? (((a)-4)*2) : 1
namespace simgear namespace simgear
{ {
ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size, ALfloat& freqf, unsigned int& block_align); ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size, ALfloat& freqf, unsigned int& block_align);
ALuint createBufferFromFile(const SGPath& path);
} }
#endif // of SG_SOUND_READWAV_HXX #endif // of SG_SOUND_READWAV_HXX
+26 -13
View File
@@ -570,25 +570,38 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
sample_data = sample->get_data(); sample_data = sample->get_data();
} }
ALenum format = AL_NONE;
switch( sample->get_format() )
{
case SG_SAMPLE_MONO16:
format = AL_FORMAT_MONO16;
break;
case SG_SAMPLE_MONO8:
format = AL_FORMAT_MONO8;
break;
case SG_SAMPLE_MULAW:
format = AL_FORMAT_MONO_MULAW_EXT;
break;
case SG_SAMPLE_ADPCM:
format = AL_FORMAT_MONO_IMA4;
break;
default:
SG_LOG(SG_SOUND, SG_ALERT, "unsupported audio format");
return buffer;
}
// create an OpenAL buffer handle // create an OpenAL buffer handle
alGenBuffers(1, &buffer); alGenBuffers(1, &buffer);
if ( !testForError("generate buffer") ) { if ( !testForError("generate buffer") ) {
// Copy data to the internal OpenAL buffer // Copy data to the internal OpenAL buffer
ALenum format = AL_NONE;
unsigned int fmt = sample->get_format();
if (fmt == SG_SAMPLE_MONO16) format = AL_FORMAT_MONO16;
else if (fmt == SG_SAMPLE_MONO8) format = AL_FORMAT_MONO8;
else if (fmt == SG_SAMPLE_MULAW) format = AL_FORMAT_MONO_MULAW_EXT;
else if (fmt == SG_SAMPLE_ADPCM) format = AL_FORMAT_MONO_IMA4;
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 );
if (_block_support) { if (format == AL_FORMAT_MONO_IMA4 && _block_support) {
ALsizei block_align = sample->get_block_align(); ALsizei samples_block = BLOCKSIZE_TO_SMP( sample->get_block_align() );
alBufferi (buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, block_align); alBufferi (buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, samples_block );
} }
if ( !testForError("buffer add data") ) { if ( !testForError("buffer add data") ) {
@@ -783,14 +796,14 @@ bool SGSoundMgr::load( const std::string &samplepath,
return false; return false;
unsigned int format; unsigned int format;
unsigned int block_align; unsigned int blocksz;
ALsizei size; ALsizei size;
ALsizei freq; ALsizei freq;
ALvoid *data; ALvoid *data;
ALfloat freqf; ALfloat freqf;
data = simgear::loadWAVFromFile(samplepath, format, size, freqf, block_align ); data = simgear::loadWAVFromFile(samplepath, format, size, freqf, blocksz);
freq = (ALsizei)freqf; freq = (ALsizei)freqf;
if (data == NULL) { if (data == NULL) {
throw sg_io_exception("Failed to load wav file", sg_location(samplepath)); throw sg_io_exception("Failed to load wav file", sg_location(samplepath));
@@ -803,7 +816,7 @@ bool SGSoundMgr::load( const std::string &samplepath,
*dbuf = (void *)data; *dbuf = (void *)data;
*fmt = (int)format; *fmt = (int)format;
*block = (int)block_align; *block = (int)blocksz;
*sz = (size_t)size; *sz = (size_t)size;
*frq = (int)freq; *frq = (int)freq;
+1 -1
View File
@@ -464,7 +464,7 @@ SGXmlSound::update (double dt)
for(i = 0; i < max; i++) { for(i = 0; i < max; i++) {
double p = 1.0; double p = 1.0;
if (_volume[i].expr) { if (_pitch[i].expr) {
p = _pitch[i].expr->getValue(NULL); p = _pitch[i].expr->getValue(NULL);
expr = true; expr = true;
continue; continue;