handle float values in sound files sensibly
authorLennart Poettering <lennart@poettering.net>
Fri, 16 Sep 2005 00:03:19 +0000 (00:03 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 16 Sep 2005 00:03:19 +0000 (00:03 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@354 fefdeb5f-60dc-0310-8127-8f9354f1896f

polyp/sound-file.c

index 80233da..f16d326 100644 (file)
@@ -52,19 +52,18 @@ int pa_sound_file_load(const char *fname, struct pa_sample_spec *ss, struct pa_m
         goto finish;
     }
 
-    switch (sfinfo.format & 0xFF) {
-        case SF_FORMAT_PCM_16:
-        case SF_FORMAT_PCM_U8:
-        case SF_FORMAT_ULAW:
-        case SF_FORMAT_ALAW:
-            ss->format = PA_SAMPLE_S16NE;
-            readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
-            break;
+    switch (sfinfo.format & SF_FORMAT_SUBMASK) {
         case SF_FORMAT_FLOAT:
-        default:
+        case SF_FORMAT_DOUBLE:
+            /* Only float and double need a special case. */
             ss->format = PA_SAMPLE_FLOAT32NE;
             readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_float;
             break;
+        default:
+            /* Everything else is cleanly converted to signed 16 bit. */
+            ss->format = PA_SAMPLE_S16NE;
+            readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
+            break;
     }
 
     ss->rate = sfinfo.samplerate;