]> git.sesse.net Git - mlt/commitdiff
add s32le and f32le format to core audio filters
authorDan Dennedy <dan@dennedy.org>
Thu, 26 Jan 2012 04:26:27 +0000 (20:26 -0800)
committerDan Dennedy <dan@dennedy.org>
Thu, 26 Jan 2012 04:26:27 +0000 (20:26 -0800)
src/modules/core/filter_audiochannels.c
src/modules/core/filter_channelcopy.c
src/modules/core/filter_mono.c

index 20e839bfebf9c6d176ccc2e6391bb136c153a15e..544d932b99b54f9dcd51f86222a573fb1273d1e7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * filter_audiochannels.c -- convert from one audio format to another
- * Copyright (C) 2009 Ushodaya Enterprises Limited
+ * Copyright (C) 2009-2012 Ushodaya Enterprises Limited
  * Author: Dan Dennedy <dan@dennedy.org>
  *
  * This library is free software; you can redistribute it and/or
@@ -46,14 +46,27 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
                        {
                                for ( j = 0; j < *channels; j++ )
                                {
-                                       new_buffer[ ( i * *channels ) + j ]     = ((int16_t*)(*buffer))[ ( i * channels_avail ) + k ];
+                                       new_buffer[ ( i * *channels ) + j ] = ((int16_t*)(*buffer))[ ( i * channels_avail ) + k ];
+                                       k = ( k + 1 ) % channels_avail;
+                               }
+                       }
+               }
+               else if ( *format == mlt_audio_s32le || *format == mlt_audio_f32le )
+               {
+                       int32_t *p = (int32_t*) new_buffer;
+                       int i, j, k = 0;
+                       for ( i = 0; i < *samples; i++ )
+                       {
+                               for ( j = 0; j < *channels; j++ )
+                               {
+                                       p[ ( i * *channels ) + j ] = ((int32_t*)(*buffer))[ ( i * channels_avail ) + k ];
                                        k = ( k + 1 ) % channels_avail;
                                }
                        }
                }
                else
                {
-                       // non-interleaved
+                       // non-interleaved - s32 or float
                        int size_avail = mlt_audio_format_size( *format, *samples, channels_avail );
                        int32_t *p = (int32_t*) new_buffer;
                        int i = *channels / channels_avail;
index cbfb709b6005b2bf111d7719ce95aa3734cfec92..be206f89a61c4a840b7982bd42ac9bc390c53bff 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * filter_channelcopy.c -- copy one audio channel to another
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
  * Author: Dan Dennedy <dan@dennedy.org>
  *
  * This library is free software; you can redistribute it and/or
@@ -86,6 +86,26 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
                        }
                        break;
                }
+               case mlt_audio_s32le:
+               case mlt_audio_f32le:
+               {
+                       int32_t *f = (int32_t*) *buffer + from;
+                       int32_t *t = (int32_t*) *buffer + to;
+                       int32_t x;
+                       int i;
+
+                       if ( swap )
+                               for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
+                               {
+                                       x = *t;
+                                       *t = *f;
+                                       *f = x;
+                               }
+                       else
+                               for ( i = 0; i < *samples; i++, f += *channels, t += *channels )
+                                       *t = *f;
+                       break;
+               }
                case mlt_audio_float:
                {
                        float *f = (float*) *buffer + from * *samples;
index 01b6f462deda35c10d4a4e1edea60c4a13764be6..3d2eba71334d66b5576be9ee6be13962c4d4ee90 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * filter_mono.c -- mix all channels to a mono signal across n channels
- * Copyright (C) 2003-2009 Ushodaya Enterprises Limited
+ * Copyright (C) 2003-2012 Ushodaya Enterprises Limited
  * Author: Dan Dennedy <dan@dennedy.org>
  *
  * This library is free software; you can redistribute it and/or
@@ -58,6 +58,34 @@ static int filter_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *f
                        *buffer = new_buffer;
                        break;
                }
+               case mlt_audio_s32le:
+               {
+                       int32_t *new_buffer = mlt_pool_alloc( size );
+                       for ( i = 0; i < *samples; i++ )
+                       {
+                               int32_t mixdown = 0;
+                               for ( j = 0; j < *channels; j++ )
+                                       mixdown += ((int32_t*) *buffer)[ ( i * *channels ) + j ] / *channels;
+                               for ( j = 0; j < channels_out; j++ )
+                                       new_buffer[ ( i * channels_out ) + j ] = mixdown;
+                       }
+                       *buffer = new_buffer;
+                       break;
+               }
+               case mlt_audio_f32le:
+               {
+                       float *new_buffer = mlt_pool_alloc( size );
+                       for ( i = 0; i < *samples; i++ )
+                       {
+                               float mixdown = 0;
+                               for ( j = 0; j < *channels; j++ )
+                                       mixdown += ((float*) *buffer)[ ( i * *channels ) + j ] / *channels;
+                               for ( j = 0; j < channels_out; j++ )
+                                       new_buffer[ ( i * channels_out ) + j ] = mixdown;
+                       }
+                       *buffer = new_buffer;
+                       break;
+               }
                case mlt_audio_s32:
                {
                        int32_t *new_buffer = mlt_pool_alloc( size );