[vlc-devel] [PATCH 2/5] aout: add deinterleave helper for doing packet->planar for audio samples (cherry picked from commit ec3df8f49c7d48389c79226db6acf00a511e7e0e)

Rafaël Carré funman at videolan.org
Sun Feb 10 15:57:35 CET 2013


From: Ilkka Ollakka <ileoo at videolan.org>

Conflicts:
	src/libvlccore.sym
---
 include/vlc_aout.h        |    2 ++
 src/audio_output/common.c |   36 ++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym        |    1 +
 3 files changed, 39 insertions(+)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index ffc8e06..a468838 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -215,6 +215,8 @@ VLC_API void aout_ChannelReorder( uint8_t *, int, int, const int *, int );
 
 VLC_API void aout_Interleave(void *dst, const void *src, unsigned samples,
                              unsigned channels, vlc_fourcc_t fourcc);
+VLC_API void aout_Deinterleave(void *dst, const void *src, unsigned samples,
+                             unsigned channels, vlc_fourcc_t fourcc);
 
 /**
  * This fonction will compute the extraction parameter into pi_selection to go
diff --git a/src/audio_output/common.c b/src/audio_output/common.c
index fe8e84c..96df600 100644
--- a/src/audio_output/common.c
+++ b/src/audio_output/common.c
@@ -686,6 +686,42 @@ do { \
 #undef INTERLEAVE_TYPE
 }
 
+/**
+ * Deinterleaves audio samples within a block of samples.
+ * \param dst destination buffer for planar samples
+ * \param src source buffer with interleaved samples
+ * \param samples number of samples (per channel/per plane)
+ * \param chans channels/planes count
+ * \param fourcc sample format (must be a linear sample format)
+ * \note The samples must be naturally aligned in memory.
+ * \warning Destination and source buffers MUST NOT overlap.
+ */
+void aout_Deinterleave( void *restrict dst, const void *restrict src,
+                      unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
+{
+#define DEINTERLEAVE_TYPE(type) \
+do { \
+    type *d = dst; \
+    const type *s = src; \
+    for( size_t i = 0; i < chans; i++ ) { \
+        for( size_t j = 0, k = 0; j < samples; j++, k += chans ) \
+            *(d++) = s[k]; \
+        s++; \
+    } \
+} while(0)
+
+    switch( fourcc )
+    {
+        case VLC_CODEC_U8:   DEINTERLEAVE_TYPE(uint8_t);  break;
+        case VLC_CODEC_S16N: DEINTERLEAVE_TYPE(uint16_t); break;
+        case VLC_CODEC_FL32: DEINTERLEAVE_TYPE(float);    break;
+        case VLC_CODEC_S32N: DEINTERLEAVE_TYPE(int32_t);  break;
+        case VLC_CODEC_FL64: DEINTERLEAVE_TYPE(double);   break;
+        default:             assert(0);
+    }
+#undef DEINTERLEAVE_TYPE
+}
+
 /*****************************************************************************
  * aout_ChannelExtract:
  *****************************************************************************/
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 6e20324..e809691 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -12,6 +12,7 @@ aout_ChannelReorder
 aout_ChannelsRestart
 aout_CheckChannelExtraction
 aout_CheckChannelReorder
+aout_Deinterleave
 aout_EnableFilter
 aout_filter_RequestVout
 aout_FormatPrepare
-- 
1.7.10.4



More information about the vlc-devel mailing list