11/*
22 * transition_mix.c -- mix two audio streams
3- * Copyright (C) 2003-2020 Meltytech, LLC
3+ * Copyright (C) 2003-2026 Meltytech, LLC
44 *
55 * This library is free software; you can redistribute it and/or
66 * modify it under the terms of the GNU Lesser General Public
@@ -49,7 +49,8 @@ static void mix_audio(double weight_start,
4949 int channels_a ,
5050 int channels_b ,
5151 int channels_out ,
52- int samples )
52+ int samples ,
53+ int power )
5354{
5455 int i , j ;
5556 double a , b , v ;
@@ -59,10 +60,12 @@ static void mix_audio(double weight_start,
5960 double mix_step = (weight_end - weight_start ) / samples ;
6061
6162 for (i = 0 ; i < samples ; i ++ ) {
63+ double gain_b = power ? sin (mix * M_PI_2 ) : mix ;
64+ double gain_a = power ? cos (mix * M_PI_2 ) : 1.0 - mix ;
6265 for (j = 0 ; j < channels_out ; j ++ ) {
6366 a = (double ) buffer_a [i * channels_a + j ];
6467 b = (double ) buffer_b [i * channels_b + j ];
65- v = mix * b + ( 1.0 - mix ) * a ;
68+ v = gain_b * b + gain_a * a ;
6669 buffer_a [i * channels_a + j ] = v ;
6770 }
6871 mix += mix_step ;
@@ -280,7 +283,17 @@ static int transition_get_audio(mlt_frame frame_a,
280283 mix_start = 1.0 - mix_start ;
281284 mix_end = 1.0 - mix_end ;
282285 }
283- mix_audio (mix_start , mix_end , buffer_a , buffer_b , channels_a , channels_b , * channels , * samples );
286+ int power = mlt_properties_get_double (MLT_TRANSITION_PROPERTIES (transition ), "start" )
287+ < -1.0 ;
288+ mix_audio (mix_start ,
289+ mix_end ,
290+ buffer_a ,
291+ buffer_b ,
292+ channels_a ,
293+ channels_b ,
294+ * channels ,
295+ * samples ,
296+ power );
284297 }
285298
286299 // Copy the audio from the dest buffer into the frame.
0 commit comments