}
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;
}
{
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;
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;
}
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;
}
// 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;
// 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
//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
// 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
// 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 );
}
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;
}
{
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;
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;
}
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;
}
// 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;
// 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
//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
// 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
// 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 );