- int result = mlt_frame_get_audio( nested_frame, buffer, format, frequency, channels, samples );
- int size = *channels * *samples * sizeof( int16_t );
- int16_t *new_buffer = mlt_pool_alloc( size );
- mlt_properties_set_data( MLT_FRAME_PROPERTIES( frame ), "audio", new_buffer, size, mlt_pool_release, NULL );
- memcpy( new_buffer, *buffer, size );
- *buffer = new_buffer;
- mlt_frame_close( nested_frame );
+ int result = 0;
+
+ // if not repeating last frame
+ if ( mlt_frame_get_position( nested_frame ) != cx->audio_position )
+ {
+ double fps = mlt_profile_fps( cx->profile );
+ if ( mlt_producer_get_fps( cx->this ) < fps )
+ fps = mlt_producer_get_fps( cx->this );
+ *samples = mlt_sample_calculator( fps, *frequency, cx->audio_counter++ );
+ result = mlt_frame_get_audio( nested_frame, buffer, format, frequency, channels, samples );
+ int size = mlt_audio_format_size( *format, *samples, *channels );
+ int16_t *new_buffer = mlt_pool_alloc( size );
+
+ mlt_frame_set_audio( frame, new_buffer, *format, size, mlt_pool_release );
+ memcpy( new_buffer, *buffer, size );
+ *buffer = new_buffer;
+ }
+ else
+ {
+ // otherwise return no samples
+ *samples = 0;
+ }
+ cx->audio_position = mlt_frame_get_position( nested_frame );
+