* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "filter_avresample.h"
-
+#include <framework/mlt_filter.h>
#include <framework/mlt_frame.h>
#include <stdio.h>
#include <string.h>
// ffmpeg Header files
-#include <avformat.h>
+#include <libavformat/avformat.h>
/** Get the audio.
*/
-static int resample_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
+static int resample_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
// Get the properties of the frame
mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
// Get the filter properties
mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );
+ mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
+
// Get the resample information
int output_rate = mlt_properties_get_int( filter_properties, "frequency" );
int16_t *sample_buffer = mlt_properties_get_data( filter_properties, "buffer", NULL );
output_rate = *frequency;
// Get the producer's audio
+ *format = mlt_audio_s16;
mlt_frame_get_audio( frame, buffer, format, frequency, &channels_avail, samples );
// Duplicate channels as necessary
{
for ( j = 0; j < *channels; j++ )
{
- new_buffer[ ( i * *channels ) + j ] = (*buffer)[ ( i * channels_avail ) + k ];
+ new_buffer[ ( i * *channels ) + j ] = ((int16_t*)(*buffer))[ ( i * channels_avail ) + k ];
k = ( k + 1 ) % channels_avail;
}
}
// Drop all but the first *channels
for ( i = 0; i < *samples; i++ )
{
- new_buffer[ ( i * *channels ) + 0 ] = (*buffer)[ ( i * channels_avail ) + 2 ];
- new_buffer[ ( i * *channels ) + 1 ] = (*buffer)[ ( i * channels_avail ) + 3 ];
+ new_buffer[ ( i * *channels ) + 0 ] = ((int16_t*)(*buffer))[ ( i * channels_avail ) + 2 ];
+ new_buffer[ ( i * *channels ) + 1 ] = ((int16_t*)(*buffer))[ ( i * channels_avail ) + 3 ];
}
// Update the audio buffer now - destroys the old
if ( resample == NULL || *frequency != mlt_properties_get_int( filter_properties, "last_frequency" ) )
{
// Create the resampler
+#if (LIBAVCODEC_VERSION_INT >= ((52<<16)+(15<<8)+0))
+ resample = av_audio_resample_init( *channels, *channels, output_rate, *frequency,
+ SAMPLE_FMT_S16, SAMPLE_FMT_S16, 16, 10, 0, 0.8 );
+#else
resample = audio_resample_init( *channels, *channels, output_rate, *frequency );
+#endif
// And store it on properties
mlt_properties_set_data( filter_properties, "audio_resample", resample, 0, ( mlt_destructor )audio_resample_close, NULL );
mlt_properties_set_int( filter_properties, "last_frequency", *frequency );
}
+ mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+
// Resample the audio
used = audio_resample( resample, sample_buffer, *buffer, *samples );
+ int size = used * *channels * sizeof( int16_t );
// Resize if necessary
if ( used > *samples )
{
- *buffer = mlt_pool_realloc( *buffer, *samples * *channels * sizeof( int16_t ) );
- mlt_properties_set_data( properties, "audio", *buffer, *channels * used * sizeof( int16_t ), mlt_pool_release, NULL );
+ *buffer = mlt_pool_realloc( *buffer, size );
+ mlt_frame_set_audio( frame, *buffer, *format, size, mlt_pool_release );
}
// Copy samples
- memcpy( *buffer, sample_buffer, *channels * used * sizeof( int16_t ) );
+ memcpy( *buffer, sample_buffer, size );
// Update output variables
*samples = used;
*frequency = output_rate;
}
+ else
+ {
+ mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
+ }
return 0;
}