Make sure block align is in samples when calling alBufferi with AL_UNPACK_BLOCK_ALIGNMENT_SOFT
This commit is contained in:
@@ -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[] )
|
||||
{
|
||||
@@ -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;
|
||||
|
||||
// Load the sample file
|
||||
buffer = simgear::createBufferFromFile(SGPath(AUDIOFILE));
|
||||
buffer = createBufferFromFile(SGPath(AUDIOFILE));
|
||||
if (buffer == AL_NONE) {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data.");
|
||||
}
|
||||
|
||||
@@ -291,9 +291,9 @@ namespace
|
||||
!wavReadLE (fd, byteRate) ||
|
||||
!wavReadLE (fd, blockAlign) ||
|
||||
!wavReadLE (fd, bitsPerSample))
|
||||
{
|
||||
{
|
||||
throw sg_io_exception("corrupt or truncated WAV data", b->path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!gzSkip(fd, chunkLength - 16))
|
||||
throw sg_io_exception("corrupt or truncated WAV data", b->path);
|
||||
@@ -389,32 +389,4 @@ ALvoid* loadWAVFromFile(const SGPath& path, unsigned int& format, ALsizei& size,
|
||||
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
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
// forward decls
|
||||
class SGPath;
|
||||
|
||||
#define DEFAULT_IMA4_BLOCKSIZE 36
|
||||
#define BLOCKSIZE_TO_SMP(a) ((a) > 1) ? (((a)-4)*2) : 1
|
||||
|
||||
namespace simgear
|
||||
{
|
||||
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
|
||||
|
||||
@@ -600,10 +600,8 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
|
||||
alBufferData( buffer, format, sample_data, size, freq );
|
||||
|
||||
if (format == AL_FORMAT_MONO_IMA4 && _block_support) {
|
||||
ALsizei block_align = sample->get_block_align();
|
||||
|
||||
block_align *= 2; // convert from bytes to samples
|
||||
alBufferi (buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, block_align);
|
||||
ALsizei samples_block = BLOCKSIZE_TO_SMP( sample->get_block_align() );
|
||||
alBufferi (buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, samples_block );
|
||||
}
|
||||
|
||||
if ( !testForError("buffer add data") ) {
|
||||
@@ -798,14 +796,14 @@ bool SGSoundMgr::load( const std::string &samplepath,
|
||||
return false;
|
||||
|
||||
unsigned int format;
|
||||
unsigned int block_align;
|
||||
unsigned int blocksz;
|
||||
ALsizei size;
|
||||
ALsizei freq;
|
||||
ALvoid *data;
|
||||
|
||||
ALfloat freqf;
|
||||
|
||||
data = simgear::loadWAVFromFile(samplepath, format, size, freqf, block_align );
|
||||
data = simgear::loadWAVFromFile(samplepath, format, size, freqf, blocksz);
|
||||
freq = (ALsizei)freqf;
|
||||
if (data == NULL) {
|
||||
throw sg_io_exception("Failed to load wav file", sg_location(samplepath));
|
||||
@@ -818,7 +816,7 @@ bool SGSoundMgr::load( const std::string &samplepath,
|
||||
|
||||
*dbuf = (void *)data;
|
||||
*fmt = (int)format;
|
||||
*block = (int)block_align;
|
||||
*block = (int)blocksz;
|
||||
*sz = (size_t)size;
|
||||
*frq = (int)freq;
|
||||
|
||||
|
||||
@@ -464,7 +464,7 @@ SGXmlSound::update (double dt)
|
||||
for(i = 0; i < max; i++) {
|
||||
double p = 1.0;
|
||||
|
||||
if (_volume[i].expr) {
|
||||
if (_pitch[i].expr) {
|
||||
p = _pitch[i].expr->getValue(NULL);
|
||||
expr = true;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user