[vlc-commits] avcodec audio decoder: add helper for interleaving
Rafaël Carré
git at videolan.org
Tue Feb 12 07:57:59 CET 2013
vlc/vlc-2.0 | branch: master | Rafaël Carré <funman at videolan.org> | Sun Feb 10 19:24:57 2013 +0100| [c32ab8847890f28cd1f6dfb5d961e349432f3523] | committer: Rafaël Carré
avcodec audio decoder: add helper for interleaving
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=c32ab8847890f28cd1f6dfb5d961e349432f3523
---
modules/codec/avcodec/audio.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 45e32d0..f02f595 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -29,6 +29,8 @@
# include "config.h"
#endif
+#include <assert.h>
+
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_codec.h>
@@ -81,6 +83,42 @@ struct decoder_sys_t
int64_t i_previous_layout;
};
+/**
+ * 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.
+ */
+static void 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
+}
+
#define BLOCK_FLAG_PRIVATE_REALLOCATED (1 << BLOCK_FLAG_PRIVATE_SHIFT)
static void SetupOutputFormat( decoder_t *p_dec, bool b_trust );
More information about the vlc-commits
mailing list