Merge pull request #5701 from ligfx/renamecmixertomixer

Rename CMixer to Mixer
This commit is contained in:
JosJuice 2017-06-27 08:15:02 +02:00 committed by GitHub
commit 4ad46f1c7c
9 changed files with 42 additions and 43 deletions

View File

@ -181,7 +181,7 @@ void SendAIBuffer(const short* samples, unsigned int num_samples)
else if (!SConfig::GetInstance().m_DumpAudio && s_audio_dump_start) else if (!SConfig::GetInstance().m_DumpAudio && s_audio_dump_start)
StopAudioDump(); StopAudioDump();
CMixer* pMixer = g_sound_stream->GetMixer(); Mixer* pMixer = g_sound_stream->GetMixer();
if (pMixer && samples) if (pMixer && samples)
{ {

View File

@ -10,7 +10,7 @@
#include "AudioCommon/SoundStream.h" #include "AudioCommon/SoundStream.h"
class CMixer; class Mixer;
extern std::unique_ptr<SoundStream> g_sound_stream; extern std::unique_ptr<SoundStream> g_sound_stream;

View File

@ -14,20 +14,20 @@
#include "Common/Swap.h" #include "Common/Swap.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
CMixer::CMixer(unsigned int BackendSampleRate) Mixer::Mixer(unsigned int BackendSampleRate)
: m_sampleRate(BackendSampleRate), m_stretcher(BackendSampleRate) : m_sampleRate(BackendSampleRate), m_stretcher(BackendSampleRate)
{ {
INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized"); INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized");
DPL2Reset(); DPL2Reset();
} }
CMixer::~CMixer() Mixer::~Mixer()
{ {
} }
// Executed from sound stream thread // Executed from sound stream thread
unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples, unsigned int Mixer::MixerFifo::Mix(short* samples, unsigned int numSamples,
bool consider_framelimit) bool consider_framelimit)
{ {
unsigned int currentSample = 0; unsigned int currentSample = 0;
@ -117,7 +117,7 @@ unsigned int CMixer::MixerFifo::Mix(short* samples, unsigned int numSamples,
return actual_sample_count; return actual_sample_count;
} }
unsigned int CMixer::Mix(short* samples, unsigned int num_samples) unsigned int Mixer::Mix(short* samples, unsigned int num_samples)
{ {
if (!samples) if (!samples)
return 0; return 0;
@ -154,7 +154,7 @@ unsigned int CMixer::Mix(short* samples, unsigned int num_samples)
return num_samples; return num_samples;
} }
unsigned int CMixer::MixSurround(float* samples, unsigned int num_samples) unsigned int Mixer::MixSurround(float* samples, unsigned int num_samples)
{ {
if (!num_samples) if (!num_samples)
return 0; return 0;
@ -175,7 +175,7 @@ unsigned int CMixer::MixSurround(float* samples, unsigned int num_samples)
return available_samples; return available_samples;
} }
void CMixer::MixerFifo::PushSamples(const short* samples, unsigned int num_samples) void Mixer::MixerFifo::PushSamples(const short* samples, unsigned int num_samples)
{ {
// Cache access in non-volatile variable // Cache access in non-volatile variable
// indexR isn't allowed to cache in the audio throttling loop as it // indexR isn't allowed to cache in the audio throttling loop as it
@ -204,7 +204,7 @@ void CMixer::MixerFifo::PushSamples(const short* samples, unsigned int num_sampl
m_indexW.fetch_add(num_samples * 2); m_indexW.fetch_add(num_samples * 2);
} }
void CMixer::PushSamples(const short* samples, unsigned int num_samples) void Mixer::PushSamples(const short* samples, unsigned int num_samples)
{ {
m_dma_mixer.PushSamples(samples, num_samples); m_dma_mixer.PushSamples(samples, num_samples);
int sample_rate = m_dma_mixer.GetInputSampleRate(); int sample_rate = m_dma_mixer.GetInputSampleRate();
@ -212,7 +212,7 @@ void CMixer::PushSamples(const short* samples, unsigned int num_samples)
m_wave_writer_dsp.AddStereoSamplesBE(samples, num_samples, sample_rate); m_wave_writer_dsp.AddStereoSamplesBE(samples, num_samples, sample_rate);
} }
void CMixer::PushStreamingSamples(const short* samples, unsigned int num_samples) void Mixer::PushStreamingSamples(const short* samples, unsigned int num_samples)
{ {
m_streaming_mixer.PushSamples(samples, num_samples); m_streaming_mixer.PushSamples(samples, num_samples);
int sample_rate = m_streaming_mixer.GetInputSampleRate(); int sample_rate = m_streaming_mixer.GetInputSampleRate();
@ -220,8 +220,8 @@ void CMixer::PushStreamingSamples(const short* samples, unsigned int num_samples
m_wave_writer_dtk.AddStereoSamplesBE(samples, num_samples, sample_rate); m_wave_writer_dtk.AddStereoSamplesBE(samples, num_samples, sample_rate);
} }
void CMixer::PushWiimoteSpeakerSamples(const short* samples, unsigned int num_samples, void Mixer::PushWiimoteSpeakerSamples(const short* samples, unsigned int num_samples,
unsigned int sample_rate) unsigned int sample_rate)
{ {
short samples_stereo[MAX_SAMPLES * 2]; short samples_stereo[MAX_SAMPLES * 2];
@ -239,27 +239,27 @@ void CMixer::PushWiimoteSpeakerSamples(const short* samples, unsigned int num_sa
} }
} }
void CMixer::SetDMAInputSampleRate(unsigned int rate) void Mixer::SetDMAInputSampleRate(unsigned int rate)
{ {
m_dma_mixer.SetInputSampleRate(rate); m_dma_mixer.SetInputSampleRate(rate);
} }
void CMixer::SetStreamInputSampleRate(unsigned int rate) void Mixer::SetStreamInputSampleRate(unsigned int rate)
{ {
m_streaming_mixer.SetInputSampleRate(rate); m_streaming_mixer.SetInputSampleRate(rate);
} }
void CMixer::SetStreamingVolume(unsigned int lvolume, unsigned int rvolume) void Mixer::SetStreamingVolume(unsigned int lvolume, unsigned int rvolume)
{ {
m_streaming_mixer.SetVolume(lvolume, rvolume); m_streaming_mixer.SetVolume(lvolume, rvolume);
} }
void CMixer::SetWiimoteSpeakerVolume(unsigned int lvolume, unsigned int rvolume) void Mixer::SetWiimoteSpeakerVolume(unsigned int lvolume, unsigned int rvolume)
{ {
m_wiimote_speaker_mixer.SetVolume(lvolume, rvolume); m_wiimote_speaker_mixer.SetVolume(lvolume, rvolume);
} }
void CMixer::StartLogDTKAudio(const std::string& filename) void Mixer::StartLogDTKAudio(const std::string& filename)
{ {
if (!m_log_dtk_audio) if (!m_log_dtk_audio)
{ {
@ -282,7 +282,7 @@ void CMixer::StartLogDTKAudio(const std::string& filename)
} }
} }
void CMixer::StopLogDTKAudio() void Mixer::StopLogDTKAudio()
{ {
if (m_log_dtk_audio) if (m_log_dtk_audio)
{ {
@ -296,7 +296,7 @@ void CMixer::StopLogDTKAudio()
} }
} }
void CMixer::StartLogDSPAudio(const std::string& filename) void Mixer::StartLogDSPAudio(const std::string& filename)
{ {
if (!m_log_dsp_audio) if (!m_log_dsp_audio)
{ {
@ -319,7 +319,7 @@ void CMixer::StartLogDSPAudio(const std::string& filename)
} }
} }
void CMixer::StopLogDSPAudio() void Mixer::StopLogDSPAudio()
{ {
if (m_log_dsp_audio) if (m_log_dsp_audio)
{ {
@ -333,26 +333,26 @@ void CMixer::StopLogDSPAudio()
} }
} }
void CMixer::MixerFifo::SetInputSampleRate(unsigned int rate) void Mixer::MixerFifo::SetInputSampleRate(unsigned int rate)
{ {
m_input_sample_rate = rate; m_input_sample_rate = rate;
} }
unsigned int CMixer::MixerFifo::GetInputSampleRate() const unsigned int Mixer::MixerFifo::GetInputSampleRate() const
{ {
return m_input_sample_rate; return m_input_sample_rate;
} }
void CMixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume) void Mixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume)
{ {
m_LVolume.store(lvolume + (lvolume >> 7)); m_LVolume.store(lvolume + (lvolume >> 7));
m_RVolume.store(rvolume + (rvolume >> 7)); m_RVolume.store(rvolume + (rvolume >> 7));
} }
unsigned int CMixer::MixerFifo::AvailableSamples() const unsigned int Mixer::MixerFifo::AvailableSamples() const
{ {
unsigned int samples_in_fifo = ((m_indexW.load() - m_indexR.load()) & INDEX_MASK) / 2; unsigned int samples_in_fifo = ((m_indexW.load() - m_indexR.load()) & INDEX_MASK) / 2;
if (samples_in_fifo <= 1) if (samples_in_fifo <= 1)
return 0; // CMixer::MixerFifo::Mix always keeps one sample in the buffer. return 0; // Mixer::MixerFifo::Mix always keeps one sample in the buffer.
return (samples_in_fifo - 1) * m_mixer->m_sampleRate / m_input_sample_rate; return (samples_in_fifo - 1) * m_mixer->m_sampleRate / m_input_sample_rate;
} }

