]> git.sesse.net Git - mlt/commitdiff
attempt to retain samples in mlt_frame_mix_audio, make consumers request the number...
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sat, 10 Jan 2004 20:16:04 +0000 (20:16 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sat, 10 Jan 2004 20:16:04 +0000 (20:16 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@50 d19143bc-622f-0410-bfdd-b5b2a6649095

mlt/src/framework/mlt_frame.c
mlt/src/modules/core/transition_luma.c
mlt/src/modules/sdl/consumer_sdl.c
mlt/src/tests/dan.c
src/framework/mlt_frame.c
src/modules/core/transition_luma.c
src/modules/sdl/consumer_sdl.c
src/tests/dan.c

index 5a5701a007f68053853ad6dc1e8572f6c2ae40dc..3b11fcf1357317f3819f2dd7ecdde1cc2d562f21 100644 (file)
@@ -239,17 +239,20 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for
        }
        else
        {
+               if ( *samples <= 0 )
+                       *samples = 1920;
+               if ( *channels <= 0 )
+                       *channels = 2;
+               if ( *frequency <= 0 )
+                       *frequency = 48000;
                if ( test_card.afmt != *format )
                {
                        test_card.afmt = *format;
-                       test_card.audio = realloc( test_card.audio, 1920 * 2 * sizeof( int16_t ) );
-                       memset( test_card.audio, 0, 1920 * 2 * sizeof( int16_t ) );
+                       test_card.audio = realloc( test_card.audio, *samples * *channels * sizeof( int16_t ) );
+                       memset( test_card.audio, 0, *samples * *channels * sizeof( int16_t ) );
                }
                
                *buffer = test_card.audio;
-               *frequency = 48000;
-               *channels = 2;
-               *samples = 1920;
        }
        return 0;
 }
@@ -692,6 +695,9 @@ int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight, int16_t *
 {
        int ret = 0;
        int16_t *p_src, *p_dest;
+       int16_t *src, *dest;
+       static int16_t *extra_src = NULL, *extra_dest = NULL;
+       static int extra_src_samples = 0, extra_dest_samples = 0;
        int frequency_src, frequency_dest;
        int channels_src, channels_dest;
        int samples_src, samples_dest;
@@ -699,20 +705,86 @@ int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight, int16_t *
 
        mlt_frame_get_audio( this, &p_dest, format, &frequency_dest, &channels_dest, &samples_dest );
        mlt_frame_get_audio( that, &p_src, format, &frequency_src, &channels_src, &samples_src );
+       //fprintf( stderr, "frame dest samples %d channels %d\n", samples_dest, channels_dest );
+       //fprintf( stderr, "frame src  samples %d channels %d\n", samples_src, channels_src );
+       
 
-       *samples = samples_src < samples_dest ? samples_src : samples_dest;
+#if 0
+       // Append new samples to leftovers
+       if ( extra_dest_samples > 0 )
+       {
+               fprintf( stderr, "prepending %d samples to dest\n", extra_dest_samples );
+               dest = realloc( extra_dest, ( samples_dest + extra_dest_samples ) * 2 * channels_dest );
+               memcpy( &extra_dest[ extra_dest_samples * channels_dest ], p_dest, samples_dest * 2 * channels_dest );
+       }
+       else
+               dest = p_dest;
+       if ( extra_src_samples > 0 )
+       {
+               fprintf( stderr, "prepending %d samples to src\n", extra_src_samples );
+               src = realloc( extra_src, ( samples_src + extra_src_samples ) * 2 * channels_src );
+               memcpy( &extra_src[ extra_src_samples * channels_src ], p_src, samples_src * 2 * channels_src );
+       }
+       else
+               src = p_src;
+#else
+       src = p_src;
+       dest = p_dest;
+#endif
+
+       // determine number of samples to process       
+       if ( samples_src + extra_src_samples < samples_dest + extra_dest_samples )
+               *samples = samples_src + extra_src_samples;
+       else if ( samples_dest + extra_dest_samples < samples_src + extra_src_samples )
+               *samples = samples_dest + extra_dest_samples;
+       
        *channels = channels_src < channels_dest ? channels_src : channels_dest;
        *buffer = p_dest;
 
+       // Mixdown
        for ( i = 0; i < *samples; i++ )
        {
                for ( j = 0; j < *channels; j++ )
                {
-                       double dest = (double) p_dest[ i * channels_dest + j ];
-                       double src = (double) p_src[ i * channels_src + j ];
-                       p_dest[ i * channels_dest + j ] = src * weight + dest * ( 1.0 - weight );
+                       double d = (double) dest[ i * channels_dest + j ];
+                       double s = (double) src[ i * channels_src + j ];
+                       dest[ i * channels_dest + j ] = s * weight + d * ( 1.0 - weight );
                }
        }
+
+       // We have to copy --sigh
+       if ( dest != p_dest )
+               memcpy( p_dest, dest, *samples * 2 * *channels );
+
+#if 0
+       // Store the leftovers
+       if ( samples_src + extra_src_samples < samples_dest + extra_dest_samples )
+       {
+               extra_dest_samples = ( samples_dest + extra_dest_samples ) - ( samples_src + extra_src_samples );
+               size_t size = extra_dest_samples * 2 * channels_dest;
+               fprintf( stderr, "storing %d samples from dest\n", extra_dest_samples );
+               if ( extra_dest )
+                       free( extra_dest );
+               extra_dest = malloc( size );
+               if ( extra_dest )
+                       memcpy( extra_dest, &p_dest[ ( samples_dest - extra_dest_samples - 1 ) * channels_dest ], size );
+               else
+                       extra_dest_samples = 0;
+       }
+       else if ( samples_dest + extra_dest_samples < samples_src + extra_src_samples )
+       {
+               extra_src_samples = ( samples_src + extra_src_samples ) - ( samples_dest + extra_dest_samples );
+               size_t size = extra_src_samples * 2 * channels_src;
+               fprintf( stderr, "storing %d samples from src\n", extra_dest_samples );
+               if ( extra_src )
+                       free( extra_src );
+               extra_src = malloc( size );
+               if ( extra_src )
+                       memcpy( extra_src, &p_src[ ( samples_src - extra_src_samples - 1 ) * channels_src ], size );
+               else
+                       extra_src_samples = 0;
+       }
+#endif
        
        return ret;
 }
