Skip to content

Commit

Permalink
Add boost-on-downmix flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
torarin committed Sep 29, 2012
1 parent 922ff00 commit 8084acd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 24 deletions.
2 changes: 1 addition & 1 deletion IAudioRenderer.h
Expand Up @@ -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;
Expand Down
36 changes: 20 additions & 16 deletions OMXAudio.cpp
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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<unsigned int>(0x10000 * (coeff[i] * s));
mix.coeff[i] = static_cast<unsigned int>(0x10000 * (coeff[i] * r));

OMX_ERRORTYPE omx_err =
m_omx_mixer.SetConfig(OMX_IndexConfigBrcmAudioDownmixCoefficients, &mix);
Expand Down
5 changes: 3 additions & 2 deletions OMXAudio.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions OMXPlayerAudio.cpp
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion OMXPlayerAudio.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion omxplayer.cpp
Expand Up @@ -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};

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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' },
Expand All @@ -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 }
};

Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8084acd

Please sign in to comment.