]> git.sesse.net Git - mlt/commitdiff
+ Alternative between track mixing mechanism (using a low pass filter)
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 23 Feb 2006 09:21:14 +0000 (09:21 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 23 Feb 2006 09:21:14 +0000 (09:21 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@888 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_frame.c
src/framework/mlt_frame.h

index 115978dd1cc5103c6c4fa69bd8d26c23a1c0eb01..f072bdd1e4e461b47ff6b32472f0ca32f0413e80 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <math.h>
 
 /** Constructor for a frame.
 */
@@ -904,6 +905,15 @@ int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight_start, flo
        float weight = weight_start;
        float weight_step = ( weight_end - weight_start ) / *samples;
 
+       if ( src == dest )
+       {
+               *samples = samples_src;
+               *channels = channels_src;
+               *buffer = src;
+               *frequency = frequency_src;
+               return ret;
+       }
+
        // Mixdown
        for ( i = 0; i < *samples; i++ )
        {
@@ -921,6 +931,71 @@ int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight_start, flo
        return ret;
 }
 
+// Replacement for broken mlt_frame_audio_mix - this filter uses an inline low pass filter
+// to allow mixing without volume hacking
+int mlt_frame_combine_audio( mlt_frame this, mlt_frame that, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
+{
+       int ret = 0;
+       int16_t *src, *dest;
+       int frequency_src = *frequency, frequency_dest = *frequency;
+       int channels_src = *channels, channels_dest = *channels;
+       int samples_src = *samples, samples_dest = *samples;
+       int i, j;
+       double vp[ 6 ];
+       double b_weight = 1.0;
+
+       if ( mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "meta.mixdown" ) )
+               b_weight = 1.0 - mlt_properties_get_double( MLT_FRAME_PROPERTIES( this ), "meta.volume" );
+
+       mlt_frame_get_audio( that, &src, format, &frequency_src, &channels_src, &samples_src );
+       mlt_frame_get_audio( this, &dest, format, &frequency_dest, &channels_dest, &samples_dest );
+
+       int silent = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "silent_audio" );
+       mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "silent_audio", 0 );
+       if ( silent )
+               memset( dest, 0, samples_dest * channels_dest * sizeof( int16_t ) );
+
+       silent = mlt_properties_get_int( MLT_FRAME_PROPERTIES( that ), "silent_audio" );
+       mlt_properties_set_int( MLT_FRAME_PROPERTIES( that ), "silent_audio", 0 );
+       if ( silent )
+               memset( src, 0, samples_src * channels_src * sizeof( int16_t ) );
+
+       if ( src == dest )
+       {
+               *samples = samples_src;
+               *channels = channels_src;
+               *buffer = src;
+               *frequency = frequency_src;
+               return ret;
+       }
+
+       // determine number of samples to process
+       *samples = samples_src < samples_dest ? samples_src : samples_dest;
+       *channels = channels_src < channels_dest ? channels_src : channels_dest;
+       *buffer = dest;
+       *frequency = frequency_dest;
+
+       for ( j = 0; j < *channels; j++ )
+               vp[ j ] = ( double )dest[ j ];
+
+       double Fc = 0.5;
+       double B = exp(-2.0 * M_PI * Fc);
+       double A = 1.0 - B;
+       double v;
+       
+       for ( i = 0; i < *samples; i++ )
+       {
+               for ( j = 0; j < *channels; j++ )
+               {
+                       v = ( double )( b_weight * dest[ i * channels_dest + j ] + src[ i * channels_src + j ] );
+                       v = v < -32767 ? -32767 : v > 32768 ? 32768 : v;
+                       vp[ j ] = dest[ i * channels_dest + j ] = ( int16_t )( v * A + vp[ j ] * B );
+               }
+       }
+
+       return ret;
+}
+
 /* Will this break when mlt_position is converted to double? -Zach */
 int mlt_sample_calculator( float fps, int frequency, int64_t position )
 {
index 18b1e608edb1e1e642e5bce7ac91b9e1c18b2ce0..9aa996c9f7b332a0d9d57e9f2b29a7a38667b553 100644 (file)
@@ -81,6 +81,7 @@ extern uint8_t *mlt_frame_resize_yuv422( mlt_frame self, int owidth, int oheight
 extern uint8_t *mlt_frame_rescale_yuv422( mlt_frame self, int owidth, int oheight );
 extern void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input, int iwidth, int iheight );
 extern int mlt_frame_mix_audio( mlt_frame self, mlt_frame that, float weight_start, float weight_end, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples  );
+extern int mlt_frame_combine_audio( mlt_frame self, mlt_frame that, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples  );
 extern int mlt_sample_calculator( float fps, int frequency, int64_t position );
 extern int64_t mlt_sample_calculator_to_now( float fps, int frequency, int64_t position );