]> git.mxchange.org Git - simgear.git/commitdiff
Add support for native mulaw encoded samples if the OpenAL implementation supports it
authorErik Hofman <erik@ehofman.com>
Mon, 30 May 2016 09:46:41 +0000 (11:46 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 13 Aug 2016 08:21:16 +0000 (10:21 +0200)
simgear/sound/openal_test2.cxx
simgear/sound/readwav.cxx
simgear/sound/soundmgr_openal.cxx
simgear/sound/soundmgr_openal_private.hxx

index 260eea97893e8307abb6600d3e106487e6ae4227..dc81a9bfe7ac4edd86f287a52d770bee92990481 100644 (file)
@@ -38,7 +38,7 @@ int main( int argc, char *argv[] ) {
     printf("playing sample1\n");
     sleep(1);
 
-    SGSoundSample *sample2 = new SGSoundSample("jet.wav", srcDir);
+    SGSoundSample *sample2 = new SGSoundSample("jet_ulaw.wav", srcDir);
     sample2->set_volume(0.5);
     sample2->set_pitch(0.4);
     sample2->play_looped();
index 4f96d883f58f851471c5357434ab216a5456c87f..1618449c997e16af796d50ec503779dab370805e 100644 (file)
@@ -52,11 +52,16 @@ namespace
     }
   };
   
-  unsigned int formatConstruct(ALint numChannels, ALint bitsPerSample)
+  unsigned int formatConstruct(ALint numChannels, ALint bitsPerSample, bool compressed)
   {
     unsigned int rv = 0;
-    if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MONO8;
-    if (numChannels == 1 && bitsPerSample == 16) rv = SG_SAMPLE_MONO16;
+    if (!compressed) {
+      if (numChannels == 1 && bitsPerSample == 16) rv = SG_SAMPLE_MONO16;
+      else if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MONO8;
+    } else {
+      if (numChannels == 1 && bitsPerSample == 4) rv = SG_SAMPLE_ADPCM; 
+      else if (numChannels == 1 && bitsPerSample == 8) rv = SG_SAMPLE_MULAW;
+    }
     return rv;
   }
   
@@ -150,6 +155,7 @@ namespace
     assert(b->data == NULL);
     
     bool found_header = false;
+    bool compressed = false;
     uint32_t chunkLength;
     int32_t magic;
     uint16_t audioFormat;
@@ -205,15 +211,20 @@ namespace
                 codec = (bitsPerSample == 8 || sgIsLittleEndian()) ? codecLinear : codecPCM16BE;
                 break;
               case 7:            /* uLaw */
-                bitsPerSample *= 2;  /* uLaw is 16-bit packed into 8 bits */
-                codec = codecULaw;
+                if (alIsExtensionPresent((ALchar *)"AL_EXT_mulaw")) {
+                  compressed = true;
+                  codec = codecLinear;
+                } else {
+                  bitsPerSample *= 2; /* uLaw is 16-bit packed into 8 bits */
+                  codec = codecULaw;
+                }
                 break;
               default:
                 throw sg_io_exception("unsupported WAV encoding", b->path);
               }
               
               b->frequency = samplesPerSecond;
-              b->format = formatConstruct(numChannels, bitsPerSample);
+              b->format = formatConstruct(numChannels, bitsPerSample, compressed);
         } else if (magic == WAV_DATA_4CC) {
             if (!found_header) {
                 /* ToDo: A bit wrong to check here, fmt chunk could come later... */
index 1dfbafa7b128c508794af30ffb39ff95085a0276..337a237315e8250bfb868d23d1d782b9333e13f1 100644 (file)
@@ -51,10 +51,15 @@ using std::vector;
 
 #define MAX_SOURCES    128
 
-
 #ifndef ALC_ALL_DEVICES_SPECIFIER
 # define ALC_ALL_DEVICES_SPECIFIER     0x1013
 #endif
+#ifndef AL_FORMAT_MONO_MULAW_EXT
+# define AL_FORMAT_MONO_MULAW_EXT      0x10014
+#endif
+#ifndef AL_FORMAT_MONO_IMA4
+# define AL_FORMAT_MONO_IMA4           0x1300
+#endif
 
 class SGSoundMgr::SoundManagerPrivate
 {
@@ -565,8 +570,9 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample)
 
             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;
+            else if (fmt == SG_SAMPLE_MONO8) format = AL_FORMAT_MONO8;
+            else if (fmt == SG_SAMPLE_MULAW) format = AL_FORMAT_MONO_MULAW_EXT;
 
             ALsizei size = sample->get_size();
             ALsizei freq = sample->get_frequency();
index d1b4f85a67a51a462b8ff8503b88b6776f4ad2e1..796652c5c39eb4785cc073275e43b51682ed064f 100644 (file)
@@ -46,9 +46,6 @@
 #else
 # include <AL/al.h>
 # include <AL/alc.h>
-# ifdef HAVE_AL_EXT_H
-#  include <AL/alext.h>
-# endif
 #endif
 
 #include <simgear/structure/SGSharedPtr.hxx>