Skip to content

Commit

Permalink
AE: User per cent volume by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fritsch committed Apr 3, 2014
1 parent 7fb9594 commit 679639c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 32 deletions.
11 changes: 1 addition & 10 deletions xbmc/Application.cpp
Expand Up @@ -5352,16 +5352,7 @@ void CApplication::SetHardwareVolume(float hardwareVolume)
hardwareVolume = std::max(VOLUME_MINIMUM, std::min(VOLUME_MAXIMUM, hardwareVolume));
m_volumeLevel = hardwareVolume;

float value = 0.0f;
if (hardwareVolume > VOLUME_MINIMUM)
{
float dB = CAEUtil::PercentToGain(hardwareVolume);
value = CAEUtil::GainToScale(dB);
}
if (value >= 0.99f)
value = 1.0f;

CAEFactory::SetVolume(value);
CAEFactory::SetVolume(hardwareVolume);
}

float CApplication::GetVolume(bool percentage /* = true */) const
Expand Down
6 changes: 4 additions & 2 deletions xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.cpp
Expand Up @@ -149,6 +149,7 @@ CActiveAE::CActiveAE() :
m_vizBuffers = NULL;
m_vizBuffersInput = NULL;
m_volume = 1.0;
m_volumeScaled = 1.0;
m_aeVolume = 1.0;
m_muted = false;
m_aeMuted = false;
Expand Down Expand Up @@ -225,6 +226,7 @@ void CActiveAE::StateMachine(int signal, Protocol *port, Message *msg)
return;
case CActiveAEControlProtocol::VOLUME:
m_volume = *(float*)msg->data;
m_volumeScaled = CAEUtil::GainToScale(CAEUtil::PercentToGain(m_volume));
if (m_sinkHasVolume)
m_sink.m_controlPort.SendOutMessage(CSinkControlProtocol::VOLUME, &m_volume, sizeof(float));
return;
Expand Down Expand Up @@ -2068,11 +2070,11 @@ void CActiveAE::MixSounds(CSoundPacket &dstSample)

void CActiveAE::Deamplify(CSoundPacket &dstSample)
{
if (m_volume < 1.0 || m_muted)
if (m_volumeScaled < 1.0 || m_muted)
{
float *buffer;
int nb_floats = dstSample.nb_samples * dstSample.config.channels / dstSample.planes;
float volume = m_muted ? 0.0f : m_volume;
float volume = m_muted ? 0.0f : m_volumeScaled;

for(int j=0; j<dstSample.planes; j++)
{
Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/AudioEngine/Engines/ActiveAE/ActiveAE.h
Expand Up @@ -337,7 +337,8 @@ class CActiveAE : public IAE, private CThread
std::list<SoundState> m_sounds_playing;
std::vector<CActiveAESound*> m_sounds;

float m_volume;
float m_volume; // volume on a 0..1 scale corresponding to a proportion along the dB scale
float m_volumeScaled; // multiplier to scale samples in order to achieve the volume specified in m_volume
bool m_muted;
bool m_sinkHasVolume;

Expand Down
4 changes: 1 addition & 3 deletions xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp
Expand Up @@ -217,9 +217,7 @@ void CAESinkAUDIOTRACK::SetVolume(float scale)
if (!m_at_jni)
return;

// Android uses fixed steps, reverse scale back to percent
float gain = CAEUtil::ScaleToGain(scale);
m_volume = CAEUtil::GainToPercent(gain);
m_volume = scale;
if (!m_passthrough)
{
CXBMCApp::SetSystemVolume(xbmc_jnienv(), m_volume);
Expand Down
9 changes: 0 additions & 9 deletions xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.cpp
Expand Up @@ -724,7 +724,6 @@ bool CAESinkDARWINIOS::Initialize(AEAudioFormat &format, std::string &device)
format.m_sampleRate = m_audioSink->getRealisedSampleRate();
m_format = format;

m_volume_changed = false;
m_audioSink->play(false);

return true;
Expand Down Expand Up @@ -799,14 +798,6 @@ bool CAESinkDARWINIOS::HasVolume()
return false;
}

void CAESinkDARWINIOS::SetVolume(float scale)
{
// CoreAudio uses fixed steps, reverse scale back to percent
float gain = CAEUtil::ScaleToGain(scale);
m_volume = CAEUtil::GainToPercent(gain);
m_volume_changed = true;
}

void CAESinkDARWINIOS::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
{
m_devices.clear();
Expand Down
5 changes: 1 addition & 4 deletions xbmc/cores/AudioEngine/Sinks/AESinkDARWINIOS.h
Expand Up @@ -51,18 +51,15 @@ class CAESinkDARWINIOS : public IAESink
virtual unsigned int AddPackets (uint8_t *data, unsigned int frames, bool hasAudio, bool blocking = false);
virtual void Drain ();
virtual bool HasVolume ();
virtual void SetVolume (float scale);
static void EnumerateDevicesEx(AEDeviceInfoList &list, bool force = false);

private:
static AEDeviceInfoList m_devices;
CAEDeviceInfo m_info;
AEAudioFormat m_format;
double m_volume;
bool m_volume_changed;

CAAudioUnitSink *m_audioSink;
#if DO_440HZ_TONE_TEST
SineWaveGenerator m_SineWaveGenerator;
#endif
};
};
4 changes: 2 additions & 2 deletions xbmc/cores/AudioEngine/Sinks/AESinkPULSE.cpp
Expand Up @@ -812,8 +812,8 @@ void CAESinkPULSE::SetVolume(float volume)
{
if (m_IsAllocated && !m_passthrough)
{
// undo internal Engine pseudo gain calculation
float per_cent_volume = CAEUtil::GainToPercent(CAEUtil::ScaleToGain(volume));
// clamp possibly too large / low values
float per_cent_volume = std::max(0.0f, std::min(volume, 1.0f));

pa_threaded_mainloop_lock(m_MainLoop);
bool external_change = false;
Expand Down
6 changes: 5 additions & 1 deletion xbmc/cores/AudioEngine/Utils/AEUtil.h
Expand Up @@ -108,7 +108,11 @@ class CAEUtil
*/
static inline const float GainToScale(const float dB)
{
return pow(10.0f, dB/20);
float val = pow(10.0f, dB/20);
if (val >= 0.99f)
val = 1.0f;

return val;
}

/*! \brief convert a scale factor to dB gain for audio manipulation
Expand Down

0 comments on commit 679639c

Please sign in to comment.