index fa6d7c3b39d8a00188f48ec09ed3271815e18eca..f5be459836fc8ee18cbb0ea50b9867572e218dda 100644 (file)
@@ -352,12 +352,13 @@ static mlt_frame transition_process( mlt_transition transition, mlt_frame a_fram
        mlt_frame_push_frame( a_frame, b_frame );
 
 /************************ AUDIO ***************************/
+#if 1
        // Backup the original get_audio (it's still needed)
        mlt_properties_set_data( mlt_frame_properties( a_frame ), "get_audio", a_frame->get_audio, 0, NULL, NULL );
 
        // Override the get_audio method
        a_frame->get_audio = transition_get_audio;
-
+#endif
        return a_frame;
 }
 
index 2725d1df715f55d3078866176c15575dd7b00cea..943a0d1be0f9d3118ec0a3b28185463f3d07376f 100644 (file)
@@ -199,9 +199,13 @@ static int consumer_play_audio( consumer_sdl this, mlt_frame frame, int init_aud
        // Get the properties of this consumer
        mlt_properties properties = this->properties;
        mlt_audio_format afmt = mlt_audio_pcm;
-       int channels = 0;
-       int samples;
-       int frequency;
+
+       // Set the preferred params of the test card signal
+       int channels = 2;
+       int frequency = 48000;
+       static int counter = 0;
+       int samples = mlt_sample_calculator( ( this->height < 576 ? 29.97 : 25 ), frequency, counter++ );
+       
        int16_t *pcm;
        int bytes;
 
index a896b146058c339d7280d6073a856c1048eb6bc7..b33cb7e89bbe039f18dc60fbf537797cebbe10da 100644 (file)
@@ -23,9 +23,9 @@ int main( int argc, char **argv )
 
        // Create the producer(s)
        mlt_producer dv1 = mlt_factory_producer( "mcdv", file1 );
-       mlt_producer_set_in_and_out( dv1, 300.0, 303.0 );
+       mlt_producer_set_in_and_out( dv1, 300, 305 );
        
-       mlt_producer dv2 = mlt_factory_producer( "mcmpeg", file2 );
+       mlt_producer dv2 = mlt_factory_producer( "mcdv", file2 );
        //mlt_producer_set_in_and_out( dv2, 10.0, 30.0 );
 
 #if 0
@@ -43,22 +43,22 @@ int main( int argc, char **argv )
        //mlt_producer dv2 = producer_libdv_init( file2 );
        //mlt_producer dv2 = mlt_factory_producer( "pixbuf", file2 );
 #if 0
-       mlt_producer dv2 = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" );
-       mlt_properties_set( mlt_producer_properties( dv2 ), "font", "Sans Bold 36" );
-       mlt_properties_set( mlt_producer_properties( dv2 ), "text", "Mutton Lettuce\nTomato" );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "video_standard", mlt_video_standard_ntsc );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "bgcolor", 0x0000007f );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "pad", 8 );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "align", 1 );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "x", -20 );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "y", 40 );
+       mlt_producer title = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" );
+       mlt_properties_set_int( mlt_producer_properties( title ), "video_standard", mlt_video_standard_ntsc );
+       mlt_properties_set( mlt_producer_properties( title ), "font", "Sans Bold 36" );
+       mlt_properties_set( mlt_producer_properties( title ), "text", "Mutton Lettuce\nTomato" );
+       mlt_properties_set_int( mlt_producer_properties( title ), "bgcolor", 0x0000007f );
+       mlt_properties_set_int( mlt_producer_properties( title ), "pad", 8 );
+       mlt_properties_set_int( mlt_producer_properties( title ), "align", 1 );
+       mlt_properties_set_int( mlt_producer_properties( title ), "x", 20 );
+       mlt_properties_set_int( mlt_producer_properties( title ), "y", 40 );
 #endif
 
        mlt_playlist playlist1 = mlt_playlist_init();
        mlt_playlist_append( playlist1, dv1 );
 
        mlt_playlist playlist2 = mlt_playlist_init();
