]> git.sesse.net Git - mlt/commitdiff
Refactor the interleaved-to-planar audio conversions.
authorDan Dennedy <dan@dennedy.org>
Tue, 23 Oct 2012 16:19:40 +0000 (09:19 -0700)
committerDan Dennedy <dan@dennedy.org>
Tue, 23 Oct 2012 16:19:40 +0000 (09:19 -0700)
src/modules/avformat/consumer_avformat.c

index d32d97247754e2f2950ef97996fd210736b00181..d105caf9f621380c6cb738f6b7992eed6bb1a132 100644 (file)
@@ -532,58 +532,21 @@ static int pick_sample_fmt( mlt_properties properties, AVCodec *codec )
        return AV_SAMPLE_FMT_NONE;
 }
 
-static int16_t* s16_to_s16p( int samples, int channels, int16_t* audio )
+static uint8_t* interleaved_to_planar( int samples, int channels, uint8_t* audio, int bytes_per_sample )
 {
-       int size = mlt_audio_format_size( mlt_audio_s16, samples, channels );
-       int16_t *buffer = mlt_pool_alloc( size );
-       int16_t *p = buffer;
+       int size = samples * channels * bytes_per_sample;
+       uint8_t *buffer = mlt_pool_alloc( size );
+       uint8_t *p = buffer;
        int c;
        for ( c = 0; c < channels; c++ )
        {
-               int16_t *q = audio + c;
+               uint8_t *q = audio + c * bytes_per_sample;
                int i = samples + 1;
                while ( --i )
                {
-                       *p++ = *q;
-                       q += channels;
-               }
-       }
-       return buffer;
-}
-
-static int32_t* s32le_to_s32p( int samples, int channels, int32_t* audio )
-{
-       int size = mlt_audio_format_size( mlt_audio_s32, samples, channels );
-       int32_t *buffer = mlt_pool_alloc( size );
-       int32_t *p = buffer;
-       int c;
-       for ( c = 0; c < channels; c++ )
-       {
-               int32_t *q = audio + c;
-               int i = samples + 1;
-               while ( --i )
-               {
-                       *p++ = *q;
-                       q += channels;
-               }
-       }
-       return buffer;
-}
-
-static float* f32le_to_fltp( int samples, int channels, float* audio )
-{
-       int size = mlt_audio_format_size( mlt_audio_float, samples, channels );
-       float *buffer = mlt_pool_alloc( size );
-       float *p = buffer;
-       int c;
-       for ( c = 0; c < channels; c++ )
-       {
-               float *q = audio + c;
-               int i = samples + 1;
-               while ( --i )
-               {
-                       *p++ = *q;
-                       q += channels;
+                       memcpy( p, q, bytes_per_sample );
+                       p += bytes_per_sample;
+                       q += channels * bytes_per_sample;
                }
        }
        return buffer;
@@ -1663,11 +1626,11 @@ static void *consumer_thread( void *arg )
                                                        void* p = audio_buf_1;
 #if LIBAVUTIL_VERSION_INT >= ((51<<16)+(17<<8)+0)
                                                        if ( codec->sample_fmt == AV_SAMPLE_FMT_FLTP )
-                                                               p = f32le_to_fltp( samples, channels, p );
+                                                               p = interleaved_to_planar( samples, channels, p, sizeof( float ) );
                                                        else if ( codec->sample_fmt == AV_SAMPLE_FMT_S16P )
-                                                               p = s16_to_s16p( samples, channels, p );
+                                                               p = interleaved_to_planar( samples, channels, p, sizeof( int16_t ) );
                                                        else if ( codec->sample_fmt == AV_SAMPLE_FMT_S32P )
-                                                               p = s32le_to_s32p( samples, channels, p );
+                                                               p = interleaved_to_planar( samples, channels, p, sizeof( int32_t ) );
 #endif
                                                        pkt.size = avcodec_encode_audio( codec, audio_outbuf, audio_outbuf_size, p );