]> git.mxchange.org Git - simgear.git/commitdiff
block_alignment for AL_SOFT_block_alignment is in samples, not in bytes
authorErik Hofman <erik@ehofman.com>
Wed, 1 Jun 2016 12:16:49 +0000 (14:16 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 13 Aug 2016 08:21:16 +0000 (10:21 +0200)
simgear/sound/soundmgr_openal.cxx

index 7e48da8c2df3ff0f0c61fecd6d0e900f0fb60e21..eacd8f2028c5078dff274c5f8da22c8133b27ac8 100644 (file)
@@ -570,24 +570,39 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
             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
         alGenBuffers(1, &buffer);
         if ( !testForError("generate 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 freq = sample->get_frequency();
             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();
+
+                block_align *= 2; // convert from bytes to samples
                 alBufferi (buffer, AL_UNPACK_BLOCK_ALIGNMENT_SOFT, block_align);
             }