-       mlt_playlist_blank( playlist2, 1.0 );
+       mlt_playlist_blank( playlist2, 3.0 );
        mlt_playlist_append( playlist2, dv2 );
        
        // Register producers(s) with a multitrack object
@@ -74,8 +74,8 @@ int main( int argc, char **argv )
        // Define a transition
        mlt_transition transition = mlt_factory_transition( "luma", NULL );
        mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 );
-       mlt_transition_set_in_and_out( transition, 1.0, 3.0 );
-       //mlt_properties_set( mlt_transition_properties( transition ), "filename", "clock.pgm" );
+       mlt_transition_set_in_and_out( transition, 3.0, 5.0 );
+       mlt_properties_set( mlt_transition_properties( transition ), "filename", "clock.pgm" );
        mlt_properties_set_double( mlt_transition_properties( transition ), "softness", 0.1 );
 
        // Buy a tractor and connect it to the filter
@@ -92,7 +92,7 @@ int main( int argc, char **argv )
        // Close everything...
        mlt_consumer_close( consumer );
        mlt_tractor_close( tractor );
-//     mlt_filter_close( filter );
+       mlt_transition_close( transition );
        mlt_multitrack_close( multitrack );
        mlt_producer_close( dv1 );
        mlt_producer_close( dv2 );
index 5a5701a007f68053853ad6dc1e8572f6c2ae40dc..3b11fcf1357317f3819f2dd7ecdde1cc2d562f21 100644 (file)
@@ -239,17 +239,20 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for
        }
        else
        {
+               if ( *samples <= 0 )
+                       *samples = 1920;
+               if ( *channels <= 0 )
+                       *channels = 2;
+               if ( *frequency <= 0 )
+                       *frequency = 48000;
                if ( test_card.afmt != *format )
                {
                        test_card.afmt = *format;
-                       test_card.audio = realloc( test_card.audio, 1920 * 2 * sizeof( int16_t ) );
-                       memset( test_card.audio, 0, 1920 * 2 * sizeof( int16_t ) );
+                       test_card.audio = realloc( test_card.audio, *samples * *channels * sizeof( int16_t ) );
+                       memset( test_card.audio, 0, *samples * *channels * sizeof( int16_t ) );
                }
                
                *buffer = test_card.audio;
-               *frequency = 48000;
-               *channels = 2;
-               *samples = 1920;
        }
        return 0;
 }
