case VLC_CODEC_S24B:
return 24;
+ case VLC_CODEC_S24L32:
+ case VLC_CODEC_S24B32:
+ case VLC_CODEC_U32L:
+ case VLC_CODEC_U32B:
case VLC_CODEC_S32L:
case VLC_CODEC_S32B:
case VLC_CODEC_F32L:
case VLC_CODEC_F32B:
- case VLC_CODEC_FI32:
return 32;
case VLC_CODEC_F64L:
return 0;
}
-/*****************************************************************************
- * aout_ChannelReorder :
- *****************************************************************************/
-void aout_ChannelReorder( void *ptr, size_t bytes, unsigned channels,
- const uint8_t *chans_table, unsigned bits_per_sample )
+/**
+ * Reorders audio samples within a block of linear audio interleaved samples.
+ * \param ptr start address of the block of samples
+ * \param bytes size of the block in bytes (must be a multiple of the product
+ * of the channels count and the sample size)
+ * \param channels channels count (also length of the chans_table table)
+ * \param chans_table permutation table to reorder the channels
+ * (usually computed by aout_CheckChannelReorder())
+ * \param fourcc sample format (must be a linear sample format)
+ * \note The samples must be naturally aligned in memory.
+ */
+void aout_ChannelReorder( void *ptr, size_t bytes, uint8_t channels,
+ const uint8_t *restrict chans_table, vlc_fourcc_t fourcc )
{
- size_t samples = bytes / (channels * (bits_per_sample >> 3));
-
- assert( channels <= AOUT_CHAN_MAX );
-
- switch( bits_per_sample )
+ if( unlikely(bytes == 0) )
+ return;
+
+ assert( channels != 0 );
+
+ /* The audio formats supported in audio output are inlined. For other
+ * formats (used in demuxers and muxers), memcpy() is used to avoid
+ * breaking type punning. */
+#define REORDER_TYPE(type) \
+do { \
+ const size_t frames = (bytes / sizeof (type)) / channels; \
+ type *buf = ptr; \
+\
+ for( size_t i = 0; i < frames; i++ ) \
+ { \
+ type tmp[AOUT_CHAN_MAX]; \
+\
+ for( size_t j = 0; j < channels; j++ ) \
+ tmp[chans_table[j]] = buf[j]; \
+ memcpy( buf, tmp, sizeof (type) * channels ); \
+ buf += channels; \
+ } \
+} while(0)
+
+ if( likely(channels <= AOUT_CHAN_MAX) )
{
- case 32:
- {
- uint32_t *buf = ptr;
-
- for( size_t i = 0; i < samples; i++ )
- {
- uint32_t tmp[AOUT_CHAN_MAX];
-
- for( size_t j = 0; j < channels; j++ )
- tmp[chans_table[j]] = buf[j];
-
- memcpy( buf, tmp, 4 * channels );
- buf += channels;
- }
- break;
- }
-
- case 16:
+ switch( fourcc )
{
- uint16_t *buf = ptr;
-
- for( size_t i = 0; i < samples; i++ )
- {
- uint16_t tmp[AOUT_CHAN_MAX];
-
- for( size_t j = 0; j < channels; j++ )
- tmp[chans_table[j]] = buf[j];
-
- memcpy( buf, tmp, 2 * channels );
- buf += channels;
- }
- break;
+ case VLC_CODEC_U8: REORDER_TYPE(uint8_t); return;
+ case VLC_CODEC_S16N: REORDER_TYPE(int16_t); return;
+ case VLC_CODEC_FL32: REORDER_TYPE(float); return;
+ case VLC_CODEC_S32N: REORDER_TYPE(int32_t); return;
+ case VLC_CODEC_FL64: REORDER_TYPE(double); return;
}
+ }
- case 8:
- {
- uint8_t *buf = ptr;
-
- for( size_t i = 0; i < samples; i++ )
- {
- uint8_t tmp[AOUT_CHAN_MAX];
-
- for( size_t j = 0; j < channels; j++ )
- tmp[chans_table[j]] = buf[j];
+ unsigned size = aout_BitsPerSample( fourcc ) / 8;
+ assert( size != 0 && size <= 8 );
- memcpy( buf, tmp, channels );
- buf += channels;
- }
- break;
- }
+ const size_t frames = bytes / (size * channels);
+ unsigned char *buf = ptr;
- case 24:
- {
- uint8_t *buf = ptr;
+ for( size_t i = 0; i < frames; i++ )
+ {
+ unsigned char tmp[256 * 8];
- for( size_t i = 0; i < samples; i++ )
- {
- uint8_t tmp[3 * AOUT_CHAN_MAX];
+ for( size_t j = 0; j < channels; j++ )
+ memcpy( tmp + size * chans_table[j], buf + size * j, size );
+ memcpy( buf, tmp, size * channels );
+ buf += size * channels;
+ }
+}
- for( size_t j = 0; j < channels; j++ )
- memcpy( tmp + (3 * chans_table[j]), buf + (3 * j), 3 );
+/**
+ * Interleaves audio samples within a block of samples.
+ * \param dst destination buffer for interleaved samples
+ * \param srcv source buffers (one per plane) of uninterleaved 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 *const *srcv,
+ unsigned samples, unsigned chans, vlc_fourcc_t fourcc )
+{
+#define INTERLEAVE_TYPE(type) \
+do { \
+ type *d = dst; \
+ for( size_t i = 0; i < chans; i++ ) { \
+ const type *s = srcv[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: vlc_assert_unreachable();
+ }
+#undef INTERLEAVE_TYPE
+}
- memcpy( buf, tmp, 3 * channels );
- buf += 3 * channels;
- }
- }
+/**
+ * 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: vlc_assert_unreachable();
}
+#undef DEINTERLEAVE_TYPE
}
/*****************************************************************************
ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 1 );
else if( i_bits_per_sample == 16 )
ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 2 );
- else if( i_bits_per_sample == 24 )
- ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 3 );
else if( i_bits_per_sample == 32 )
ExtractChannel( p_dst, i_dst_channels, p_src, i_src_channels, i_sample_count, pi_selection, 4 );
else if( i_bits_per_sample == 64 )
return INT_MAX;
}
-/* This function will add or remove a a module from a string list (colon
+/* This function will add or remove a module from a string list (colon
* separated). It will return true if there is a modification
* In case p_aout is NULL, we will use configuration instead of variable */
bool aout_ChangeFilterString( vlc_object_t *p_obj, vlc_object_t *p_aout,