]> git.sesse.net Git - vlc/commitdiff
aout: add aout_Interleave() helper for interleaving
authorRémi Denis-Courmont <remi@remlab.net>
Fri, 21 Dec 2012 22:13:57 +0000 (00:13 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Fri, 21 Dec 2012 22:18:11 +0000 (00:18 +0200)
include/vlc_aout.h
src/audio_output/common.c
src/libvlccore.sym

index 61f95378eb7252e71c23c920aafd4f2c46508db9..1c1b9846d5c8caf22f5dcbc39b781bf21189cdff 100644 (file)
@@ -212,6 +212,9 @@ VLC_API unsigned aout_CheckChannelReorder( const uint32_t *, const uint32_t *,
                                            uint32_t mask, uint8_t *table );
 VLC_API void aout_ChannelReorder(void *, size_t, unsigned, const uint8_t *, vlc_fourcc_t);
 
+VLC_API void aout_Interleave(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
  * from i_channels with their type given by pi_order_src[] into the order
index edab67ffbe793f08b5bbb877a27e7d69a4a2321d..d6c13ea82e6b5466078507fede3f8b9765f55ae9 100644 (file)
@@ -402,6 +402,42 @@ void aout_ChannelReorder( void *ptr, size_t bytes, unsigned channels,
     }
 }
 
+/**
+ * Interleaves audio samples within a block of samples.
+ * \param dst destination buffer for interleaved samples
+ * \param src source buffer with consecutive planes of 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_Interleave( void *restrict dst, const void *restrict src,
+                      unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
+{
+#define INTERLEAVE_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[k] = *(s++); \
+        d++; \
+    } \
+} while(0)
+
+    switch( fourcc )
+    {
+        case VLC_CODEC_U8:   INTERLEAVE_TYPE(uint8_t);  break;
+        case VLC_CODEC_S16N: INTERLEAVE_TYPE(uint16_t); break;
+        case VLC_CODEC_FL32: INTERLEAVE_TYPE(float);    break;
+        case VLC_CODEC_S32N: INTERLEAVE_TYPE(int32_t);  break;
+        case VLC_CODEC_FL64: INTERLEAVE_TYPE(double);   break;
+        default:             assert(0);
+    }
+#undef INTERLEAVE_TYPE
+}
+
 /*****************************************************************************
  * aout_ChannelExtract:
  *****************************************************************************/
index 85cc03c1285f3a25253453169747f5dac7fa6407..62d6e0b9b60084aca1051a31a3540987ad944913 100644 (file)
@@ -5,6 +5,7 @@ aout_ChannelExtract
 aout_ChannelReorder
 aout_CheckChannelExtraction
 aout_CheckChannelReorder
+aout_Interleave
 aout_filter_RequestVout
 aout_FormatPrepare
 aout_FormatPrint