Skip to content

Commit

Permalink
Various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
phire committed Sep 17, 2015
1 parent ebee3cf commit 1b3bb21
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 65 deletions.
24 changes: 10 additions & 14 deletions Source/Core/AudioCommon/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "Common/CPUDetect.h"
#include "Common/MathUtil.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/AudioInterface.h"
#include "Core/HW/VideoInterface.h"

Expand All @@ -20,11 +19,6 @@
#include <tmmintrin.h>
#endif

const float CMixer::LOW_WATERMARK = 1280;
const float CMixer::MAX_FREQ_SHIFT = 200;
const float CMixer::CONTROL_FACTOR = 0.2f;
const float CMixer::CONTROL_AVG = 32;

void CMixer::LinearMixerFifo::Interpolate(u32 left_input_index, float* left_output, float* right_output)
{
*left_output = (1 - m_fraction) * m_float_buffer[left_input_index & INDEX_MASK]
Expand All @@ -34,22 +28,24 @@ void CMixer::LinearMixerFifo::Interpolate(u32 left_input_index, float* left_outp
}

static const float _coeffs[] =
{ -0.5f, 1.0f, -0.5f, 0.0f,
1.5f, -2.5f, 0.0f, 1.0f,
-1.5f, 2.0f, 0.5f, 0.0f,
0.5f, -0.5f, 0.0f, 0.0f };
{
-0.5f, 1.0f, -0.5f, 0.0f,
1.5f, -2.5f, 0.0f, 1.0f,
-1.5f, 2.0f, 0.5f, 0.0f,
0.5f, -0.5f, 0.0f, 0.0f,
};

void CMixer::CubicMixerFifo::Interpolate(u32 left_input_index, float* left_output, float* right_output)
{
const float x2 = m_fraction; // x
const float x1 = x2*x2; // x^2
const float x0 = x1*x2; // x^3
const float x1 = x2 * x2; // x^2
const float x0 = x1 * x2; // x^3

float y0 = _coeffs[0] * x0 + _coeffs[1] * x1 + _coeffs[2] * x2 + _coeffs[3];
float y1 = _coeffs[4] * x0 + _coeffs[5] * x1 + _coeffs[6] * x2 + _coeffs[7];
float y2 = _coeffs[8] * x0 + _coeffs[9] * x1 + _coeffs[10] * x2 + _coeffs[11];
float y3 = _coeffs[12] * x0 + _coeffs[13] * x1 + _coeffs[14] * x2 + _coeffs[15];

*left_output = y0 * m_float_buffer[left_input_index & INDEX_MASK]
+ y1 * m_float_buffer[(left_input_index + 2) & INDEX_MASK]
+ y2 * m_float_buffer[(left_input_index + 4) & INDEX_MASK]
Expand Down Expand Up @@ -173,7 +169,7 @@ u32 CMixer::Mix(float* samples, u32 num_samples, bool consider_framelimit)
memset(samples, 0, num_samples * 2 * sizeof(float));
if (PowerPC::GetState() != PowerPC::CPU_RUNNING)
{
// Silence
// Silence
return num_samples;
}
m_dma_mixer.Mix(samples, num_samples, consider_framelimit);
Expand Down
28 changes: 12 additions & 16 deletions Source/Core/AudioCommon/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#pragma once

#include <atomic>
#include <array>
#include <atomic>
#include <mutex>
#include <string>
#include <vector>
Expand All @@ -18,21 +18,20 @@ const float rndrcp = 8.f / float(RAND_MAX);
#define DITHER_NOISE ((rand() * rndrcp) - 4.f)

// converts [-32768, 32767] -> [-1.0, 1.0)
__forceinline float Signed16ToFloat(const s16 s)
constexpr float Signed16ToFloat(const s16 s)
{
return s * 0.000030517578125f;
}

// we NEED dithering going from float -> 16bit
__forceinline void TriangleDither(float& sample, float& prev_dither)
{
float dither = DITHER_NOISE;
float dither = DITHER_NOISE;
sample += dither - prev_dither;
prev_dither = dither;
}

class CMixer {

public:
CMixer(u32 BackendSampleRate)
: m_dma_mixer(this, 32000)
Expand All @@ -48,23 +47,21 @@ class CMixer {
INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized");
}

static const u32 MAX_SAMPLES = 2048;
static const u32 INDEX_MASK = MAX_SAMPLES * 2 - 1;
static const float LOW_WATERMARK;
static const float MAX_FREQ_SHIFT;
static const float CONTROL_FACTOR;
static const float CONTROL_AVG;

virtual ~CMixer() {}
static constexpr u32 MAX_SAMPLES = 2048;
static constexpr u32 INDEX_MASK = MAX_SAMPLES * 2 - 1;
static constexpr float LOW_WATERMARK = 1280;
static constexpr float MAX_FREQ_SHIFT = 200;
static constexpr float CONTROL_FACTOR = 0.2f;
static constexpr float CONTROL_AVG = 32;

// Called from audio threads
u32 Mix(s16* samples, u32 numSamples, bool consider_framelimit = true);
u32 Mix(float* samples, u32 numSamples, bool consider_framelimit = true);
u32 AvailableSamples();
// Called from main thread
virtual void PushSamples(const s16* samples, u32 num_samples);
virtual void PushStreamingSamples(const s16* samples, u32 num_samples);
virtual void PushWiimoteSpeakerSamples(const s16* samples, u32 num_samples, u32 sample_rate);
void PushSamples(const s16* samples, u32 num_samples);
void PushStreamingSamples(const s16* samples, u32 num_samples);
void PushWiimoteSpeakerSamples(const s16* samples, u32 num_samples, u32 sample_rate);
u32 GetSampleRate() const { return m_sample_rate; }

void SetDMAInputSampleRate(u32 rate);
Expand Down Expand Up @@ -159,7 +156,6 @@ class CMixer {
std::atomic<float> m_speed; // Current rate of the emulation (1.0 = 100% speed)

private:

std::vector<float> m_output_buffer;
float m_l_dither_prev;
float m_r_dither_prev;
Expand Down
11 changes: 1 addition & 10 deletions Source/Core/AudioCommon/NullSoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

bool NullSound::Start()
{
m_enablesoundloop = false;
m_enablesoundloop = false;
return true;
}

void NullSound::SetVolume(int volume)
{
}

void NullSound::Update()
{
m_mixer->Mix(realtimeBuffer, 0);
Expand All @@ -26,8 +22,3 @@ void NullSound::Clear(bool mute)
{
m_muted = mute;
}

void NullSound::Stop()
{

}
7 changes: 2 additions & 5 deletions Source/Core/AudioCommon/NullSoundStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ class NullSound final : public SoundStream
short realtimeBuffer[BUF_SIZE / sizeof(short)];

public:
NullSound()
{}

virtual ~NullSound() {}

virtual bool Start() override;
virtual void SetVolume(int volume) override;
virtual void Stop() override;
virtual void SetVolume(int volume) override {};
virtual void Stop() override {};
virtual void Clear(bool mute) override;
static bool isValid() { return true; }
virtual void Update() override;
Expand Down
6 changes: 1 addition & 5 deletions Source/Core/AudioCommon/OpenALStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#include "AudioCommon/aldlist.h"
#include "AudioCommon/DPL2Decoder.h"
#include "AudioCommon/OpenALStream.h"
#include "Core/Core.h"
#include "Core/ConfigManager.h"



#if defined HAVE_OPENAL && HAVE_OPENAL

#ifdef _WIN32
Expand Down Expand Up @@ -160,9 +157,8 @@ bool OpenALStream::SupportSurroundOutput()
bool surround_capable = SConfig::GetInstance().bDPL2Decoder;
#if defined(__APPLE__)
surround_capable = false;
#endif
#endif
return surround_capable;
}

#endif //HAVE_OPENAL

15 changes: 7 additions & 8 deletions Source/Core/AudioCommon/SoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
#ifdef __APPLE__
#undef BOOL
#endif
#include "Core/Core.h"
#include "Core/ConfigManager.h"
#include "Core/HW/AudioInterface.h"
#include "Core/HW/SystemTimers.h"

#include "AudioCommon/AudioCommon.h"
#include "AudioCommon/DPL2Decoder.h"
#include "AudioCommon/SoundStream.h"

#include "Common/MathUtil.h"
#include "Core/ConfigManager.h"
#include "Core/HW/AudioInterface.h"
#include "Core/HW/SystemTimers.h"

void SoundStream::StartLogAudio(const char *filename) {
void SoundStream::StartLogAudio(const char *filename)
{
if (!m_logAudio) {
m_logAudio = true;
g_wave_writer.Start(filename, GetMixer()->GetSampleRate());
Expand All @@ -37,7 +35,8 @@ void SoundStream::StartLogAudio(const char *filename) {
}
}

void SoundStream::StopLogAudio() {
void SoundStream::StopLogAudio()
{
if (m_logAudio) {
m_logAudio = false;
g_wave_writer.Stop();
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/AudioCommon/XAudio2Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
#include <xaudio2.h>
#include "AudioCommon/AudioCommon.h"
#include "AudioCommon/XAudio2Stream.h"
#include "Core/Core.h"
#include "Core/ConfigManager.h"
#include "Common/Event.h"
#include "Core/ConfigManager.h"

struct StreamingVoiceContext : public IXAudio2VoiceCallback
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/AudioCommon/XAudio2Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ class XAudio2 final : public SoundStream
{}

#endif
};
};
7 changes: 3 additions & 4 deletions Source/Core/AudioCommon/XAudio2_7Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include "AudioCommon/AudioCommon.h"
#include "AudioCommon/XAudio2_7Stream.h"
#include "Core/Core.h"
#include "Core/ConfigManager.h"
#include "Common/Event.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"

struct StreamingVoiceContext2_7 : public IXAudio2VoiceCallback
{
Expand Down Expand Up @@ -245,8 +245,7 @@ void XAudio2_7::WriteSamples(s16 *src, u32 numsamples)

bool XAudio2_7::SupportSurroundOutput()
{
bool surround_capable = SConfig::GetInstance().bDPL2Decoder;
return surround_capable;
return SConfig::GetInstance().bDPL2Decoder;
}

void XAudio2_7::SetVolume(int volume)
Expand Down

0 comments on commit 1b3bb21

Please sign in to comment.