View File

@ -11,11 +11,11 @@
#include "AudioCommon/WaveFile.h" #include "AudioCommon/WaveFile.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
class CMixer final class Mixer final
{ {
public: public:
explicit CMixer(unsigned int BackendSampleRate); explicit Mixer(unsigned int BackendSampleRate);
~CMixer(); ~Mixer();
// Called from audio threads // Called from audio threads
unsigned int Mix(short* samples, unsigned int numSamples); unsigned int Mix(short* samples, unsigned int numSamples);
@ -50,8 +50,7 @@ private:
class MixerFifo final class MixerFifo final
{ {
public: public:
MixerFifo(CMixer* mixer, unsigned sample_rate) MixerFifo(Mixer* mixer, unsigned sample_rate) : m_mixer(mixer), m_input_sample_rate(sample_rate)
: m_mixer(mixer), m_input_sample_rate(sample_rate)
{ {
} }
void PushSamples(const short* samples, unsigned int num_samples); void PushSamples(const short* samples, unsigned int num_samples);
@ -62,7 +61,7 @@ private:
unsigned int AvailableSamples() const; unsigned int AvailableSamples() const;
private: private:
CMixer* m_mixer; Mixer* m_mixer;
unsigned m_input_sample_rate; unsigned m_input_sample_rate;
std::array<short, MAX_SAMPLES * 2> m_buffer{}; std::array<short, MAX_SAMPLES * 2> m_buffer{};
std::atomic<u32> m_indexW{0}; std::atomic<u32> m_indexW{0};

View File

@ -24,7 +24,7 @@ static SLPlayItf bqPlayerPlay;
static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
static SLMuteSoloItf bqPlayerMuteSolo; static SLMuteSoloItf bqPlayerMuteSolo;
static SLVolumeItf bqPlayerVolume; static SLVolumeItf bqPlayerVolume;
static CMixer* g_mixer; static Mixer* g_mixer;
#define BUFFER_SIZE 512 #define BUFFER_SIZE 512
#define BUFFER_SIZE_IN_SAMPLES (BUFFER_SIZE / 2) #define BUFFER_SIZE_IN_SAMPLES (BUFFER_SIZE / 2)

View File

@ -12,14 +12,14 @@
class SoundStream class SoundStream
{ {
protected: protected:
std::unique_ptr<CMixer> m_mixer; std::unique_ptr<Mixer> m_mixer;
bool m_muted; bool m_muted;
public: public:
SoundStream() : m_mixer(new CMixer(48000)), m_muted(false) {} SoundStream() : m_mixer(new Mixer(48000)), m_muted(false) {}
virtual ~SoundStream() {} virtual ~SoundStream() {}
static bool isValid() { return false; } static bool isValid() { return false; }
CMixer* GetMixer() const { return m_mixer.get(); } Mixer* GetMixer() const { return m_mixer.get(); }
virtual bool Start() { return false; } virtual bool Start() { return false; }
virtual void SetVolume(int) {} virtual void SetVolume(int) {}
virtual void SoundLoop() {} virtual void SoundLoop() {}

View File

@ -16,7 +16,7 @@
struct StreamingVoiceContext : public IXAudio2VoiceCallback struct StreamingVoiceContext : public IXAudio2VoiceCallback
{ {
private: private:
CMixer* const m_mixer; Mixer* const m_mixer;
Common::Event& m_sound_sync_event; Common::Event& m_sound_sync_event;
IXAudio2SourceVoice* m_source_voice; IXAudio2SourceVoice* m_source_voice;
std::unique_ptr<BYTE[]> xaudio_buffer; std::unique_ptr<BYTE[]> xaudio_buffer;
@ -24,7 +24,7 @@ private:
void SubmitBuffer(PBYTE buf_data); void SubmitBuffer(PBYTE buf_data);
public: public:
StreamingVoiceContext(IXAudio2* pXAudio2, CMixer* pMixer, Common::Event& pSyncEvent); StreamingVoiceContext(IXAudio2* pXAudio2, Mixer* pMixer, Common::Event& pSyncEvent);
virtual ~StreamingVoiceContext(); virtual ~StreamingVoiceContext();
void Stop(); void Stop();
@ -56,7 +56,7 @@ void StreamingVoiceContext::SubmitBuffer(PBYTE buf_data)
m_source_voice->SubmitSourceBuffer(&buf); m_source_voice->SubmitSourceBuffer(&buf);
} }
StreamingVoiceContext::StreamingVoiceContext(IXAudio2* pXAudio2, CMixer* pMixer, StreamingVoiceContext::StreamingVoiceContext(IXAudio2* pXAudio2, Mixer* pMixer,
Common::Event& pSyncEvent) Common::Event& pSyncEvent)
: m_mixer(pMixer), m_sound_sync_event(pSyncEvent), : m_mixer(pMixer), m_sound_sync_event(pSyncEvent),
xaudio_buffer(new BYTE[NUM_BUFFERS * BUFFER_SIZE_BYTES]()) xaudio_buffer(new BYTE[NUM_BUFFERS * BUFFER_SIZE_BYTES]())

View File

@ -16,7 +16,7 @@
struct StreamingVoiceContext2_7 : public IXAudio2VoiceCallback struct StreamingVoiceContext2_7 : public IXAudio2VoiceCallback
{ {
private: private:
CMixer* const m_mixer; Mixer* const m_mixer;
Common::Event& m_sound_sync_event; Common::Event& m_sound_sync_event;
IXAudio2SourceVoice* m_source_voice; IXAudio2SourceVoice* m_source_voice;
std::unique_ptr<BYTE[]> xaudio_buffer; std::unique_ptr<BYTE[]> xaudio_buffer;
@ -24,7 +24,7 @@ private:
void SubmitBuffer(PBYTE buf_data); void SubmitBuffer(PBYTE buf_data);
public: public:
StreamingVoiceContext2_7(IXAudio2* pXAudio2, CMixer* pMixer, Common::Event& pSyncEvent); StreamingVoiceContext2_7(IXAudio2* pXAudio2, Mixer* pMixer, Common::Event& pSyncEvent);
virtual ~StreamingVoiceContext2_7(); virtual ~StreamingVoiceContext2_7();
void Stop(); void Stop();
@ -56,7 +56,7 @@ void StreamingVoiceContext2_7::SubmitBuffer(PBYTE buf_data)
m_source_voice->SubmitSourceBuffer(&buf); m_source_voice->SubmitSourceBuffer(&buf);
} }
StreamingVoiceContext2_7::StreamingVoiceContext2_7(IXAudio2* pXAudio2, CMixer* pMixer, StreamingVoiceContext2_7::StreamingVoiceContext2_7(IXAudio2* pXAudio2, Mixer* pMixer,
Common::Event& pSyncEvent) Common::Event& pSyncEvent)
: m_mixer(pMixer), m_sound_sync_event(pSyncEvent), : m_mixer(pMixer), m_sound_sync_event(pSyncEvent),
xaudio_buffer(new BYTE[NUM_BUFFERS * BUFFER_SIZE_BYTES]()) xaudio_buffer(new BYTE[NUM_BUFFERS * BUFFER_SIZE_BYTES]())

View File

@ -918,7 +918,7 @@ void UpdateTitle()
// Update the audio timestretcher with the current speed // Update the audio timestretcher with the current speed
if (g_sound_stream) if (g_sound_stream)
{ {
CMixer* pMixer = g_sound_stream->GetMixer(); Mixer* pMixer = g_sound_stream->GetMixer();
pMixer->UpdateSpeed((float)Speed / 100); pMixer->UpdateSpeed((float)Speed / 100);
} }