X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Ftransition_mix.c;h=a9bef5cd9d241cba313ac2be3ed771fde59b5ad6;hb=41fffb7a1b11ad7dc05236043108d8edab1f6b91;hp=1f084719991a9d3bc8243987b3c29ef329658403;hpb=52fa2474c1a2472022dd12ccea5c794f66532012;p=melted diff --git a/src/modules/core/transition_mix.c b/src/modules/core/transition_mix.c index 1f08471..a9bef5c 100644 --- a/src/modules/core/transition_mix.c +++ b/src/modules/core/transition_mix.c @@ -30,31 +30,34 @@ static int transition_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples ) { - // Get the properties of the a frame - mlt_properties a_props = mlt_frame_properties( frame ); - // Get the b frame from the stack mlt_frame b_frame = mlt_frame_pop_audio( frame ); + // Get the effect + mlt_transition effect = mlt_frame_pop_audio( frame ); + // Get the properties of the b frame - mlt_properties b_props = mlt_frame_properties( b_frame ); + mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame ); - // Restore the original get_audio - frame->get_audio = mlt_properties_get_data( a_props, "mix.get_audio", NULL ); + if ( mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( effect ), "combine" ) == 0 ) + { + double mix_start = 0.5, mix_end = 0.5; + if ( mlt_properties_get( b_props, "audio.previous_mix" ) != NULL ) + mix_start = mlt_properties_get_double( b_props, "audio.previous_mix" ); + if ( mlt_properties_get( b_props, "audio.mix" ) != NULL ) + mix_end = mlt_properties_get_double( b_props, "audio.mix" ); + if ( mlt_properties_get_int( b_props, "audio.reverse" ) ) + { + mix_start = 1 - mix_start; + mix_end = 1 - mix_end; + } - double mix_start = 0.5, mix_end = 0.5; - if ( mlt_properties_get( b_props, "audio.previous_mix" ) != NULL ) - mix_start = mlt_properties_get_double( b_props, "audio.previous_mix" ); - if ( mlt_properties_get( b_props, "audio.mix" ) != NULL ) - mix_end = mlt_properties_get_double( b_props, "audio.mix" ); - if ( mlt_properties_get_int( b_props, "audio.reverse" ) ) + mlt_frame_mix_audio( frame, b_frame, mix_start, mix_end, buffer, format, frequency, channels, samples ); + } + else { - mix_start = 1 - mix_start; - mix_end = 1 - mix_end; + mlt_frame_combine_audio( frame, b_frame, buffer, format, frequency, channels, samples ); } - //fprintf( stderr, "transition_mix: previous %f current %f\n", mix_start, mix_end ); - - mlt_frame_mix_audio( frame, b_frame, mix_start, mix_end, buffer, format, frequency, channels, samples ); return 0; } @@ -65,62 +68,81 @@ static int transition_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_fo static mlt_frame transition_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame ) { - mlt_properties properties = mlt_transition_properties( this ); - mlt_properties b_props = mlt_frame_properties( b_frame ); + mlt_properties properties = MLT_TRANSITION_PROPERTIES( this ); + mlt_properties b_props = MLT_FRAME_PROPERTIES( b_frame ); // Only if mix is specified, otherwise a producer may set the mix if ( mlt_properties_get( properties, "start" ) != NULL ) { // Determine the time position of this frame in the transition duration - mlt_position in = mlt_transition_get_in( this ); - mlt_position out = mlt_transition_get_out( this ); - mlt_position time = mlt_frame_get_position( b_frame ); + mlt_properties props = mlt_properties_get_data( MLT_FRAME_PROPERTIES( b_frame ), "_producer", NULL ); + int always_active = mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( this ), "always_active" ); + mlt_position in = !always_active ? mlt_transition_get_in( this ) : mlt_properties_get_int( props, "in" ); + mlt_position out = !always_active ? mlt_transition_get_out( this ) : mlt_properties_get_int( props, "out" ); + int length = mlt_properties_get_int( MLT_TRANSITION_PROPERTIES( this ), "length" ); + mlt_position time = !always_active ? mlt_frame_get_position( b_frame ) : mlt_properties_get_int( props, "_frame" ); double mix = ( double )( time - in ) / ( double )( out - in + 1 ); - - // If there is an end mix level adjust mix to the range - if ( mlt_properties_get( properties, "end" ) != NULL ) - { - double start = mlt_properties_get_double( properties, "start" ); - double end = mlt_properties_get_double( properties, "end" ); - mix = start + ( end - start ) * mix; - } - // A negative means total crossfade (uses position) - else if ( mlt_properties_get_double( properties, "start" ) >= 0 ) + + // TODO: Check the logic here - shouldn't we be computing current and next mixing levels in all cases? + if ( length == 0 ) { - // Otherwise, start/constructor is a constant mix level - mix = mlt_properties_get_double( properties, "start" ); - } + // If there is an end mix level adjust mix to the range + if ( mlt_properties_get( properties, "end" ) != NULL ) + { + double start = mlt_properties_get_double( properties, "start" ); + double end = mlt_properties_get_double( properties, "end" ); + mix = start + ( end - start ) * mix; + } + // A negative means total crossfade (uses position) + else if ( mlt_properties_get_double( properties, "start" ) >= 0 ) + { + // Otherwise, start/constructor is a constant mix level + mix = mlt_properties_get_double( properties, "start" ); + } + + // Finally, set the mix property on the frame + mlt_properties_set_double( b_props, "audio.mix", mix ); - // Finally, set the mix property on the frame - mlt_properties_set_double( b_props, "audio.mix", mix ); - - // Initialise transition previous mix value to prevent an inadvertant jump from 0 - if ( mlt_properties_get( properties, "previous_mix" ) == NULL ) + // Initialise transition previous mix value to prevent an inadvertant jump from 0 + if ( mlt_properties_get( properties, "previous_mix" ) == NULL ) + mlt_properties_set_double( properties, "previous_mix", mlt_properties_get_double( b_props, "audio.mix" ) ); + + // Tell b frame what the previous mix level was + mlt_properties_set_double( b_props, "audio.previous_mix", mlt_properties_get_double( properties, "previous_mix" ) ); + + // Save the current mix level for the next iteration mlt_properties_set_double( properties, "previous_mix", mlt_properties_get_double( b_props, "audio.mix" ) ); - - // Tell b frame what the previous mix level was - mlt_properties_set_double( b_props, "audio.previous_mix", mlt_properties_get_double( properties, "previous_mix" ) ); - - // Save the current mix level for the next iteration - mlt_properties_set_double( properties, "previous_mix", mlt_properties_get_double( b_props, "audio.mix" ) ); - mlt_properties_set_double( b_props, "audio.reverse", mlt_properties_get_double( properties, "reverse" ) ); - } - - // Ensure that the tractor knows this isn't test audio... - if ( mlt_properties_get_int( mlt_frame_properties( a_frame ), "test_audio" ) ) - { - mlt_properties_set_int( mlt_frame_properties( a_frame ), "test_audio", 0 ); - mlt_properties_set_int( mlt_frame_properties( a_frame ), "silent_audio", 1 ); + mlt_properties_set_double( b_props, "audio.reverse", mlt_properties_get_double( properties, "reverse" ) ); + } + else + { + double level = mlt_properties_get_double( properties, "start" ); + double mix_start = level; + double mix_end = mix_start; + double mix_increment = 1.0 / length; + if ( time - in < length ) + { + mix_start = mix_start * ( ( double )( time - in ) / length ); + mix_end = mix_start + mix_increment; + } + else if ( time > out - length ) + { + mix_end = mix_start * ( ( double )( out - time - in ) / length ); + mix_start = mix_end - mix_increment; + } + + mix_start = mix_start < 0 ? 0 : mix_start > level ? level : mix_start; + mix_end = mix_end < 0 ? 0 : mix_end > level ? level : mix_end; + mlt_properties_set_double( b_props, "audio.previous_mix", mix_start ); + mlt_properties_set_double( b_props, "audio.mix", mix_end ); + } } - // Backup the original get_audio (it's still needed) - mlt_properties_set_data( mlt_frame_properties( a_frame ), "mix.get_audio", a_frame->get_audio, 0, NULL, NULL ); - // Override the get_audio method - a_frame->get_audio = transition_get_audio; - + mlt_frame_push_audio( a_frame, this ); mlt_frame_push_audio( a_frame, b_frame ); + mlt_frame_push_audio( a_frame, transition_get_audio ); return a_frame; } @@ -135,8 +157,9 @@ mlt_transition transition_mix_init( char *arg ) { this->process = transition_process; if ( arg != NULL ) - mlt_properties_set_double( mlt_transition_properties( this ), "start", atof( arg ) ); - mlt_properties_set_int( mlt_transition_properties( this ), "_accepts_blanks", 1 ); + mlt_properties_set_double( MLT_TRANSITION_PROPERTIES( this ), "start", atof( arg ) ); + // Inform apps and framework that this is an audio only transition + mlt_properties_set_int( MLT_TRANSITION_PROPERTIES( this ), "_transition_type", 2 ); } return this; }