@@ -692,6 +695,9 @@ int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight, int16_t *
 {
        int ret = 0;
        int16_t *p_src, *p_dest;
+       int16_t *src, *dest;
+       static int16_t *extra_src = NULL, *extra_dest = NULL;
+       static int extra_src_samples = 0, extra_dest_samples = 0;
        int frequency_src, frequency_dest;
        int channels_src, channels_dest;
        int samples_src, samples_dest;
@@ -699,20 +705,86 @@ int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight, int16_t *
 
        mlt_frame_get_audio( this, &p_dest, format, &frequency_dest, &channels_dest, &samples_dest );
        mlt_frame_get_audio( that, &p_src, format, &frequency_src, &channels_src, &samples_src );
+       //fprintf( stderr, "frame dest samples %d channels %d\n", samples_dest, channels_dest );
+       //fprintf( stderr, "frame src  samples %d channels %d\n", samples_src, channels_src );
+       
 
-       *samples = samples_src < samples_dest ? samples_src : samples_dest;
+#if 0
+       // Append new samples to leftovers
+       if ( extra_dest_samples > 0 )
+       {
+               fprintf( stderr, "prepending %d samples to dest\n", extra_dest_samples );
+               dest = realloc( extra_dest, ( samples_dest + extra_dest_samples ) * 2 * channels_dest );
+               memcpy( &extra_dest[ extra_dest_samples * channels_dest ], p_dest, samples_dest * 2 * channels_dest );
+       }
+       else
+               dest = p_dest;
+       if ( extra_src_samples > 0 )
+       {
+               fprintf( stderr, "prepending %d samples to src\n", extra_src_samples );
+               src = realloc( extra_src, ( samples_src + extra_src_samples ) * 2 * channels_src );
+               memcpy( &extra_src[ extra_src_samples * channels_src ], p_src, samples_src * 2 * channels_src );
+       }
+       else
+               src = p_src;
+#else
+       src = p_src;
+       dest = p_dest;
+#endif
+
+       // determine number of samples to process       
+       if ( samples_src + extra_src_samples < samples_dest + extra_dest_samples )
+               *samples = samples_src + extra_src_samples;
+       else if ( samples_dest + extra_dest_samples < samples_src + extra_src_samples )
+               *samples = samples_dest + extra_dest_samples;
+       
        *channels = channels_src < channels_dest ? channels_src : channels_dest;
        *buffer = p_dest;
 
+       // Mixdown
        for ( i = 0; i < *samples; i++ )
        {
                for ( j = 0; j < *channels; j++ )
                {
-                       double dest = (double) p_dest[ i * channels_dest + j ];
-                       double src = (double) p_src[ i * channels_src + j ];
-                       p_dest[ i * channels_dest + j ] = src * weight + dest * ( 1.0 - weight );
+                       double d = (double) dest[ i * channels_dest + j ];
+                       double s = (double) src[ i * channels_src + j ];
+                       dest[ i * channels_dest + j ] = s * weight + d * ( 1.0 - weight );
                }
        }
+
+       // We have to copy --sigh
+       if ( dest != p_dest )
+               memcpy( p_dest, dest, *samples * 2 * *channels );
+
+#if 0
+       // Store the leftovers
+       if ( samples_src + extra_src_samples < samples_dest + extra_dest_samples )
+       {
+               extra_dest_samples = ( samples_dest + extra_dest_samples ) - ( samples_src + extra_src_samples );
+               size_t size = extra_dest_samples * 2 * channels_dest;
+               fprintf( stderr, "storing %d samples from dest\n", extra_dest_samples );
+               if ( extra_dest )
+                       free( extra_dest );
+               extra_dest = malloc( size );
+               if ( extra_dest )
+                       memcpy( extra_dest, &p_dest[ ( samples_dest - extra_dest_samples - 1 ) * channels_dest ], size );
+               else
+                       extra_dest_samples = 0;
+       }
+       else if ( samples_dest + extra_dest_samples < samples_src + extra_src_samples )
+       {
+               extra_src_samples = ( samples_src + extra_src_samples ) - ( samples_dest + extra_dest_samples );
+               size_t size = extra_src_samples * 2 * channels_src;
+               fprintf( stderr, "storing %d samples from src\n", extra_dest_samples );
+               if ( extra_src )
+                       free( extra_src );
+               extra_src = malloc( size );
+               if ( extra_src )
+                       memcpy( extra_src, &p_src[ ( samples_src - extra_src_samples - 1 ) * channels_src ], size );
+               else
+                       extra_src_samples = 0;
+       }
+#endif
        
        return ret;
 }
index fa6d7c3b39d8a00188f48ec09ed3271815e18eca..f5be459836fc8ee18cbb0ea50b9867572e218dda 100644 (file)
@@ -352,12 +352,13 @@ static mlt_frame transition_process( mlt_transition transition, mlt_frame a_fram
        mlt_frame_push_frame( a_frame, b_frame );
 
 /************************ AUDIO ***************************/
+#if 1
        // Backup the original get_audio (it's still needed)
        mlt_properties_set_data( mlt_frame_properties( a_frame ), "get_audio", a_frame->get_audio, 0, NULL, NULL );
 
        // Override the get_audio method
        a_frame->get_audio = transition_get_audio;
-
+#endif
        return a_frame;
 }
 
