diff options
author | unknown <fernetmenta@online.de> | 2013-08-14 08:11:42 +0200 |
---|---|---|
committer | Rainer Hochecker <fernetmenta@online.de> | 2013-08-22 12:57:43 +0200 |
commit | 45d41f8ed537dae29f28c3652052a922020c649f (patch) | |
tree | 2a45a079cbb7b4b9aeaa662e30b8b5347a3d2313 | |
parent | e4ffe757f43074075749c59e8971f32649aa99a3 (diff) |
ActiveAE: fix volume amplification
4 files changed, 32 insertions, 22 deletions
diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp index 9b3ff006fc..10ac1c870d 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp @@ -435,6 +435,7 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg) MsgStreamParameter *par; par = (MsgStreamParameter*)msg->data; par->stream->m_limiter.SetAmplification(par->parameter.float_par); + par->stream->m_amplify = par->parameter.float_par; return; case CActiveAEControlProtocol::STREAMVOLUME: par = (MsgStreamParameter*)msg->data; @@ -972,6 +973,9 @@ void CActiveAE::Configure(AEAudioFormat *desiredFmt) } if (m_mode == MODE_TRANSCODE || m_streams.size() > 1) (*it)->m_resampleBuffers->m_fillPackets = true; + + // amplification + (*it)->m_limiter.SetSamplerate(outputFormat.m_sampleRate); } // buffers for viz @@ -1165,19 +1169,6 @@ void CActiveAE::DiscardSound(CActiveAESound *sound) } } -float CActiveAE::CalcStreamAmplification(CActiveAEStream *stream, CSampleBuffer *buf) -{ - float amp = 1.0f; - int nb_floats = buf->pkt->nb_samples * buf->pkt->config.channels / buf->pkt->planes; - float tamp; - for(int i=0; i<buf->pkt->planes; i++) - { - tamp = stream->m_limiter.Run((float*)buf->pkt->data[i], nb_floats); - amp = std::min(amp, tamp); - } - return amp; -} - void CActiveAE::ChangeResampleQuality() { std::list<CActiveAEStream*>::iterator it; @@ -1488,9 +1479,6 @@ bool CActiveAE::RunStages() out = (*it)->m_resampleBuffers->m_outputSamples.front(); (*it)->m_resampleBuffers->m_outputSamples.pop_front(); - // volume for stream - float amp = (*it)->m_rgain * CalcStreamAmplification((*it), out); - int nb_floats = out->pkt->nb_samples * out->pkt->config.channels / out->pkt->planes; int nb_loops = 1; float fadingStep = 0.0f; @@ -1509,6 +1497,14 @@ bool CActiveAE::RunStages() int samples = m_internalFormat.m_sampleRate * (float)(*it)->m_fadingTime / 1000.0f; fadingStep = delta / samples; } + + // for stream amplification we need to run on a per sample basis + if ((*it)->m_amplify != 1.0) + { + nb_floats = out->pkt->config.channels / out->pkt->planes; + nb_loops = out->pkt->nb_samples; + } + for(int i=0; i<nb_loops; i++) { if ((*it)->m_fadingSamples > 0) @@ -1523,7 +1519,11 @@ bool CActiveAE::RunStages() (*it)->m_streamFading = false; } } - float volume = (*it)->m_volume * amp; + + // volume for stream + float volume = (*it)->m_volume * (*it)->m_rgain; + if(nb_loops > 1) + volume *= (*it)->m_limiter.Run((float**)out->pkt->data, out->pkt->config.channels, i*nb_floats, out->pkt->planes > 1); for(int j=0; j<out->pkt->planes; j++) { @@ -1543,9 +1543,6 @@ bool CActiveAE::RunStages() mix = (*it)->m_resampleBuffers->m_outputSamples.front(); (*it)->m_resampleBuffers->m_outputSamples.pop_front(); - // volume for stream - float amp = (*it)->m_volume * (*it)->m_rgain * CalcStreamAmplification((*it), mix); - int nb_floats = mix->pkt->nb_samples * mix->pkt->config.channels / mix->pkt->planes; int nb_loops = 1; float fadingStep = 0.0f; @@ -1564,6 +1561,14 @@ bool CActiveAE::RunStages() int samples = m_internalFormat.m_sampleRate * (float)(*it)->m_fadingTime / 1000.0f; fadingStep = delta / samples; } + + // for stream amplification we need to run on a per sample basis + if ((*it)->m_amplify != 1.0) + { + nb_floats = out->pkt->config.channels / out->pkt->planes; + nb_loops = out->pkt->nb_samples; + } + for(int i=0; i<nb_loops; i++) { if ((*it)->m_fadingSamples > 0) @@ -1578,7 +1583,11 @@ bool CActiveAE::RunStages() (*it)->m_streamFading = false; } } - float volume = (*it)->m_volume * amp; + + // volume for stream + float volume = (*it)->m_volume * (*it)->m_rgain; + if(nb_loops > 1) + volume *= (*it)->m_limiter.Run((float**)mix->pkt->data, mix->pkt->config.channels, i*nb_floats, mix->pkt->planes > 1); for(int j=0; j<out->pkt->planes && j<mix->pkt->planes; j++) { diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h index e5a3e9dace..9b4c243dd8 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h @@ -258,7 +258,6 @@ protected: void ClearDiscardedBuffers(); void SStopSound(CActiveAESound *sound); void DiscardSound(CActiveAESound *sound); - float CalcStreamAmplification(CActiveAEStream *stream, CSampleBuffer *buf); void ChangeResampleQuality(); bool RunStages(); diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp index ab2b10a744..ca0a38d706 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.cpp @@ -44,6 +44,7 @@ CActiveAEStream::CActiveAEStream(AEAudioFormat *format) m_paused = false; m_rgain = 1.0; m_volume = 1.0; + m_amplify = 1.0; m_streamSpace = m_format.m_frameSize * m_format.m_frames; m_streamDraining = false; m_streamDrained = false; diff --git a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.h b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.h index bddf1a37b1..2c0de2e30a 100644 --- a/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.h +++ b/xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAEStream.h @@ -107,6 +107,7 @@ protected: CAELimiter m_limiter; float m_volume; float m_rgain; + float m_amplify; float m_bufferedTime; int m_fadingSamples; float m_fadingBase; |