}
}
+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[] )
{
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.");
}
!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);
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
// 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
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") ) {
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));
*dbuf = (void *)data;
*fmt = (int)format;
- *block = (int)block_align;
+ *block = (int)blocksz;
*sz = (size_t)size;
*frq = (int)freq;
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;