index 2725d1df715f55d3078866176c15575dd7b00cea..943a0d1be0f9d3118ec0a3b28185463f3d07376f 100644 (file)
@@ -199,9 +199,13 @@ static int consumer_play_audio( consumer_sdl this, mlt_frame frame, int init_aud
        // Get the properties of this consumer
        mlt_properties properties = this->properties;
        mlt_audio_format afmt = mlt_audio_pcm;
-       int channels = 0;
-       int samples;
-       int frequency;
+
+       // Set the preferred params of the test card signal
+       int channels = 2;
+       int frequency = 48000;
+       static int counter = 0;
+       int samples = mlt_sample_calculator( ( this->height < 576 ? 29.97 : 25 ), frequency, counter++ );
+       
        int16_t *pcm;
        int bytes;
 
index a896b146058c339d7280d6073a856c1048eb6bc7..b33cb7e89bbe039f18dc60fbf537797cebbe10da 100644 (file)
@@ -23,9 +23,9 @@ int main( int argc, char **argv )
 
        // Create the producer(s)
        mlt_producer dv1 = mlt_factory_producer( "mcdv", file1 );
-       mlt_producer_set_in_and_out( dv1, 300.0, 303.0 );
+       mlt_producer_set_in_and_out( dv1, 300, 305 );
        
-       mlt_producer dv2 = mlt_factory_producer( "mcmpeg", file2 );
+       mlt_producer dv2 = mlt_factory_producer( "mcdv", file2 );
        //mlt_producer_set_in_and_out( dv2, 10.0, 30.0 );
 
 #if 0
@@ -43,22 +43,22 @@ int main( int argc, char **argv )
        //mlt_producer dv2 = producer_libdv_init( file2 );
        //mlt_producer dv2 = mlt_factory_producer( "pixbuf", file2 );
 #if 0
-       mlt_producer dv2 = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" );
-       mlt_properties_set( mlt_producer_properties( dv2 ), "font", "Sans Bold 36" );
-       mlt_properties_set( mlt_producer_properties( dv2 ), "text", "Mutton Lettuce\nTomato" );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "video_standard", mlt_video_standard_ntsc );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "bgcolor", 0x0000007f );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "pad", 8 );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "align", 1 );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "x", -20 );
-       mlt_properties_set_int( mlt_producer_properties( dv2 ), "y", 40 );
+       mlt_producer title = mlt_factory_producer( "pango", NULL ); //"<span font_desc=\"Sans Bold 36\">Mutton <span font_desc=\"Luxi Serif Bold Oblique 36\">Lettuce</span> Tomato</span>" );
+       mlt_properties_set_int( mlt_producer_properties( title ), "video_standard", mlt_video_standard_ntsc );
+       mlt_properties_set( mlt_producer_properties( title ), "font", "Sans Bold 36" );
+       mlt_properties_set( mlt_producer_properties( title ), "text", "Mutton Lettuce\nTomato" );
+       mlt_properties_set_int( mlt_producer_properties( title ), "bgcolor", 0x0000007f );
+       mlt_properties_set_int( mlt_producer_properties( title ), "pad", 8 );
+       mlt_properties_set_int( mlt_producer_properties( title ), "align", 1 );
+       mlt_properties_set_int( mlt_producer_properties( title ), "x", 20 );
+       mlt_properties_set_int( mlt_producer_properties( title ), "y", 40 );
 #endif
 
        mlt_playlist playlist1 = mlt_playlist_init();
        mlt_playlist_append( playlist1, dv1 );
 
        mlt_playlist playlist2 = mlt_playlist_init();
-       mlt_playlist_blank( playlist2, 1.0 );
+       mlt_playlist_blank( playlist2, 3.0 );
        mlt_playlist_append( playlist2, dv2 );
        
        // Register producers(s) with a multitrack object
@@ -74,8 +74,8 @@ int main( int argc, char **argv )
        // Define a transition
        mlt_transition transition = mlt_factory_transition( "luma", NULL );
        mlt_transition_connect( transition, mlt_multitrack_service( multitrack ), 0, 1 );
-       mlt_transition_set_in_and_out( transition, 1.0, 3.0 );
-       //mlt_properties_set( mlt_transition_properties( transition ), "filename", "clock.pgm" );
+       mlt_transition_set_in_and_out( transition, 3.0, 5.0 );
+       mlt_properties_set( mlt_transition_properties( transition ), "filename", "clock.pgm" );
        mlt_properties_set_double( mlt_transition_properties( transition ), "softness", 0.1 );
 
        // Buy a tractor and connect it to the filter
@@ -92,7 +92,7 @@ int main( int argc, char **argv )
        // Close everything...
        mlt_consumer_close( consumer );
        mlt_tractor_close( tractor );
-//     mlt_filter_close( filter );
+       mlt_transition_close( transition );
        mlt_multitrack_close( multitrack );
        mlt_producer_close( dv1 );
        mlt_producer_close( dv2 );