forked from mirror/openmw-tes3mp
102 lines
2.6 KiB
C++
102 lines
2.6 KiB
C++
|
#ifndef HAVE_LIBSWRESAMPLE
|
||
|
extern "C"
|
||
|
{
|
||
|
#ifdef _MSC_VER
|
||
|
# include <stdint.h>
|
||
|
#endif
|
||
|
|
||
|
#include <libavresample/avresample.h>
|
||
|
#include <libavutil/opt.h>
|
||
|
|
||
|
/* FIXME: delete this file once libswresample is available on all platforms */
|
||
|
|
||
|
int swr_init(AVAudioResampleContext *avr) { return 1; }
|
||
|
|
||
|
void swr_free(AVAudioResampleContext **avr) { avresample_free(avr); }
|
||
|
|
||
|
int swr_convert(
|
||
|
AVAudioResampleContext *avr,
|
||
|
uint8_t** output,
|
||
|
int out_samples,
|
||
|
const uint8_t** input,
|
||
|
int in_samples)
|
||
|
{
|
||
|
// FIXME: potential performance hit
|
||
|
int out_plane_size = 0;
|
||
|
int in_plane_size = 0;
|
||
|
return avresample_convert(avr, output, out_plane_size, out_samples,
|
||
|
(uint8_t **)input, in_plane_size, in_samples);
|
||
|
}
|
||
|
|
||
|
AVAudioResampleContext * swr_alloc_set_opts(
|
||
|
AVAudioResampleContext *avr,
|
||
|
int64_t out_ch_layout,
|
||
|
AVSampleFormat out_fmt,
|
||
|
int out_rate,
|
||
|
int64_t in_ch_layout,
|
||
|
AVSampleFormat in_fmt,
|
||
|
int in_rate,
|
||
|
int o,
|
||
|
void* l)
|
||
|
{
|
||
|
avr = avresample_alloc_context();
|
||
|
if(!avr)
|
||
|
return 0;
|
||
|
|
||
|
int res;
|
||
|
res = av_opt_set_int(avr, "out_channel_layout", out_ch_layout, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: out_ch_layout = %d\n", res);
|
||
|
return 0;
|
||
|
}
|
||
|
res = av_opt_set_int(avr, "out_sample_fmt", out_fmt, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: out_fmt = %d\n", res);
|
||
|
return 0;
|
||
|
}
|
||
|
res = av_opt_set_int(avr, "out_sample_rate", out_rate, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: out_rate = %d\n", res);
|
||
|
return 0;
|
||
|
}
|
||
|
res = av_opt_set_int(avr, "in_channel_layout", in_ch_layout, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: in_ch_layout = %d\n", res);
|
||
|
return 0;
|
||
|
}
|
||
|
res = av_opt_set_int(avr, "in_sample_fmt", in_fmt, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: in_fmt = %d\n", res);
|
||
|
return 0;
|
||
|
}
|
||
|
res = av_opt_set_int(avr, "in_sample_rate", in_rate, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: in_rate = %d\n", res);
|
||
|
return 0;
|
||
|
}
|
||
|
res = av_opt_set_int(avr, "internal_sample_fmt", AV_SAMPLE_FMT_FLTP, 0);
|
||
|
if(res < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "av_opt_set_int: internal_sample_fmt\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
if(avresample_open(avr) < 0)
|
||
|
{
|
||
|
av_log(avr, AV_LOG_ERROR, "Error opening context\n");
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
return avr;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
#endif
|