2 * mlt_frame.c -- interface for all frame classes
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "mlt_frame.h"
23 #include "mlt_producer.h"
24 #include "mlt_factory.h"
29 /** Constructor for a frame.
32 mlt_frame mlt_frame_init( )
35 mlt_frame this = calloc( sizeof( struct mlt_frame_s ), 1 );
39 // Get the normalisation
40 char *normalisation = mlt_environment( "MLT_NORMALISATION" );
42 // Initialise the properties
43 mlt_properties properties = &this->parent;
44 mlt_properties_init( properties, this );
46 // Set default properties on the frame
47 mlt_properties_set_position( properties, "_position", 0.0 );
48 mlt_properties_set_data( properties, "image", NULL, 0, NULL, NULL );
50 if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) )
52 mlt_properties_set_int( properties, "width", 720 );
53 mlt_properties_set_int( properties, "height", 576 );
54 mlt_properties_set_int( properties, "normalised_width", 720 );
55 mlt_properties_set_int( properties, "normalised_height", 576 );
56 mlt_properties_set_double( properties, "aspect_ratio", 59.0/54.0 );
60 mlt_properties_set_int( properties, "width", 720 );
61 mlt_properties_set_int( properties, "height", 480 );
62 mlt_properties_set_int( properties, "normalised_width", 720 );
63 mlt_properties_set_int( properties, "normalised_height", 480 );
64 mlt_properties_set_double( properties, "aspect_ratio", 10.0/11.0 );
67 mlt_properties_set_data( properties, "audio", NULL, 0, NULL, NULL );
68 mlt_properties_set_data( properties, "alpha", NULL, 0, NULL, NULL );
70 // Construct stacks for frames and methods
71 this->stack_image = mlt_deque_init( );
72 this->stack_audio = mlt_deque_init( );
73 this->stack_service = mlt_deque_init( );
79 /** Fetch the frames properties.
82 mlt_properties mlt_frame_properties( mlt_frame this )
84 return this != NULL ? &this->parent : NULL;
87 /** Check if we have a way to derive something other than a test card.
90 int mlt_frame_is_test_card( mlt_frame this )
92 return mlt_deque_count( this->stack_image ) == 0 || mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "test_image" );
95 /** Check if we have a way to derive something than test audio.
98 int mlt_frame_is_test_audio( mlt_frame this )
100 return this->get_audio == NULL || mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "test_audio" );
103 /** Get the aspect ratio of the frame.
106 double mlt_frame_get_aspect_ratio( mlt_frame this )
108 return mlt_properties_get_double( MLT_FRAME_PROPERTIES( this ), "aspect_ratio" );
111 /** Set the aspect ratio of the frame.
114 int mlt_frame_set_aspect_ratio( mlt_frame this, double value )
116 return mlt_properties_set_double( MLT_FRAME_PROPERTIES( this ), "aspect_ratio", value );
119 /** Get the position of this frame.
122 mlt_position mlt_frame_get_position( mlt_frame this )
124 int pos = mlt_properties_get_position( MLT_FRAME_PROPERTIES( this ), "_position" );
125 return pos < 0 ? 0 : pos;
128 /** Set the position of this frame.
131 int mlt_frame_set_position( mlt_frame this, mlt_position value )
133 return mlt_properties_set_position( MLT_FRAME_PROPERTIES( this ), "_position", value );
136 /** Stack a get_image callback.
139 int mlt_frame_push_get_image( mlt_frame this, mlt_get_image get_image )
141 return mlt_deque_push_back( this->stack_image, get_image );
144 /** Pop a get_image callback.
147 mlt_get_image mlt_frame_pop_get_image( mlt_frame this )
149 return mlt_deque_pop_back( this->stack_image );
155 int mlt_frame_push_frame( mlt_frame this, mlt_frame that )
157 return mlt_deque_push_back( this->stack_image, that );
163 mlt_frame mlt_frame_pop_frame( mlt_frame this )
165 return mlt_deque_pop_back( this->stack_image );
171 int mlt_frame_push_service( mlt_frame this, void *that )
173 return mlt_deque_push_back( this->stack_image, that );
179 void *mlt_frame_pop_service( mlt_frame this )
181 return mlt_deque_pop_back( this->stack_image );
184 /** Push an audio item on the stack.
187 int mlt_frame_push_audio( mlt_frame this, void *that )
189 return mlt_deque_push_back( this->stack_audio, that );
192 /** Pop an audio item from the stack
195 void *mlt_frame_pop_audio( mlt_frame this )
197 return mlt_deque_pop_back( this->stack_audio );
200 /** Return the service stack
203 mlt_deque mlt_frame_service_stack( mlt_frame this )
205 return this->stack_service;
208 int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
210 mlt_properties properties = MLT_FRAME_PROPERTIES( this );
211 mlt_get_image get_image = mlt_frame_pop_get_image( this );
212 mlt_producer producer = mlt_properties_get_data( properties, "test_card_producer", NULL );
214 *width = *width >> 1 << 1;
216 if ( get_image != NULL )
219 mlt_position position = mlt_frame_get_position( this );
220 error = get_image( this, buffer, format, width, height, writable );
221 mlt_frame_set_position( this, position );
224 else if ( mlt_properties_get_data( properties, "image", NULL ) != NULL )
226 *format = mlt_image_yuv422;
227 *buffer = mlt_properties_get_data( properties, "image", NULL );
228 *width = mlt_properties_get_int( properties, "width" );
229 *height = mlt_properties_get_int( properties, "height" );
231 else if ( producer != NULL )
233 mlt_frame test_frame = NULL;
234 mlt_service_get_frame( MLT_PRODUCER_SERVICE( producer ), &test_frame, 0 );
235 if ( test_frame != NULL )
237 mlt_properties test_properties = MLT_FRAME_PROPERTIES( test_frame );
238 mlt_properties_set_double( test_properties, "consumer_aspect_ratio", mlt_properties_get_double( properties, "consumer_aspect_ratio" ) );
239 mlt_properties_set( test_properties, "rescale.interp", mlt_properties_get( properties, "rescale.interp" ) );
240 mlt_frame_get_image( test_frame, buffer, format, width, height, writable );
241 mlt_properties_set_data( properties, "test_card_frame", test_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
242 mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL );
243 mlt_properties_set_int( properties, "width", *width );
244 mlt_properties_set_int( properties, "height", *height );
245 mlt_properties_set_double( properties, "aspect_ratio", mlt_frame_get_aspect_ratio( test_frame ) );
249 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
250 mlt_frame_get_image( this, buffer, format, width, height, writable );
259 *width = *width == 0 ? 720 : *width;
260 *height = *height == 0 ? 576 : *height;
261 size = *width * *height;
263 mlt_properties_set_int( properties, "width", *width );
264 mlt_properties_set_int( properties, "height", *height );
265 mlt_properties_set_int( properties, "aspect_ratio", 1 );
273 case mlt_image_rgb24:
276 *buffer = mlt_pool_alloc( size );
278 memset( *buffer, 255, size );
280 case mlt_image_rgb24a:
283 *buffer = mlt_pool_alloc( size );
285 memset( *buffer, 255, size );
287 case mlt_image_yuv422:
290 *buffer = mlt_pool_alloc( size );
293 while ( p != NULL && p != q )
299 case mlt_image_yuv420p:
301 *buffer = mlt_pool_alloc( size );
303 memset( *buffer, 255, size );
307 mlt_properties_set_data( properties, "image", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
308 mlt_properties_set_int( properties, "test_image", 1 );
314 uint8_t *mlt_frame_get_alpha_mask( mlt_frame this )
316 if ( this != NULL && this->get_alpha_mask != NULL )
317 return this->get_alpha_mask( this );
318 return this == NULL ? NULL : mlt_properties_get_data( &this->parent, "alpha", NULL );
321 int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
323 mlt_properties properties = MLT_FRAME_PROPERTIES( this );
324 int hide = mlt_properties_get_int( properties, "test_audio" );
326 if ( hide == 0 && this->get_audio != NULL )
328 mlt_position position = mlt_frame_get_position( this );
329 this->get_audio( this, buffer, format, frequency, channels, samples );
330 mlt_frame_set_position( this, position );
332 else if ( mlt_properties_get_data( properties, "audio", NULL ) )
334 *buffer = mlt_properties_get_data( properties, "audio", NULL );
335 *frequency = mlt_properties_get_int( properties, "audio_frequency" );
336 *channels = mlt_properties_get_int( properties, "audio_channels" );
337 *samples = mlt_properties_get_int( properties, "audio_samples" );
342 *samples = *samples <= 0 ? 1920 : *samples;
343 *channels = *channels <= 0 ? 2 : *channels;
344 *frequency = *frequency <= 0 ? 48000 : *frequency;
345 size = *samples * *channels * sizeof( int16_t );
346 *buffer = mlt_pool_alloc( size );
347 if ( *buffer != NULL )
348 memset( *buffer, 0, size );
349 mlt_properties_set_data( properties, "audio", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
350 mlt_properties_set_int( properties, "test_audio", 1 );
353 mlt_properties_set_int( properties, "audio_frequency", *frequency );
354 mlt_properties_set_int( properties, "audio_channels", *channels );
355 mlt_properties_set_int( properties, "audio_samples", *samples );
357 if ( mlt_properties_get( properties, "meta.volume" ) )
359 double value = mlt_properties_get_double( properties, "meta.volume" );
362 memset( *buffer, 0, *samples * *channels * 2 );
363 mlt_properties_set_double( properties, "meta.volume", 1.0 );
365 else if ( value != 1.0 )
367 int total = *samples * *channels;
368 int16_t *p = *buffer;
374 mlt_properties_set_double( properties, "meta.volume", 1.0 );
381 unsigned char *mlt_frame_get_waveform( mlt_frame this, int w, int h )
384 mlt_properties properties = MLT_FRAME_PROPERTIES( this );
385 mlt_audio_format format = mlt_audio_pcm;
386 int frequency = 32000; // lower frequency available?
388 double fps = mlt_properties_get_double( properties, "fps" );
389 int samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) );
392 mlt_frame_get_audio( this, &pcm, &format, &frequency, &channels, &samples );
394 // Make an 8-bit buffer large enough to hold rendering
396 unsigned char *bitmap = ( unsigned char* )mlt_pool_alloc( size );
397 if ( bitmap != NULL )
398 memset( bitmap, 0, size );
399 mlt_properties_set_data( properties, "waveform", bitmap, size, ( mlt_destructor )mlt_pool_release, NULL );
401 // Render vertical lines
402 int16_t *ubound = pcm + samples * channels;
403 int skip = samples / w - 1;
406 // Iterate sample stream and along x coordinate
407 for ( i = 0; i < w && pcm < ubound; i++ )
409 // pcm data has channels interleaved
410 for ( j = 0; j < channels; j++ )
412 // Determine sample's magnitude from 2s complement;
413 int pcm_magnitude = *pcm < 0 ? ~(*pcm) + 1 : *pcm;
414 // The height of a line is the ratio of the magnitude multiplied by
415 // half the vertical resolution
416 int height = ( int )( ( double )( pcm_magnitude ) / 32768 * h / 2 );
417 // Determine the starting y coordinate - left channel above center,
418 // right channel below - currently assumes 2 channels
419 int displacement = ( h / 2 ) - ( 1 - j ) * height;
420 // Position buffer pointer using y coordinate, stride, and x coordinate
421 unsigned char *p = &bitmap[ i + displacement * w ];
423 // Draw vertical line
424 for ( k = 0; k < height; k++ )
429 pcm += skip * channels;
435 mlt_producer mlt_frame_get_original_producer( mlt_frame this )
438 return mlt_properties_get_data( MLT_FRAME_PROPERTIES( this ), "_producer", NULL );
442 void mlt_frame_close( mlt_frame this )
444 if ( this != NULL && mlt_properties_dec_ref( MLT_FRAME_PROPERTIES( this ) ) <= 0 )
446 mlt_deque_close( this->stack_image );
447 mlt_deque_close( this->stack_audio );
448 while( mlt_deque_peek_back( this->stack_service ) )
449 mlt_service_close( mlt_deque_pop_back( this->stack_service ) );
450 mlt_deque_close( this->stack_service );
451 mlt_properties_close( &this->parent );
456 /***** convenience functions *****/
458 int mlt_convert_rgb24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha )
461 register int y0, y1, u0, u1, v0, v1;
462 register int r, g, b;
463 register uint8_t *d = yuv;
466 for ( i = 0; i < height; i++ )
468 register uint8_t *s = rgba + ( stride * i );
469 for ( j = 0; j < ( width / 2 ); j++ )
475 RGB2YUV (r, g, b, y0, u0 , v0);
480 RGB2YUV (r, g, b, y1, u1 , v1);
492 RGB2YUV (r, g, b, y0, u0 , v0);
500 int mlt_convert_rgb24_to_yuv422( uint8_t *rgb, int width, int height, int stride, uint8_t *yuv )
503 register int y0, y1, u0, u1, v0, v1;
504 register int r, g, b;
505 register uint8_t *d = yuv;
508 for ( i = 0; i < height; i++ )
510 register uint8_t *s = rgb + ( stride * i );
511 for ( j = 0; j < ( width / 2 ); j++ )
516 RGB2YUV (r, g, b, y0, u0 , v0);
520 RGB2YUV (r, g, b, y1, u1 , v1);
531 RGB2YUV (r, g, b, y0, u0 , v0);
539 int mlt_convert_yuv420p_to_yuv422( uint8_t *yuv420p, int width, int height, int stride, uint8_t *yuv )
544 int half = width >> 1;
546 uint8_t *Y = yuv420p;
547 uint8_t *U = Y + width * height;
548 uint8_t *V = U + width * height / 4;
550 register uint8_t *d = yuv;
552 for ( i = 0; i < height; i++ )
554 register uint8_t *u = U + ( i / 2 ) * ( half );
555 register uint8_t *v = V + ( i / 2 ) * ( half );
557 for ( j = 0; j < half; j++ )
568 uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight )
570 uint8_t *output = NULL;
572 if ( input != NULL && ( iwidth != owidth || iheight != oheight ) )
574 iwidth = iwidth - ( iwidth % 2 );
575 owidth = owidth - ( owidth % 2 );
577 output = mlt_pool_alloc( owidth * oheight );
579 // Coordinates (0,0 is middle of output)
583 int out_x_range = owidth / 2;
584 int out_y_range = oheight / 2;
585 int in_x_range = iwidth / 2 < out_x_range ? iwidth / 2 : out_x_range;
586 int in_y_range = iheight / 2 < out_y_range ? iheight / 2 : out_y_range;
589 uint8_t *out_line = output;
590 uint8_t *out_ptr = out_line;
592 // Calculate a middle and possibly invalid pointer in the input
593 uint8_t *in_middle = input + iwidth * ( iheight / 2 ) + ( iwidth / 2 );
594 int in_line = - in_y_range * iwidth - in_x_range;
598 // Fill whole section with black
599 y = out_y_range - ( iheight / 2 );
600 int blank_elements = owidth * y;
601 elements = blank_elements;
602 while ( elements -- )
605 int active_width = iwidth;
606 int inactive_width = out_x_range - in_x_range;
610 // Loop for the entirety of our output height.
613 // Start at the beginning of the line
616 // Fill the outer part with black
617 elements = inactive_width;
618 while ( elements -- )
621 // We're in the input range for this row.
622 p = in_middle + in_line;
623 end = out_ptr + active_width;
624 while ( out_ptr != end )
627 // Fill the outer part with black
628 elements = inactive_width;
629 while ( elements -- )
632 // Move to next input line
635 // Move to next output line
639 // Fill whole section with black
640 elements = blank_elements;
641 while ( elements -- )
648 void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input, int iwidth, int iheight )
651 int istride = iwidth * 2;
652 int ostride = owidth * 2;
654 iwidth = iwidth - ( iwidth % 4 );
655 owidth = owidth - ( owidth % 4 );
656 //iheight = iheight - ( iheight % 2 );
657 //oheight = oheight - ( oheight % 2 );
659 // Optimisation point
660 if ( iwidth == owidth && iheight == oheight )
661 memcpy( output, input, iheight * istride );
663 // Coordinates (0,0 is middle of output)
667 int out_x_range = owidth / 2;
668 int out_y_range = oheight / 2;
669 int in_x_range = iwidth / 2 < out_x_range ? iwidth / 2 : out_x_range;
670 int in_y_range = iheight / 2 < out_y_range ? iheight / 2 : out_y_range;
673 uint8_t *out_line = output;
674 uint8_t *out_ptr = out_line;
676 // Calculate a middle and possibly invalid pointer in the input
677 uint8_t *in_middle = input + istride * ( iheight / 2 ) + ( iwidth / 2 ) * 2;
678 int in_line = - in_y_range * istride - in_x_range * 2;
682 // Fill whole section with black
683 y = out_y_range - ( iheight / 2 );
684 int blank_elements = ostride * y / 2;
685 elements = blank_elements;
686 while ( elements -- )
692 int active_width = 2 * iwidth;
693 int inactive_width = out_x_range - in_x_range;
697 // Loop for the entirety of our output height.
700 // Start at the beginning of the line
703 // Fill the outer part with black
704 elements = inactive_width;
705 while ( elements -- )
711 // We're in the input range for this row.
712 p = in_middle + in_line;
713 end = out_ptr + active_width;
714 while ( out_ptr != end )
720 // Fill the outer part with black
721 elements = inactive_width;
722 while ( elements -- )
728 // Move to next input line
731 // Move to next output line
735 // Fill whole section with black
736 elements = blank_elements;
737 while ( elements -- )
744 /** A resizing function for yuv422 frames - this does not rescale, but simply
745 resizes. It assumes yuv422 images available on the frame so use with care.
748 uint8_t *mlt_frame_resize_yuv422( mlt_frame this, int owidth, int oheight )
751 mlt_properties properties = MLT_FRAME_PROPERTIES( this );
753 // Get the input image, width and height
754 uint8_t *input = mlt_properties_get_data( properties, "image", NULL );
755 uint8_t *alpha = mlt_frame_get_alpha_mask( this );
757 int iwidth = mlt_properties_get_int( properties, "width" );
758 int iheight = mlt_properties_get_int( properties, "height" );
760 // If width and height are correct, don't do anything
761 if ( iwidth != owidth || iheight != oheight )
763 // Create the output image
764 uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
766 // Call the generic resize
767 mlt_resize_yuv422( output, owidth, oheight, input, iwidth, iheight );
769 // Now update the frame
770 mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
771 mlt_properties_set_int( properties, "width", owidth );
772 mlt_properties_set_int( properties, "height", oheight );
774 // We should resize the alpha too
775 alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight );
778 mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
779 this->get_alpha_mask = NULL;
785 // No change, return input
789 /** A rescaling function for yuv422 frames - low quality, and provided for testing
790 only. It assumes yuv422 images available on the frame so use with care.
793 uint8_t *mlt_frame_rescale_yuv422( mlt_frame this, int owidth, int oheight )
796 mlt_properties properties = MLT_FRAME_PROPERTIES( this );
798 // Get the input image, width and height
799 uint8_t *input = mlt_properties_get_data( properties, "image", NULL );
800 int iwidth = mlt_properties_get_int( properties, "width" );
801 int iheight = mlt_properties_get_int( properties, "height" );
803 // If width and height are correct, don't do anything
804 if ( iwidth != owidth || iheight != oheight )
806 // Create the output image
807 uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
810 int istride = iwidth * 2;
811 int ostride = owidth * 2;
813 iwidth = iwidth - ( iwidth % 4 );
815 // Derived coordinates
819 int out_x_range = owidth / 2;
820 int out_y_range = oheight / 2;
821 int in_x_range = iwidth / 2;
822 int in_y_range = iheight / 2;
825 register uint8_t *out_line = output;
826 register uint8_t *out_ptr;
828 // Calculate a middle pointer
829 uint8_t *in_middle = input + istride * in_y_range + in_x_range * 2;
832 // Generate the affine transform scaling values
833 register int scale_width = ( iwidth << 16 ) / owidth;
834 register int scale_height = ( iheight << 16 ) / oheight;
835 register int base = 0;
837 int outer = out_x_range * scale_width;
838 int bottom = out_y_range * scale_height;
840 // Loop for the entirety of our output height.
841 for ( dy = - bottom; dy < bottom; dy += scale_height )
843 // Start at the beginning of the line
846 // Pointer to the middle of the input line
847 in_line = in_middle + ( dy >> 16 ) * istride;
849 // Loop for the entirety of our output row.
850 for ( dx = - outer; dx < outer; dx += scale_width )
854 *out_ptr ++ = *( in_line + base );
856 *out_ptr ++ = *( in_line + base + 1 );
860 *out_ptr ++ = *( in_line + base );
862 *out_ptr ++ = *( in_line + base + 3 );
865 // Move to next output line
869 // Now update the frame
870 mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
871 mlt_properties_set_int( properties, "width", owidth );
872 mlt_properties_set_int( properties, "height", oheight );
878 // No change, return input
882 int mlt_frame_mix_audio( mlt_frame this, mlt_frame that, float weight_start, float weight_end, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
886 int frequency_src = *frequency, frequency_dest = *frequency;
887 int channels_src = *channels, channels_dest = *channels;
888 int samples_src = *samples, samples_dest = *samples;
892 mlt_frame_get_audio( this, &dest, format, &frequency_dest, &channels_dest, &samples_dest );
893 mlt_frame_get_audio( that, &src, format, &frequency_src, &channels_src, &samples_src );
895 int silent = mlt_properties_get_int( MLT_FRAME_PROPERTIES( this ), "silent_audio" );
896 mlt_properties_set_int( MLT_FRAME_PROPERTIES( this ), "silent_audio", 0 );
898 memset( dest, 0, samples_dest * channels_dest * sizeof( int16_t ) );
900 silent = mlt_properties_get_int( MLT_FRAME_PROPERTIES( that ), "silent_audio" );
901 mlt_properties_set_int( MLT_FRAME_PROPERTIES( that ), "silent_audio", 0 );
903 memset( src, 0, samples_src * channels_src * sizeof( int16_t ) );
905 if ( channels_src > 6 )
907 if ( channels_dest > 6 )
909 if ( samples_src > 4000 )
911 if ( samples_dest > 4000 )
914 // determine number of samples to process
915 *samples = samples_src < samples_dest ? samples_src : samples_dest;
916 *channels = channels_src < channels_dest ? channels_src : channels_dest;
918 *frequency = frequency_dest;
920 // Compute a smooth ramp over start to end
921 float weight = weight_start;
922 float weight_step = ( weight_end - weight_start ) / *samples;
925 for ( i = 0; i < *samples; i++ )
927 for ( j = 0; j < *channels; j++ )
929 if ( j < channels_dest )
930 d = (double) dest[ i * channels_dest + j ];
931 if ( j < channels_src )
932 s = (double) src[ i * channels_src + j ];
933 dest[ i * channels_dest + j ] = s * weight + d * ( 1.0 - weight );
935 weight += weight_step;
941 int mlt_sample_calculator( float fps, int frequency, int64_t position )
945 if ( ( int )( fps * 100 ) == 2997 )
947 samples = frequency / 30;
952 if ( position % 5 != 0 )
956 if ( position % 300 == 0 )
958 else if ( position % 30 == 0 )
960 else if ( position % 2 == 0 )
966 if ( position % 30 == 0 )
968 else if ( position % 29 == 0 )
970 else if ( position % 4 == 2 )
981 samples = frequency / fps;