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( );
78 /** Fetch the frames properties.
81 mlt_properties mlt_frame_properties( mlt_frame this )
83 return this != NULL ? &this->parent : NULL;
86 /** Check if we have a way to derive something other than a test card.
89 int mlt_frame_is_test_card( mlt_frame this )
91 return mlt_deque_count( this->stack_image ) == 0 || mlt_properties_get_int( mlt_frame_properties( this ), "test_image" );
94 /** Check if we have a way to derive something than test audio.
97 int mlt_frame_is_test_audio( mlt_frame this )
99 return this->get_audio == NULL || mlt_properties_get_int( mlt_frame_properties( this ), "test_audio" );
102 /** Get the aspect ratio of the frame.
105 double mlt_frame_get_aspect_ratio( mlt_frame this )
107 return mlt_properties_get_double( mlt_frame_properties( this ), "aspect_ratio" );
110 /** Set the aspect ratio of the frame.
113 int mlt_frame_set_aspect_ratio( mlt_frame this, double value )
115 return mlt_properties_set_double( mlt_frame_properties( this ), "aspect_ratio", value );
118 /** Get the position of this frame.
121 mlt_position mlt_frame_get_position( mlt_frame this )
123 int pos = mlt_properties_get_position( mlt_frame_properties( this ), "_position" );
124 return pos < 0 ? 0 : pos;
127 /** Set the position of this frame.
130 int mlt_frame_set_position( mlt_frame this, mlt_position value )
132 return mlt_properties_set_position( mlt_frame_properties( this ), "_position", value );
135 /** Stack a get_image callback.
138 int mlt_frame_push_get_image( mlt_frame this, mlt_get_image get_image )
140 return mlt_deque_push_back( this->stack_image, get_image );
143 /** Pop a get_image callback.
146 mlt_get_image mlt_frame_pop_get_image( mlt_frame this )
148 return mlt_deque_pop_back( this->stack_image );
154 int mlt_frame_push_frame( mlt_frame this, mlt_frame that )
156 return mlt_deque_push_back( this->stack_image, that );
162 mlt_frame mlt_frame_pop_frame( mlt_frame this )
164 return mlt_deque_pop_back( this->stack_image );
170 int mlt_frame_push_service( mlt_frame this, void *that )
172 return mlt_deque_push_back( this->stack_image, that );
178 void *mlt_frame_pop_service( mlt_frame this )
180 return mlt_deque_pop_back( this->stack_image );
183 /** Push an audio item on the stack.
186 int mlt_frame_push_audio( mlt_frame this, void *that )
188 return mlt_deque_push_back( this->stack_audio, that );
191 /** Pop an audio item from the stack
194 void *mlt_frame_pop_audio( mlt_frame this )
196 return mlt_deque_pop_back( this->stack_audio );
199 int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable )
201 mlt_properties properties = mlt_frame_properties( this );
202 mlt_get_image get_image = mlt_frame_pop_get_image( this );
203 mlt_producer producer = mlt_properties_get_data( properties, "test_card_producer", NULL );
205 *width = *width >> 1 << 1;
207 if ( get_image != NULL )
210 mlt_position position = mlt_frame_get_position( this );
211 error = get_image( this, buffer, format, width, height, writable );
212 mlt_frame_set_position( this, position );
215 else if ( mlt_properties_get_data( properties, "image", NULL ) != NULL )
217 *format = mlt_image_yuv422;
218 *buffer = mlt_properties_get_data( properties, "image", NULL );
219 *width = mlt_properties_get_int( properties, "width" );
220 *height = mlt_properties_get_int( properties, "height" );
222 else if ( producer != NULL )
224 mlt_frame test_frame = NULL;
225 mlt_service_get_frame( mlt_producer_service( producer ), &test_frame, 0 );
226 if ( test_frame != NULL )
228 mlt_properties test_properties = mlt_frame_properties( test_frame );
229 mlt_properties_set_double( test_properties, "consumer_aspect_ratio", mlt_properties_get_double( properties, "consumer_aspect_ratio" ) );
230 mlt_properties_set( test_properties, "rescale.interp", mlt_properties_get( properties, "rescale.interp" ) );
231 mlt_frame_get_image( test_frame, buffer, format, width, height, writable );
232 mlt_properties_set_data( properties, "test_card_frame", test_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
233 mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL );
234 mlt_properties_set_int( properties, "width", *width );
235 mlt_properties_set_int( properties, "height", *height );
236 mlt_properties_set_double( properties, "aspect_ratio", mlt_frame_get_aspect_ratio( test_frame ) );
240 mlt_properties_set_data( properties, "test_card_producer", NULL, 0, NULL, NULL );
241 mlt_frame_get_image( this, buffer, format, width, height, writable );
250 *width = *width == 0 ? 720 : *width;
251 *height = *height == 0 ? 576 : *height;
252 size = *width * *height;
254 mlt_properties_set_int( properties, "width", *width );
255 mlt_properties_set_int( properties, "height", *height );
256 mlt_properties_set_int( properties, "aspect_ratio", 1 );
264 case mlt_image_rgb24:
267 *buffer = mlt_pool_alloc( size );
269 memset( *buffer, 255, size );
271 case mlt_image_rgb24a:
274 *buffer = mlt_pool_alloc( size );
276 memset( *buffer, 255, size );
278 case mlt_image_yuv422:
281 *buffer = mlt_pool_alloc( size );
284 while ( p != NULL && p != q )
290 case mlt_image_yuv420p:
292 *buffer = mlt_pool_alloc( size );
294 memset( *buffer, 255, size );
298 mlt_properties_set_data( properties, "image", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
299 mlt_properties_set_int( properties, "test_image", 1 );
305 uint8_t *mlt_frame_get_alpha_mask( mlt_frame this )
307 if ( this != NULL && this->get_alpha_mask != NULL )
308 return this->get_alpha_mask( this );
309 return this == NULL ? NULL : mlt_properties_get_data( &this->parent, "alpha", NULL );
312 int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
314 mlt_properties properties = mlt_frame_properties( this );
315 int hide = mlt_properties_get_int( properties, "test_audio" );
317 if ( hide == 0 && this->get_audio != NULL )
319 mlt_position position = mlt_frame_get_position( this );
320 this->get_audio( this, buffer, format, frequency, channels, samples );
321 mlt_frame_set_position( this, position );
323 else if ( mlt_properties_get_data( properties, "audio", NULL ) )
325 *buffer = mlt_properties_get_data( properties, "audio", NULL );
326 *frequency = mlt_properties_get_int( properties, "audio_frequency" );
327 *channels = mlt_properties_get_int( properties, "audio_channels" );
328 *samples = mlt_properties_get_int( properties, "audio_samples" );
333 *samples = *samples <= 0 ? 1920 : *samples;
334 *channels = *channels <= 0 ? 2 : *channels;
335 *frequency = *frequency <= 0 ? 48000 : *frequency;
336 size = *samples * *channels * sizeof( int16_t );
337 *buffer = mlt_pool_alloc( size );
338 if ( *buffer != NULL )
339 memset( *buffer, 0, size );
340 mlt_properties_set_data( properties, "audio", *buffer, size, ( mlt_destructor )mlt_pool_release, NULL );
341 mlt_properties_set_int( properties, "test_audio", 1 );
344 mlt_properties_set_int( properties, "audio_frequency", *frequency );
345 mlt_properties_set_int( properties, "audio_channels", *channels );
346 mlt_properties_set_int( properties, "audio_samples", *samples );
351 unsigned char *mlt_frame_get_waveform( mlt_frame this, int w, int h )
354 mlt_properties properties = mlt_frame_properties( this );
355 mlt_audio_format format = mlt_audio_pcm;
356 int frequency = 32000; // lower frequency available?
358 double fps = mlt_properties_get_double( properties, "fps" );
359 int samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) );
362 mlt_frame_get_audio( this, &pcm, &format, &frequency, &channels, &samples );
364 // Make an 8-bit buffer large enough to hold rendering
366 unsigned char *bitmap = ( unsigned char* )mlt_pool_alloc( size );
367 if ( bitmap != NULL )
368 memset( bitmap, 0, size );
369 mlt_properties_set_data( properties, "waveform", bitmap, size, ( mlt_destructor )mlt_pool_release, NULL );
371 // Render vertical lines
372 int16_t *ubound = pcm + samples * channels;
373 int skip = samples / w - 1;
376 // Iterate sample stream and along x coordinate
377 for ( i = 0; i < w && pcm < ubound; i++ )
379 // pcm data has channels interleaved
380 for ( j = 0; j < channels; j++ )
382 // Determine sample's magnitude from 2s complement;
383 int pcm_magnitude = *pcm < 0 ? ~(*pcm) + 1 : *pcm;
384 // The height of a line is the ratio of the magnitude multiplied by
385 // half the vertical resolution
386 int height = ( int )( ( double )( pcm_magnitude ) / 32768 * h / 2 );
387 // Determine the starting y coordinate - left channel above center,
388 // right channel below - currently assumes 2 channels
389 int displacement = ( h / 2 ) - ( 1 - j ) * height;
390 // Position buffer pointer using y coordinate, stride, and x coordinate
391 unsigned char *p = &bitmap[ i + displacement * w ];
393 // Draw vertical line
394 for ( k = 0; k < height; k++ )
399 pcm += skip * channels;
405 mlt_producer mlt_frame_get_original_producer( mlt_frame this )
408 return mlt_properties_get_data( mlt_frame_properties( this ), "_producer", NULL );
412 void mlt_frame_close( mlt_frame this )
414 if ( this != NULL && mlt_properties_dec_ref( mlt_frame_properties( this ) ) <= 0 )
416 mlt_deque_close( this->stack_image );
417 mlt_deque_close( this->stack_audio );
418 mlt_properties_close( &this->parent );
423 /***** convenience functions *****/
425 int mlt_convert_rgb24a_to_yuv422( uint8_t *rgba, int width, int height, int stride, uint8_t *yuv, uint8_t *alpha )
428 register int y0, y1, u0, u1, v0, v1;
429 register int r, g, b;
430 register uint8_t *d = yuv;
433 for ( i = 0; i < height; i++ )
435 register uint8_t *s = rgba + ( stride * i );
436 for ( j = 0; j < ( width / 2 ); j++ )
442 RGB2YUV (r, g, b, y0, u0 , v0);
447 RGB2YUV (r, g, b, y1, u1 , v1);
459 RGB2YUV (r, g, b, y0, u0 , v0);
467 int mlt_convert_rgb24_to_yuv422( uint8_t *rgb, int width, int height, int stride, uint8_t *yuv )
470 register int y0, y1, u0, u1, v0, v1;
471 register int r, g, b;
472 register uint8_t *d = yuv;
475 for ( i = 0; i < height; i++ )
477 register uint8_t *s = rgb + ( stride * i );
478 for ( j = 0; j < ( width / 2 ); j++ )
483 RGB2YUV (r, g, b, y0, u0 , v0);
487 RGB2YUV (r, g, b, y1, u1 , v1);
498 RGB2YUV (r, g, b, y0, u0 , v0);
506 int mlt_convert_yuv420p_to_yuv422( uint8_t *yuv420p, int width, int height, int stride, uint8_t *yuv )
511 int half = width >> 1;
513 uint8_t *Y = yuv420p;
514 uint8_t *U = Y + width * height;
515 uint8_t *V = U + width * height / 4;
517 register uint8_t *d = yuv;
519 for ( i = 0; i < height; i++ )
521 register uint8_t *u = U + ( i / 2 ) * ( half );
522 register uint8_t *v = V + ( i / 2 ) * ( half );
524 for ( j = 0; j < half; j++ )
535 uint8_t *mlt_resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight )
537 uint8_t *output = NULL;
539 if ( input != NULL && ( iwidth != owidth || iheight != oheight ) )
541 iwidth = iwidth - ( iwidth % 2 );
542 owidth = owidth - ( owidth % 2 );
544 output = mlt_pool_alloc( owidth * oheight );
546 // Coordinates (0,0 is middle of output)
550 int out_x_range = owidth / 2;
551 int out_y_range = oheight / 2;
552 int in_x_range = iwidth / 2 < out_x_range ? iwidth / 2 : out_x_range;
553 int in_y_range = iheight / 2 < out_y_range ? iheight / 2 : out_y_range;
556 uint8_t *out_line = output;
557 uint8_t *out_ptr = out_line;
559 // Calculate a middle and possibly invalid pointer in the input
560 uint8_t *in_middle = input + iwidth * ( iheight / 2 ) + ( iwidth / 2 );
561 int in_line = - in_y_range * iwidth - in_x_range;
565 // Fill whole section with black
566 y = out_y_range - ( iheight / 2 );
567 int blank_elements = owidth * y;
568 elements = blank_elements;
569 while ( elements -- )
572 int active_width = iwidth;
573 int inactive_width = out_x_range - in_x_range;
577 // Loop for the entirety of our output height.
580 // Start at the beginning of the line
583 // Fill the outer part with black
584 elements = inactive_width;
585 while ( elements -- )
588 // We're in the input range for this row.
589 p = in_middle + in_line;
590 end = out_ptr + active_width;
591 while ( out_ptr != end )
594 // Fill the outer part with black
595 elements = inactive_width;
596 while ( elements -- )
599 // Move to next input line
602 // Move to next output line
606 // Fill whole section with black
607 elements = blank_elements;
608 while ( elements -- )
615 void mlt_resize_yuv422( uint8_t *output, int owidth, int oheight, uint8_t *input, int iwidth, int iheight )
618 int istride = iwidth * 2;
619 int ostride = owidth * 2;
621 iwidth = iwidth - ( iwidth % 4 );
622 owidth = owidth - ( owidth % 4 );
623 //iheight = iheight - ( iheight % 2 );
624 //oheight = oheight - ( oheight % 2 );
626 // Optimisation point
627 if ( iwidth == owidth && iheight == oheight )
628 memcpy( output, input, iheight * istride );
630 // Coordinates (0,0 is middle of output)
634 int out_x_range = owidth / 2;
635 int out_y_range = oheight / 2;
636 int in_x_range = iwidth / 2 < out_x_range ? iwidth / 2 : out_x_range;
637 int in_y_range = iheight / 2 < out_y_range ? iheight / 2 : out_y_range;
640 uint8_t *out_line = output;
641 uint8_t *out_ptr = out_line;
643 // Calculate a middle and possibly invalid pointer in the input
644 uint8_t *in_middle = input + istride * ( iheight / 2 ) + ( iwidth / 2 ) * 2;
645 int in_line = - in_y_range * istride - in_x_range * 2;
649 // Fill whole section with black
650 y = out_y_range - ( iheight / 2 );
651 int blank_elements = ostride * y / 2;
652 elements = blank_elements;
653 while ( elements -- )
659 int active_width = 2 * iwidth;
660 int inactive_width = out_x_range - in_x_range;
664 // Loop for the entirety of our output height.
667 // Start at the beginning of the line
670 // Fill the outer part with black
671 elements = inactive_width;
672 while ( elements -- )
678 // We're in the input range for this row.
679 p = in_middle + in_line;
680 end = out_ptr + active_width;
681 while ( out_ptr != end )
687 // Fill the outer part with black
688 elements = inactive_width;
689 while ( elements -- )
695 // Move to next input line
698 // Move to next output line
702 // Fill whole section with black
703 elements = blank_elements;
704 while ( elements -- )
711 /** A resizing function for yuv422 frames - this does not rescale, but simply
712 resizes. It assumes yuv422 images available on the frame so use with care.
715 uint8_t *mlt_frame_resize_yuv422( mlt_frame this, int owidth, int oheight )
718 mlt_properties properties = mlt_frame_properties( this );
720 // Get the input image, width and height
721 uint8_t *input = mlt_properties_get_data( properties, "image", NULL );
722 uint8_t *alpha = mlt_frame_get_alpha_mask( this );
724 int iwidth = mlt_properties_get_int( properties, "width" );
725 int iheight = mlt_properties_get_int( properties, "height" );
727 // If width and height are correct, don't do anything
728 if ( iwidth != owidth || iheight != oheight )
730 // Create the output image
731 uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
733 // Call the generic resize
734 mlt_resize_yuv422( output, owidth, oheight, input, iwidth, iheight );
736 // Now update the frame
737 mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
738 mlt_properties_set_int( properties, "width", owidth );
739 mlt_properties_set_int( properties, "height", oheight );
741 // We should resize the alpha too
742 alpha = mlt_resize_alpha( alpha, owidth, oheight, iwidth, iheight );
745 mlt_properties_set_data( properties, "alpha", alpha, owidth * ( oheight + 1 ), ( mlt_destructor )mlt_pool_release, NULL );
746 this->get_alpha_mask = NULL;
752 // No change, return input
756 /** A rescaling function for yuv422 frames - low quality, and provided for testing
757 only. It assumes yuv422 images available on the frame so use with care.
760 uint8_t *mlt_frame_rescale_yuv422( mlt_frame this, int owidth, int oheight )
763 mlt_properties properties = mlt_frame_properties( this );
765 // Get the input image, width and height
766 uint8_t *input = mlt_properties_get_data( properties, "image", NULL );
767 int iwidth = mlt_properties_get_int( properties, "width" );
768 int iheight = mlt_properties_get_int( properties, "height" );
770 // If width and height are correct, don't do anything
771 if ( iwidth != owidth || iheight != oheight )
773 // Create the output image
774 uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
777 int istride = iwidth * 2;
778 int ostride = owidth * 2;
780 iwidth = iwidth - ( iwidth % 4 );
782 // Derived coordinates
786 int out_x_range = owidth / 2;
787 int out_y_range = oheight / 2;
788 int in_x_range = iwidth / 2;
789 int in_y_range = iheight / 2;
792 register uint8_t *out_line = output;
793 register uint8_t *out_ptr;
795 // Calculate a middle pointer
796 uint8_t *in_middle = input + istride * in_y_range + in_x_range * 2;
799 // Generate the affine transform scaling values
800 register int scale_width = ( iwidth << 16 ) / owidth;
801 register int scale_height = ( iheight << 16 ) / oheight;
802 register int base = 0;
804 int outer = out_x_range * scale_width;
805 int bottom = out_y_range * scale_height;
807 // Loop for the entirety of our output height.
808 for ( dy = - bottom; dy < bottom; dy += scale_height )
810 // Start at the beginning of the line
813 // Pointer to the middle of the input line
814 in_line = in_middle + ( dy >> 16 ) * istride;
816 // Loop for the entirety of our output row.
817 for ( dx = - outer; dx < outer; dx += scale_width )
821 *out_ptr ++ = *( in_line + base );
823 *out_ptr ++ = *( in_line + base + 1 );
827 *out_ptr ++ = *( in_line + base );
829 *out_ptr ++ = *( in_line + base + 3 );
832 // Move to next output line
836 // Now update the frame
837 mlt_properties_set_data( properties, "image", output, owidth * ( oheight + 1 ) * 2, ( mlt_destructor )mlt_pool_release, NULL );
838 mlt_properties_set_int( properties, "width", owidth );
839 mlt_properties_set_int( properties, "height", oheight );
845 // No change, return input
849 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 )
853 int frequency_src = *frequency, frequency_dest = *frequency;
854 int channels_src = *channels, channels_dest = *channels;
855 int samples_src = *samples, samples_dest = *samples;
859 mlt_frame_get_audio( this, &dest, format, &frequency_dest, &channels_dest, &samples_dest );
860 //fprintf( stderr, "mix: frame dest samples %d channels %d position %lld\n", samples_dest, channels_dest, mlt_properties_get_position( mlt_frame_properties( this ), "_position" ) );
861 mlt_frame_get_audio( that, &src, format, &frequency_src, &channels_src, &samples_src );
862 //fprintf( stderr, "mix: frame src samples %d channels %d\n", samples_src, channels_src );
864 int silent = mlt_properties_get_int( mlt_frame_properties( this ), "silent_audio" );
865 mlt_properties_set_int( mlt_frame_properties( this ), "silent_audio", 0 );
867 memset( dest, 0, samples_dest * channels_dest * sizeof( int16_t ) );
869 silent = mlt_properties_get_int( mlt_frame_properties( that ), "silent_audio" );
870 mlt_properties_set_int( mlt_frame_properties( that ), "silent_audio", 0 );
872 memset( src, 0, samples_src * channels_src * sizeof( int16_t ) );
874 if ( channels_src > 6 )
876 if ( channels_dest > 6 )
878 if ( samples_src > 4000 )
880 if ( samples_dest > 4000 )
883 // determine number of samples to process
884 *samples = samples_src < samples_dest ? samples_src : samples_dest;
885 *channels = channels_src < channels_dest ? channels_src : channels_dest;
887 *frequency = frequency_dest;
889 // Compute a smooth ramp over start to end
890 float weight = weight_start;
891 float weight_step = ( weight_end - weight_start ) / *samples;
894 for ( i = 0; i < *samples; i++ )
896 for ( j = 0; j < *channels; j++ )
898 if ( j < channels_dest )
899 d = (double) dest[ i * channels_dest + j ];
900 if ( j < channels_src )
901 s = (double) src[ i * channels_src + j ];
902 dest[ i * channels_dest + j ] = s * weight + d * ( 1.0 - weight );
904 weight += weight_step;
910 int mlt_sample_calculator( float fps, int frequency, int64_t position )
914 if ( ( int )( fps * 100 ) == 2997 )
916 samples = frequency / 30;
921 if ( position % 5 != 0 )
925 if ( position % 300 == 0 )
927 else if ( position % 30 == 0 )
929 else if ( position % 2 == 0 )
935 if ( position % 30 == 0 )
937 else if ( position % 29 == 0 )
939 else if ( position % 4 == 2 )
950 samples = frequency / fps;