Skip to content

Commit

Permalink
[PATCH] [AE/CA] - add soft limiter / volume amplification
Browse files Browse the repository at this point in the history
  • Loading branch information
Memphiz authored and bobo1on1 committed Nov 13, 2012
1 parent 970818e commit ea8c26b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 20 additions & 1 deletion xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.cpp
Expand Up @@ -132,6 +132,7 @@ CCoreAudioAEStream::CCoreAudioAEStream(enum AEDataFormat dataFormat, unsigned in
m_vizRemapBuffer = (uint8_t *)_aligned_malloc(m_vizRemapBufferSize,16);

m_isRaw = COREAUDIO_IS_RAW(dataFormat);
m_limiter.SetSamplerate(AE.GetSampleRate());
}

CCoreAudioAEStream::~CCoreAudioAEStream()
Expand Down Expand Up @@ -453,14 +454,14 @@ unsigned int CCoreAudioAEStream::GetFrames(uint8_t *buffer, unsigned int size)
{
float *floatBuffer = (float *)buffer;
unsigned int samples = readsize / m_OutputBytesPerSample;
unsigned int frames = samples / m_chLayoutCountOutput;

// we have a frame, if we have a viz we need to hand the data to it.
// Keep in mind that our buffer is already in output format.
// So we remap output format to viz format !!!
if (m_OutputFormat.m_dataFormat == AE_FMT_FLOAT)
{
// TODO : Why the hell is vizdata limited ?
unsigned int frames = samples / m_chLayoutCountOutput;
unsigned int samplesClamped = (samples > 512) ? 512 : samples;
if (samplesClamped)
{
Expand Down Expand Up @@ -498,6 +499,24 @@ unsigned int CCoreAudioAEStream::GetFrames(uint8_t *buffer, unsigned int size)
#endif
CAEUtil::ClampArray(floatBuffer, samples);
}
// apply volume amplification by using the sogt limiter
// TODO - maybe reinvent the coreaudio compressor for this after frodo
else if (GetAmplification() != 1.0f)
{
for(unsigned int i = 0; i < frames; i++)
{
int frameIdx = i*m_chLayoutCountOutput;
float amplification = RunLimiter(&floatBuffer[frameIdx], m_chLayoutCountOutput);
float *frameStart = &floatBuffer[frameIdx];
#ifdef __SSE___
CAEUtil::SSEMulArray(frameStart, amplification, m_chLayoutCountOutput);
#else
for(unsigned int n = 0; n < m_chLayoutCountOutput; n++)
frameStart[n] *= amplification;
#endif

}
}
}

return readsize;
Expand Down
6 changes: 6 additions & 0 deletions xbmc/cores/AudioEngine/Engines/CoreAudio/CoreAudioAEStream.h
Expand Up @@ -28,6 +28,7 @@
#include "Interfaces/AEStream.h"
#include "cores/AudioEngine/Utils/AEConvert.h"
#include "cores/AudioEngine/Utils/AERemap.h"
#include "Utils/AELimiter.h"

#if defined(TARGET_DARWIN_IOS)
# include "CoreAudioAEHALIOS.h"
Expand Down Expand Up @@ -77,8 +78,12 @@ class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource

virtual float GetVolume();
virtual float GetReplayGain();
virtual float GetAmplification() { return m_limiter.GetAmplification(); }
virtual void SetVolume(float volume);
virtual void SetReplayGain(float factor);
virtual void SetAmplification(float amplify){ m_limiter.SetAmplification(amplify); }

virtual float RunLimiter(float* frame, int channels) { return m_limiter.Run(frame, channels); }

virtual const unsigned int GetChannelCount() const;
virtual const unsigned int GetSampleRate() const;
Expand Down Expand Up @@ -129,6 +134,7 @@ class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
CAERemap m_remap; /* the remapper */
float m_volume; /* the volume level */
float m_rgain; /* replay gain level */
CAELimiter m_limiter; /* volume amplification/limiter*/
IAEStream *m_slave; /* slave aestream */

CAEConvert::AEConvertToFn m_convertFn;
Expand Down

0 comments on commit ea8c26b

Please sign in to comment.