[pulseaudio-discuss] [PATCH]sndfile-util : Correct wav file creation/writing for 24-32 and 24 bits PCM sample formats

Becker, VincentX vincentx.becker at intel.com
Tue Feb 8 06:33:40 PST 2011


Hi,

This patch corrects format values that are set for specific sample formats PA_SAMPLE_S24NE and PA_SAMPLE_S24_32NE, for wav file creation and writing. Also PA_SAMPLE_S24_32NE was not fully supported in sndfile-util.c. For the unusual format PA_SAMPLE_S24_32NE, sfi format has to be SF_FORMAT_PCM_32 as the audio is coded on 32 bits. In this case, one has to shift 8 bits on the left 24 bits in order to fit into the MSB audio data on 32 bits.

Vincent


---
 src/pulsecore/sndfile-util.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/pulsecore/sndfile-util.c b/src/pulsecore/sndfile-util.c
index 9d15a86..cadda93 100644
--- a/src/pulsecore/sndfile-util.c
+++ b/src/pulsecore/sndfile-util.c
@@ -51,6 +51,9 @@ int pa_sndfile_read_sample_spec(SNDFILE *sf, pa_sample_spec *ss) {
             break;
 
         case SF_FORMAT_PCM_24:
+            ss->format = PA_SAMPLE_S24NE;
+	    break;
+
         case SF_FORMAT_PCM_32:
             ss->format = PA_SAMPLE_S32NE;
             break;
@@ -106,10 +109,14 @@ int pa_sndfile_write_sample_spec(SF_INFO *sfi, pa_sample_spec *ss) {
 
         case PA_SAMPLE_S24LE:
         case PA_SAMPLE_S24BE:
+	    ss->format = PA_SAMPLE_S24NE;
+	    sfi->format |= SF_FORMAT_PCM_24;
+	    break;
+
         case PA_SAMPLE_S24_32LE:
         case PA_SAMPLE_S24_32BE:
-            ss->format = PA_SAMPLE_S32NE;
-            sfi->format |= SF_FORMAT_PCM_24;
+            ss->format = PA_SAMPLE_S24_32NE;
+            sfi->format |= SF_FORMAT_PCM_32;
             break;
 
         case PA_SAMPLE_S32LE:
@@ -362,6 +369,7 @@ pa_sndfile_readf_t pa_sndfile_readf_function(const pa_sample_spec *ss) {
             return (pa_sndfile_readf_t) sf_readf_short;
 
         case PA_SAMPLE_S32NE:
+        case PA_SAMPLE_S24_32NE:
             return (pa_sndfile_readf_t) sf_readf_int;
 
         case PA_SAMPLE_FLOAT32NE:
@@ -384,6 +392,7 @@ pa_sndfile_writef_t pa_sndfile_writef_function(const pa_sample_spec *ss) {
             return (pa_sndfile_writef_t) sf_writef_short;
 
         case PA_SAMPLE_S32NE:
+        case PA_SAMPLE_S24_32NE:
             return (pa_sndfile_writef_t) sf_writef_int;
 
         case PA_SAMPLE_FLOAT32NE:
-- 
1.7.2.3

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Correct-wav-file-creation-for-24-32-and-24-bits-samp.patch
Type: application/octet-stream
Size: 2066 bytes
Desc: 0001-Correct-wav-file-creation-for-24-32-and-24-bits-samp.patch
URL: <http://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20110208/273c9f92/attachment.obj>


More information about the pulseaudio-discuss mailing list