]> git.sesse.net Git - vlc/commitdiff
aout: add deinterleave helper for doing packet->planar for audio samples
authorIlkka Ollakka <ileoo@videolan.org>
Sat, 29 Dec 2012 12:21:04 +0000 (14:21 +0200)
committerIlkka Ollakka <ileoo@videolan.org>
Sun, 30 Dec 2012 11:24:27 +0000 (13:24 +0200)
include/vlc_aout.h
src/audio_output/common.c
src/libvlccore.sym

index 1c1b9846d5c8caf22f5dcbc39b781bf21189cdff..9d89ff12f637e6648928c9d5d19cb50fc86dc67f 100644 (file)
@@ -214,6 +214,8 @@ VLC_API void aout_ChannelReorder(void *, size_t, unsigned, const uint8_t *, vlc_
 
 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
index 735f0a0613a917c6ce0a751626080fefdceedc66..2bc5437289b50e09d1790e95cd46ce986e5fdf57 100644 (file)
@@ -376,6 +376,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:
  *****************************************************************************/
index 62d6e0b9b60084aca1051a31a3540987ad944913..f917612ffdad11688c0b1b342eabd458241a60f3 100644 (file)
@@ -6,6 +6,7 @@ aout_ChannelReorder
 aout_CheckChannelExtraction
 aout_CheckChannelReorder
 aout_Interleave
+aout_Deinterleave
 aout_filter_RequestVout
 aout_FormatPrepare
 aout_FormatPrint