Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3240 from FernetMenta/aefixes

ActiveAE: fix setting resample ratio
  • Loading branch information...
commit 429ce9bc69cdee21d3f3be23c1f7147f25b42db6 2 parents 1b4a9d6 + 6f5642e
Rainer Hochecker FernetMenta authored
4 lib/DllSwResample.h
View
@@ -57,6 +57,7 @@ class DllSwResampleInterface
virtual int64_t swr_get_delay(struct SwrContext *s, int64_t base) = 0;
virtual int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map) = 0;
virtual int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) = 0;
+ virtual int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance) = 0;
};
#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN)
@@ -83,6 +84,7 @@ class DllSwResample : public DllDynamic, DllSwResampleInterface
virtual int64_t swr_get_delay(struct SwrContext *s, int64_t base) { return ::swr_get_delay(s, base); }
virtual int swr_set_channel_mapping (struct SwrContext *s, const int *channel_map) { return ::swr_set_channel_mapping(s, channel_map); }
virtual int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride) { return ::swr_set_matrix(s, matrix, stride); }
+ virtual int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance) { return ::int swr_set_compensation(s, sample_delta, compensation_distance); }
};
#else
@@ -100,6 +102,7 @@ class DllSwResample : public DllDynamic, DllSwResampleInterface
DEFINE_METHOD2(int64_t, swr_get_delay, (struct SwrContext *p1, int64_t p2))
DEFINE_METHOD2(int, swr_set_channel_mapping, (struct SwrContext *p1, const int *p2))
DEFINE_METHOD3(int, swr_set_matrix, (struct SwrContext *p1, const double *p2, int p3))
+ DEFINE_METHOD3(int, swr_set_compensation, (struct SwrContext *p1, int p2, int p3))
BEGIN_METHOD_RESOLVE()
RESOLVE_METHOD(swr_alloc_set_opts)
@@ -109,6 +112,7 @@ class DllSwResample : public DllDynamic, DllSwResampleInterface
RESOLVE_METHOD(swr_get_delay)
RESOLVE_METHOD(swr_set_channel_mapping)
RESOLVE_METHOD(swr_set_matrix)
+ RESOLVE_METHOD(swr_set_compensation)
END_METHOD_RESOLVE()
/* dependencies of libavformat */
2  lib/xbmc-libav-hacks/libav_hacks.h
View
@@ -75,6 +75,8 @@ int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
+int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
+
// libavfilter
#define LIBAVFILTER_AVFRAME_BASED
5 lib/xbmc-libav-hacks/swresample.c
View
@@ -73,3 +73,8 @@ int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride)
{
return avresample_set_matrix(s, matrix, stride);
}
+
+int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance)
+{
+ return avresample_set_compensation(s, sample_delta, compensation_distance);
+}
10 xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp
View
@@ -458,12 +458,7 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg)
par = (MsgStreamParameter*)msg->data;
if (par->stream->m_resampleBuffers)
{
- if ((unsigned int)(par->stream->m_resampleBuffers->m_format.m_sampleRate * par->parameter.double_par) != par->stream->m_resampleBuffers->m_outSampleRate)
- {
- par->stream->m_resampleBuffers->m_resampleRatio = par->parameter.double_par;
- par->stream->m_resampleBuffers->m_resampleQuality = AE_QUALITY_LOW;
- par->stream->m_resampleBuffers->m_changeResampler = true;
- }
+ par->stream->m_resampleBuffers->m_resampleRatio = par->parameter.double_par;
}
return;
case CActiveAEControlProtocol::STREAMFADE:
@@ -2333,7 +2328,8 @@ bool CActiveAE::ResampleSound(CActiveAESound *sound)
}
int samples = resampler->Resample(dst_buffer, dst_samples,
sound->GetSound(true)->data,
- sound->GetSound(true)->nb_samples);
+ sound->GetSound(true)->nb_samples,
+ 1.0);
sound->GetSound(false)->nb_samples = samples;
12 xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEBuffer.cpp
View
@@ -177,9 +177,6 @@ bool CActiveAEBufferPoolResample::Create(unsigned int totaltime, bool remap, boo
m_resampleQuality);
}
- // store output sampling rate, needed when ratio gets changed
- m_outSampleRate = m_format.m_sampleRate;
-
m_stereoUpmix = upmix;
return true;
@@ -187,14 +184,12 @@ bool CActiveAEBufferPoolResample::Create(unsigned int totaltime, bool remap, boo
void CActiveAEBufferPoolResample::ChangeResampler()
{
- m_outSampleRate = m_format.m_sampleRate * m_resampleRatio;
-
delete m_resampler;
m_resampler = new CActiveAEResample();
m_resampler->Init(CActiveAEResample::GetAVChannelLayout(m_format.m_channelLayout),
m_format.m_channelLayout.Count(),
- m_outSampleRate,
+ m_format.m_sampleRate,
CActiveAEResample::GetAVSampleFormat(m_format.m_dataFormat),
CAEUtil::DataFormatToUsedBits(m_format.m_dataFormat),
CActiveAEResample::GetAVChannelLayout(m_inputFormat.m_channelLayout),
@@ -275,7 +270,8 @@ bool CActiveAEBufferPoolResample::ResampleBuffers(unsigned int timestamp)
out_samples = m_resampler->Resample(m_planes,
m_procSample->pkt->max_nb_samples - m_procSample->pkt->nb_samples,
in ? in->pkt->data : NULL,
- in ? in->pkt->nb_samples : 0);
+ in ? in->pkt->nb_samples : 0,
+ m_resampleRatio);
m_procSample->pkt->nb_samples += out_samples;
busy = true;
m_empty = (out_samples == 0);
@@ -345,7 +341,7 @@ float CActiveAEBufferPoolResample::GetDelay()
if (m_resampler)
{
int samples = m_resampler->GetBufferedSamples();
- delay += (float)samples / m_outSampleRate;
+ delay += (float)samples / m_format.m_sampleRate;
}
return delay;
1  xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEBuffer.h
View
@@ -107,7 +107,6 @@ class CActiveAEBufferPoolResample : public CActiveAEBufferPool
bool m_changeResampler;
double m_resampleRatio;
AEQuality m_resampleQuality;
- unsigned int m_outSampleRate;
bool m_stereoUpmix;
};
13 xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEResample.cpp
View
@@ -159,8 +159,19 @@ bool CActiveAEResample::Init(uint64_t dst_chan_layout, int dst_channels, int dst
return true;
}
-int CActiveAEResample::Resample(uint8_t **dst_buffer, int dst_samples, uint8_t **src_buffer, int src_samples)
+int CActiveAEResample::Resample(uint8_t **dst_buffer, int dst_samples, uint8_t **src_buffer, int src_samples, double ratio)
{
+ if (ratio != 1.0)
+ {
+ if (m_dllSwResample.swr_set_compensation(m_pContext,
+ (dst_samples*ratio-dst_samples)*m_dst_rate/m_src_rate,
+ dst_samples*m_dst_rate/m_src_rate) < 0)
+ {
+ CLog::Log(LOGERROR, "CActiveAEResample::Resample - set compensation failed");
+ return 0;
+ }
+ }
+
int ret = m_dllSwResample.swr_convert(m_pContext, dst_buffer, dst_samples, (const uint8_t**)src_buffer, src_samples);
if (ret < 0)
{
2  xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEResample.h
View
@@ -35,7 +35,7 @@ class CActiveAEResample
CActiveAEResample();
virtual ~CActiveAEResample();
bool Init(uint64_t dst_chan_layout, int dst_channels, int dst_rate, AVSampleFormat dst_fmt, int dst_bits, uint64_t src_chan_layout, int src_channels, int src_rate, AVSampleFormat src_fmt, int src_bits, bool upmix, CAEChannelInfo *remapLayout, AEQuality quality);
- int Resample(uint8_t **dst_buffer, int dst_samples, uint8_t **src_buffer, int src_samples);
+ int Resample(uint8_t **dst_buffer, int dst_samples, uint8_t **src_buffer, int src_samples, double ratio);
int64_t GetDelay(int64_t base);
int GetBufferedSamples();
int CalcDstSampleCount(int src_samples, int dst_rate, int src_rate);
Please sign in to comment.
Something went wrong with that request. Please try again.