From 8084acd283354369da64ac98e04bd8d0c2b3a663 Mon Sep 17 00:00:00 2001 From: Torarin Date: Sat, 29 Sep 2012 16:42:25 +0200 Subject: [PATCH] Add boost-on-downmix flag. --- IAudioRenderer.h | 2 +- OMXAudio.cpp | 36 ++++++++++++++++++++---------------- OMXAudio.h | 5 +++-- OMXPlayerAudio.cpp | 9 ++++++--- OMXPlayerAudio.h | 4 +++- README.md | 1 + omxplayer.cpp | 11 ++++++++++- 7 files changed, 44 insertions(+), 24 deletions(-) diff --git a/IAudioRenderer.h b/IAudioRenderer.h index 59d6dac2..0dbe99d7 100644 --- a/IAudioRenderer.h +++ b/IAudioRenderer.h @@ -52,7 +52,7 @@ class IAudioRenderer IAudioRenderer() {}; virtual ~IAudioRenderer() {}; - virtual bool Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int downmixChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic=false, EEncoded encoded = ENCODED_NONE) = 0; + virtual bool Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int downmixChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool boostOnDownmix, bool bIsMusic=false, EEncoded encoded = ENCODED_NONE) = 0; virtual void UnRegisterAudioCallback() = 0; virtual void RegisterAudioCallback(IAudioCallback* pCallback) = 0; virtual float GetDelay() = 0; diff --git a/OMXAudio.cpp b/OMXAudio.cpp index c2972904..f88396c0 100644 --- a/OMXAudio.cpp +++ b/OMXAudio.cpp @@ -120,6 +120,7 @@ COMXAudio::COMXAudio() : m_CurrentVolume (0 ), m_Passthrough (false ), m_HWDecode (false ), + m_normalize_downmix(true ), m_BytesPerSec (0 ), m_BufferLen (0 ), m_ChunkLen (0 ), @@ -151,7 +152,8 @@ COMXAudio::~COMXAudio() bool COMXAudio::Initialize(IAudioCallback* pCallback, const CStdString& device, enum PCMChannels *channelMap, - COMXStreamInfo &hints, OMXClock *clock, EEncoded bPassthrough, bool bUseHWDecode) + COMXStreamInfo &hints, OMXClock *clock, EEncoded bPassthrough, bool bUseHWDecode, + bool boostOnDownmix) { m_HWDecode = false; m_Passthrough = false; @@ -179,10 +181,10 @@ bool COMXAudio::Initialize(IAudioCallback* pCallback, const CStdString& device, memcpy(m_extradata, hints.extradata, hints.extrasize); } - return Initialize(pCallback, device, hints.channels, channelMap, hints.samplerate, hints.bitspersample, false, false, bPassthrough); + return Initialize(pCallback, device, hints.channels, channelMap, hints.channels, hints.samplerate, hints.bitspersample, false, boostOnDownmix, false, bPassthrough); } -bool COMXAudio::Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int downmixChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic, EEncoded bPassthrough) +bool COMXAudio::Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int downmixChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool boostOnDownmix, bool bIsMusic, EEncoded bPassthrough) { std::string deviceuse; if(device == "hdmi") { @@ -220,6 +222,7 @@ bool COMXAudio::Initialize(IAudioCallback* pCallback, const CStdString& device, #endif m_downmix_channels = downmixChannels; + m_normalize_downmix = !boostOnDownmix; m_InputChannels = iChannels; m_remap.Reset(); @@ -756,20 +759,21 @@ bool COMXAudio::SetCurrentVolume(long nVolume) assert(0); } - double sum_L = 0; - double sum_R = 0; - for(size_t i = 0; i < 16; ++i) + if(m_normalize_downmix) { - if(i & 1) - sum_R += coeff[i]; - else - sum_L += coeff[i]; - } - double normalization = 1 / max(sum_L, sum_R); - - // printf("normalization: %f\n", normalization); + double sum_L = 0; + double sum_R = 0; - double s = r * normalization; + for(size_t i = 0; i < 16; ++i) + { + if(i & 1) + sum_R += coeff[i]; + else + sum_L += coeff[i]; + } + + r /= max(sum_L, sum_R); + } OMX_CONFIG_BRCMAUDIODOWNMIXCOEFFICIENTS mix; OMX_INIT_STRUCTURE(mix); @@ -779,7 +783,7 @@ bool COMXAudio::SetCurrentVolume(long nVolume) "Unexpected OMX_CONFIG_BRCMAUDIODOWNMIXCOEFFICIENTS::coeff length"); for(size_t i = 0; i < 16; ++i) - mix.coeff[i] = static_cast(0x10000 * (coeff[i] * s)); + mix.coeff[i] = static_cast(0x10000 * (coeff[i] * r)); OMX_ERRORTYPE omx_err = m_omx_mixer.SetConfig(OMX_IndexConfigBrcmAudioDownmixCoefficients, &mix); diff --git a/OMXAudio.h b/OMXAudio.h index 9b6a0dd4..abc9e194 100644 --- a/OMXAudio.h +++ b/OMXAudio.h @@ -58,8 +58,8 @@ class COMXAudio : public IAudioRenderer unsigned int GetAudioRenderingLatency(); COMXAudio(); bool Initialize(IAudioCallback* pCallback, const CStdString& device, enum PCMChannels *channelMap, - COMXStreamInfo &hints, OMXClock *clock, EEncoded bPassthrough, bool bUseHWDecode); - bool Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int downmixChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool bIsMusic=false, EEncoded bPassthrough = IAudioRenderer::ENCODED_NONE); + COMXStreamInfo &hints, OMXClock *clock, EEncoded bPassthrough, bool bUseHWDecode, bool boostOnDownmix); + bool Initialize(IAudioCallback* pCallback, const CStdString& device, int iChannels, enum PCMChannels *channelMap, unsigned int downmixChannels, unsigned int uiSamplesPerSec, unsigned int uiBitsPerSample, bool bResample, bool boostOnDownmix, bool bIsMusic=false, EEncoded bPassthrough = IAudioRenderer::ENCODED_NONE); ~COMXAudio(); unsigned int AddPackets(const void* data, unsigned int len); @@ -105,6 +105,7 @@ class COMXAudio : public IAudioRenderer long m_drc; bool m_Passthrough; bool m_HWDecode; + bool m_normalize_downmix; unsigned int m_BytesPerSec; unsigned int m_BufferLen; unsigned int m_ChunkLen; diff --git a/OMXPlayerAudio.cpp b/OMXPlayerAudio.cpp index 66968ca3..590fec9e 100644 --- a/OMXPlayerAudio.cpp +++ b/OMXPlayerAudio.cpp @@ -99,7 +99,8 @@ void OMXPlayerAudio::UnLockDecoder() } bool OMXPlayerAudio::Open(COMXStreamInfo &hints, OMXClock *av_clock, OMXReader *omx_reader, - std::string device, bool passthrough, bool hw_decode, bool use_thread) + std::string device, bool passthrough, bool hw_decode, + bool boost_on_downmix, bool use_thread) { if(ThreadHandle()) Close(); @@ -117,6 +118,7 @@ bool OMXPlayerAudio::Open(COMXStreamInfo &hints, OMXClock *av_clock, OMXReader * m_hw_decode = false; m_use_passthrough = passthrough; m_use_hw_decode = hw_decode; + m_boost_on_downmix = boost_on_downmix; m_iCurrentPts = DVD_NOPTS_VALUE; m_bAbort = false; m_bMpeg = m_omx_reader->IsMpegVideo(); @@ -612,7 +614,8 @@ bool OMXPlayerAudio::OpenDecoder() if(m_passthrough) m_hw_decode = false; bAudioRenderOpen = m_decoder->Initialize(NULL, m_device.substr(4), m_pChannelMap, - m_hints, m_av_clock, m_passthrough, m_hw_decode); + m_hints, m_av_clock, m_passthrough, + m_hw_decode, m_boost_on_downmix); } else { @@ -624,7 +627,7 @@ bool OMXPlayerAudio::OpenDecoder() bAudioRenderOpen = m_decoder->Initialize(NULL, m_device.substr(4), m_hints.channels, m_pChannelMap, downmix_channels, m_hints.samplerate, m_hints.bitspersample, - false, false, m_passthrough); + false, m_boost_on_downmix, false, m_passthrough); } m_codec_name = m_omx_reader->GetCodecName(OMXSTREAM_AUDIO); diff --git a/OMXPlayerAudio.h b/OMXPlayerAudio.h index 9c46c485..3a262fa2 100644 --- a/OMXPlayerAudio.h +++ b/OMXPlayerAudio.h @@ -75,6 +75,7 @@ class OMXPlayerAudio : public CThread bool m_use_hw_decode; IAudioRenderer::EEncoded m_passthrough; bool m_hw_decode; + bool m_boost_on_downmix; bool m_bMpeg; bool m_bAbort; bool m_use_thread; @@ -108,7 +109,8 @@ class OMXPlayerAudio : public CThread OMXPlayerAudio(); ~OMXPlayerAudio(); bool Open(COMXStreamInfo &hints, OMXClock *av_clock, OMXReader *omx_reader, - std::string device, bool passthrough, bool hw_decode, bool use_thread); + std::string device, bool passthrough, bool hw_decode, + bool boost_on_downmix, bool use_thread); bool Close(); bool Decode(OMXPacket *pkt); void Process(); diff --git a/README.md b/README.md index 24de305c..89265a64 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Using OMXPlayer -y / --hdmiclocksync adjust display refresh rate to match video -t / --sid index show subtitle with index -r / --refresh adjust framerate/resolution to video + --boost-on-downmix boost volume when downmixing --font path subtitle font (default: /usr/share/fonts/truetype/freefont/FreeSans.ttf) --font-size size font size as thousandths of screen height diff --git a/omxplayer.cpp b/omxplayer.cpp index 2297ad1c..2abb6f3f 100644 --- a/omxplayer.cpp +++ b/omxplayer.cpp @@ -91,6 +91,7 @@ bool m_has_video = false; bool m_has_audio = false; bool m_has_subtitle = false; float m_display_aspect = 0.0f; +bool m_boost_on_downmix = false; enum{ERROR=-1,SUCCESS,ONEBYTE}; @@ -130,6 +131,7 @@ void print_usage() printf(" -y / --hdmiclocksync adjust display refresh rate to match video\n"); printf(" -t / --sid index show subtitle with index\n"); printf(" -r / --refresh adjust framerate/resolution to video\n"); + printf(" --boost-on-downmix boost volume when downmixing\n"); printf(" --font path subtitle font\n"); printf(" (default: /usr/share/fonts/truetype/freefont/FreeSans.ttf)\n"); printf(" --font-size size font size as thousandths of screen height\n"); @@ -329,6 +331,8 @@ int main(int argc, char *argv[]) double startpts = 0; TV_GET_STATE_RESP_T tv_state; + const int boost_on_downmix_opt = 0x200; + struct option longopts[] = { { "info", no_argument, NULL, 'i' }, { "help", no_argument, NULL, 'h' }, @@ -345,6 +349,7 @@ int main(int argc, char *argv[]) { "font", required_argument, NULL, 0x100 }, { "font-size", required_argument, NULL, 0x101 }, { "align", required_argument, NULL, 0x102 }, + { "boost-on-downmix", no_argument, NULL, boost_on_downmix_opt }, { 0, 0, 0, 0 } }; @@ -413,6 +418,9 @@ int main(int argc, char *argv[]) else m_centered = false; break; + case boost_on_downmix_opt: + m_boost_on_downmix = true; + break; case 0: break; case 'h': @@ -511,7 +519,8 @@ int main(int argc, char *argv[]) m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio); if(m_has_audio && !m_player_audio.Open(m_hints_audio, m_av_clock, &m_omx_reader, deviceString, - m_passthrough, m_use_hw_audio, m_thread_player)) + m_passthrough, m_use_hw_audio, + m_boost_on_downmix, m_thread_player)) goto do_exit; m_av_clock->SetSpeed(DVD_PLAYSPEED_NORMAL);