[polypaudio-commits] r900 - /trunk/src/polypcore/sound-file.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed May 17 07:55:17 PDT 2006


Author: lennart
Date: Wed May 17 16:55:17 2006
New Revision: 900

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=900&root=polypaudio&view=rev
Log:
support loading ULAW/ALAW files into ULAW/ALAW memchunks

Modified:
    trunk/src/polypcore/sound-file.c

Modified: trunk/src/polypcore/sound-file.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polypcore/sound-file.c?rev=900&root=polypaudio&r1=899&r2=900&view=diff
==============================================================================
--- trunk/src/polypcore/sound-file.c (original)
+++ trunk/src/polypcore/sound-file.c Wed May 17 16:55:17 2006
@@ -39,7 +39,7 @@
     SF_INFO sfinfo;
     int ret = -1;
     size_t l;
-    sf_count_t (*readf_function)(SNDFILE *sndfile, void *ptr, sf_count_t frames);
+    sf_count_t (*readf_function)(SNDFILE *sndfile, void *ptr, sf_count_t frames) = NULL;
     assert(fname && ss && chunk);
 
     chunk->memblock = NULL;
@@ -53,16 +53,26 @@
     }
 
     switch (sfinfo.format & SF_FORMAT_SUBMASK) {
+        case SF_FORMAT_PCM_16:
+        case SF_FORMAT_PCM_U8:
+        case SF_FORMAT_PCM_S8:
+            ss->format = PA_SAMPLE_S16NE;
+            readf_function = (sf_count_t (*)(SNDFILE *sndfile, void *ptr, sf_count_t frames)) sf_readf_short;
+            break;
+
+        case SF_FORMAT_ULAW:
+            ss->format = PA_SAMPLE_ULAW;
+            break;
+            
+        case SF_FORMAT_ALAW:
+            ss->format = PA_SAMPLE_ALAW;
+            break;
+
         case SF_FORMAT_FLOAT:
         case SF_FORMAT_DOUBLE:
-            /* Only float and double need a special case. */
+        default:
             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;
     }
 
@@ -87,11 +97,12 @@
     chunk->index = 0;
     chunk->length = l;
 
-    if (readf_function(sf, chunk->memblock->data, sfinfo.frames) != sfinfo.frames) {
+    if ((readf_function && readf_function(sf, chunk->memblock->data, sfinfo.frames) != sfinfo.frames) ||
+        (!readf_function && sf_read_raw(sf, chunk->memblock->data, l) != l)) {
         pa_log(__FILE__": Premature file end");
         goto finish;
     }
-
+        
     ret = 0;
 
 finish:
@@ -119,14 +130,24 @@
     sf_close(sf);
 
     switch (sfinfo.format & SF_FORMAT_SUBMASK) {
+        case SF_FORMAT_PCM_16:
+        case SF_FORMAT_PCM_U8:
+        case SF_FORMAT_PCM_S8:
+            ss.format = PA_SAMPLE_S16NE;
+            break;
+
+        case SF_FORMAT_ULAW:
+            ss.format = PA_SAMPLE_ULAW;
+            break;
+            
+        case SF_FORMAT_ALAW:
+            ss.format = PA_SAMPLE_ALAW;
+            break;
+
+        case SF_FORMAT_DOUBLE:
         case SF_FORMAT_FLOAT:
-        case SF_FORMAT_DOUBLE:
-            /* Only float and double need a special case. */
+        default:
             ss.format = PA_SAMPLE_FLOAT32NE;
-            break;
-        default:
-            /* Everything else is cleanly converted to signed 16 bit. */
-            ss.format = PA_SAMPLE_S16NE;
             break;
     }
 




More information about the pulseaudio-commits mailing list