mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-08 21:53:31 +01:00
Merge pull request #2445 from lioncash/mixer
AudioCommon: Construct the mixer inside the SoundStream base class.
This commit is contained in:
commit
5213d85118
@ -77,8 +77,4 @@ void AOSound::Stop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AOSound::~AOSound()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,10 +33,6 @@ class AOSound final : public SoundStream
|
|||||||
short realtimeBuffer[1024 * 1024];
|
short realtimeBuffer[1024 * 1024];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AOSound(CMixer *mixer) : SoundStream(mixer) {}
|
|
||||||
|
|
||||||
virtual ~AOSound();
|
|
||||||
|
|
||||||
virtual bool Start() override;
|
virtual bool Start() override;
|
||||||
|
|
||||||
virtual void SoundLoop() override;
|
virtual void SoundLoop() override;
|
||||||
@ -49,9 +45,5 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update() override;
|
virtual void Update() override;
|
||||||
|
|
||||||
#else
|
|
||||||
public:
|
|
||||||
AOSound(CMixer *mixer) : SoundStream(mixer) {}
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -10,9 +10,8 @@
|
|||||||
#define BUFFER_SIZE_MAX 8192
|
#define BUFFER_SIZE_MAX 8192
|
||||||
#define BUFFER_SIZE_BYTES (BUFFER_SIZE_MAX*2*2)
|
#define BUFFER_SIZE_BYTES (BUFFER_SIZE_MAX*2*2)
|
||||||
|
|
||||||
AlsaSound::AlsaSound(CMixer *mixer)
|
AlsaSound::AlsaSound()
|
||||||
: SoundStream(mixer)
|
: m_thread_status(ALSAThreadStatus::STOPPED)
|
||||||
, m_thread_status(ALSAThreadStatus::STOPPED)
|
|
||||||
, handle(nullptr)
|
, handle(nullptr)
|
||||||
, frames_to_deliver(FRAME_COUNT_MIN)
|
, frames_to_deliver(FRAME_COUNT_MIN)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ class AlsaSound final : public SoundStream
|
|||||||
{
|
{
|
||||||
#if defined(HAVE_ALSA) && HAVE_ALSA
|
#if defined(HAVE_ALSA) && HAVE_ALSA
|
||||||
public:
|
public:
|
||||||
AlsaSound(CMixer *mixer);
|
AlsaSound();
|
||||||
virtual ~AlsaSound();
|
virtual ~AlsaSound();
|
||||||
|
|
||||||
virtual bool Start() override;
|
virtual bool Start() override;
|
||||||
@ -49,8 +49,5 @@ private:
|
|||||||
|
|
||||||
snd_pcm_t *handle;
|
snd_pcm_t *handle;
|
||||||
int frames_to_deliver;
|
int frames_to_deliver;
|
||||||
#else
|
|
||||||
public:
|
|
||||||
AlsaSound(CMixer *mixer) : SoundStream(mixer) {}
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -32,38 +32,34 @@ namespace AudioCommon
|
|||||||
|
|
||||||
SoundStream* InitSoundStream()
|
SoundStream* InitSoundStream()
|
||||||
{
|
{
|
||||||
CMixer *mixer = new CMixer(48000);
|
|
||||||
|
|
||||||
// TODO: possible memleak with mixer
|
|
||||||
|
|
||||||
std::string backend = SConfig::GetInstance().sBackend;
|
std::string backend = SConfig::GetInstance().sBackend;
|
||||||
if (backend == BACKEND_OPENAL && OpenALStream::isValid())
|
if (backend == BACKEND_OPENAL && OpenALStream::isValid())
|
||||||
g_sound_stream = new OpenALStream(mixer);
|
g_sound_stream = new OpenALStream();
|
||||||
else if (backend == BACKEND_NULLSOUND && NullSound::isValid())
|
else if (backend == BACKEND_NULLSOUND && NullSound::isValid())
|
||||||
g_sound_stream = new NullSound(mixer);
|
g_sound_stream = new NullSound();
|
||||||
else if (backend == BACKEND_XAUDIO2)
|
else if (backend == BACKEND_XAUDIO2)
|
||||||
{
|
{
|
||||||
if (XAudio2::isValid())
|
if (XAudio2::isValid())
|
||||||
g_sound_stream = new XAudio2(mixer);
|
g_sound_stream = new XAudio2();
|
||||||
else if (XAudio2_7::isValid())
|
else if (XAudio2_7::isValid())
|
||||||
g_sound_stream = new XAudio2_7(mixer);
|
g_sound_stream = new XAudio2_7();
|
||||||
}
|
}
|
||||||
else if (backend == BACKEND_AOSOUND && AOSound::isValid())
|
else if (backend == BACKEND_AOSOUND && AOSound::isValid())
|
||||||
g_sound_stream = new AOSound(mixer);
|
g_sound_stream = new AOSound();
|
||||||
else if (backend == BACKEND_ALSA && AlsaSound::isValid())
|
else if (backend == BACKEND_ALSA && AlsaSound::isValid())
|
||||||
g_sound_stream = new AlsaSound(mixer);
|
g_sound_stream = new AlsaSound();
|
||||||
else if (backend == BACKEND_COREAUDIO && CoreAudioSound::isValid())
|
else if (backend == BACKEND_COREAUDIO && CoreAudioSound::isValid())
|
||||||
g_sound_stream = new CoreAudioSound(mixer);
|
g_sound_stream = new CoreAudioSound();
|
||||||
else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid())
|
else if (backend == BACKEND_PULSEAUDIO && PulseAudio::isValid())
|
||||||
g_sound_stream = new PulseAudio(mixer);
|
g_sound_stream = new PulseAudio();
|
||||||
else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
|
else if (backend == BACKEND_OPENSLES && OpenSLESStream::isValid())
|
||||||
g_sound_stream = new OpenSLESStream(mixer);
|
g_sound_stream = new OpenSLESStream();
|
||||||
|
|
||||||
if (!g_sound_stream && NullSound::isValid())
|
if (!g_sound_stream && NullSound::isValid())
|
||||||
{
|
{
|
||||||
WARN_LOG(DSPHLE, "Could not initialize backend %s, using %s instead.",
|
WARN_LOG(DSPHLE, "Could not initialize backend %s, using %s instead.",
|
||||||
backend.c_str(), BACKEND_NULLSOUND);
|
backend.c_str(), BACKEND_NULLSOUND);
|
||||||
g_sound_stream = new NullSound(mixer);
|
g_sound_stream = new NullSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_sound_stream)
|
if (g_sound_stream)
|
||||||
|
@ -19,14 +19,6 @@ OSStatus CoreAudioSound::callback(void *inRefCon,
|
|||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioSound::CoreAudioSound(CMixer *mixer) : SoundStream(mixer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CoreAudioSound::~CoreAudioSound()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CoreAudioSound::Start()
|
bool CoreAudioSound::Start()
|
||||||
{
|
{
|
||||||
OSStatus err;
|
OSStatus err;
|
||||||
|
@ -14,9 +14,6 @@ class CoreAudioSound final : public SoundStream
|
|||||||
{
|
{
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
public:
|
public:
|
||||||
CoreAudioSound(CMixer *mixer);
|
|
||||||
virtual ~CoreAudioSound();
|
|
||||||
|
|
||||||
virtual bool Start();
|
virtual bool Start();
|
||||||
virtual void SetVolume(int volume);
|
virtual void SetVolume(int volume);
|
||||||
virtual void SoundLoop();
|
virtual void SoundLoop();
|
||||||
@ -38,8 +35,5 @@ private:
|
|||||||
const AudioTimeStamp *inTimeStamp,
|
const AudioTimeStamp *inTimeStamp,
|
||||||
UInt32 inBusNumber, UInt32 inNumberFrames,
|
UInt32 inBusNumber, UInt32 inNumberFrames,
|
||||||
AudioBufferList *ioData);
|
AudioBufferList *ioData);
|
||||||
#else
|
|
||||||
public:
|
|
||||||
CoreAudioSound(CMixer *mixer) : SoundStream(mixer) {}
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -15,12 +15,6 @@ class NullSound final : public SoundStream
|
|||||||
short realtimeBuffer[BUF_SIZE / sizeof(short)];
|
short realtimeBuffer[BUF_SIZE / sizeof(short)];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NullSound(CMixer *mixer)
|
|
||||||
: SoundStream(mixer)
|
|
||||||
{}
|
|
||||||
|
|
||||||
virtual ~NullSound() {}
|
|
||||||
|
|
||||||
virtual bool Start() override;
|
virtual bool Start() override;
|
||||||
virtual void SoundLoop() override;
|
virtual void SoundLoop() override;
|
||||||
virtual void SetVolume(int volume) override;
|
virtual void SetVolume(int volume) override;
|
||||||
|
@ -56,12 +56,9 @@ class OpenALStream final : public SoundStream
|
|||||||
{
|
{
|
||||||
#if defined HAVE_OPENAL && HAVE_OPENAL
|
#if defined HAVE_OPENAL && HAVE_OPENAL
|
||||||
public:
|
public:
|
||||||
OpenALStream(CMixer *mixer)
|
OpenALStream() : uiSource(0)
|
||||||
: SoundStream(mixer)
|
{
|
||||||
, uiSource(0)
|
}
|
||||||
{}
|
|
||||||
|
|
||||||
virtual ~OpenALStream() {}
|
|
||||||
|
|
||||||
virtual bool Start() override;
|
virtual bool Start() override;
|
||||||
virtual void SoundLoop() override;
|
virtual void SoundLoop() override;
|
||||||
@ -84,10 +81,5 @@ private:
|
|||||||
ALfloat fVolume;
|
ALfloat fVolume;
|
||||||
|
|
||||||
u8 numBuffers;
|
u8 numBuffers;
|
||||||
#else
|
|
||||||
public:
|
|
||||||
OpenALStream(CMixer *mixer)
|
|
||||||
: SoundStream(mixer)
|
|
||||||
{}
|
|
||||||
#endif // HAVE_OPENAL
|
#endif // HAVE_OPENAL
|
||||||
};
|
};
|
||||||
|
@ -102,7 +102,7 @@ bool OpenSLESStream::Start()
|
|||||||
|
|
||||||
// Render and enqueue a first buffer.
|
// Render and enqueue a first buffer.
|
||||||
curBuffer ^= 1;
|
curBuffer ^= 1;
|
||||||
g_mixer = m_mixer;
|
g_mixer = m_mixer.get();
|
||||||
|
|
||||||
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[0], sizeof(buffer[0]));
|
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[0], sizeof(buffer[0]));
|
||||||
if (SL_RESULT_SUCCESS != result)
|
if (SL_RESULT_SUCCESS != result)
|
||||||
|
@ -13,15 +13,6 @@ class OpenSLESStream final : public SoundStream
|
|||||||
{
|
{
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
public:
|
public:
|
||||||
OpenSLESStream(CMixer *mixer)
|
|
||||||
: SoundStream(mixer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~OpenSLESStream()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool Start();
|
virtual bool Start();
|
||||||
virtual void Stop();
|
virtual void Stop();
|
||||||
static bool isValid() { return true; }
|
static bool isValid() { return true; }
|
||||||
@ -29,11 +20,5 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
Common::Event soundSyncEvent;
|
Common::Event soundSyncEvent;
|
||||||
#else
|
|
||||||
public:
|
|
||||||
OpenSLESStream(CMixer *mixer)
|
|
||||||
: SoundStream(mixer)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif // HAVE_OPENSL
|
#endif // HAVE_OPENSL
|
||||||
};
|
};
|
||||||
|
@ -13,9 +13,8 @@ namespace
|
|||||||
const size_t BUFFER_SAMPLES = 512; // ~10 ms - needs to be at least 240 for surround
|
const size_t BUFFER_SAMPLES = 512; // ~10 ms - needs to be at least 240 for surround
|
||||||
}
|
}
|
||||||
|
|
||||||
PulseAudio::PulseAudio(CMixer *mixer)
|
PulseAudio::PulseAudio()
|
||||||
: SoundStream(mixer)
|
: m_thread()
|
||||||
, m_thread()
|
|
||||||
, m_run_thread()
|
, m_run_thread()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ class PulseAudio final : public SoundStream
|
|||||||
{
|
{
|
||||||
#if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO
|
#if defined(HAVE_PULSEAUDIO) && HAVE_PULSEAUDIO
|
||||||
public:
|
public:
|
||||||
PulseAudio(CMixer *mixer);
|
PulseAudio();
|
||||||
|
|
||||||
virtual bool Start() override;
|
virtual bool Start() override;
|
||||||
virtual void Stop() override;
|
virtual void Stop() override;
|
||||||
@ -56,8 +56,5 @@ private:
|
|||||||
pa_context *m_pa_ctx;
|
pa_context *m_pa_ctx;
|
||||||
pa_stream *m_pa_s;
|
pa_stream *m_pa_s;
|
||||||
pa_buffer_attr m_pa_ba;
|
pa_buffer_attr m_pa_ba;
|
||||||
#else
|
|
||||||
public:
|
|
||||||
PulseAudio(CMixer *mixer) : SoundStream(mixer) {}
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "AudioCommon/Mixer.h"
|
#include "AudioCommon/Mixer.h"
|
||||||
#include "AudioCommon/WaveFile.h"
|
#include "AudioCommon/WaveFile.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
@ -11,17 +13,17 @@
|
|||||||
class SoundStream
|
class SoundStream
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CMixer* m_mixer;
|
std::unique_ptr<CMixer> m_mixer;
|
||||||
bool m_logAudio;
|
bool m_logAudio;
|
||||||
WaveFileWriter g_wave_writer;
|
WaveFileWriter g_wave_writer;
|
||||||
bool m_muted;
|
bool m_muted;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SoundStream(CMixer* mixer) : m_mixer(mixer), m_logAudio(false), m_muted(false) {}
|
SoundStream() : m_mixer(new CMixer(48000)), m_logAudio(false), m_muted(false) {}
|
||||||
virtual ~SoundStream() { delete m_mixer; }
|
virtual ~SoundStream() { }
|
||||||
|
|
||||||
static bool isValid() { return false; }
|
static bool isValid() { return false; }
|
||||||
virtual CMixer* GetMixer() const { return m_mixer; }
|
CMixer* 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() {}
|
||||||
|
@ -155,9 +155,8 @@ bool XAudio2::InitLibrary()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
XAudio2::XAudio2(CMixer *mixer)
|
XAudio2::XAudio2()
|
||||||
: SoundStream(mixer)
|
: m_mastering_voice(nullptr)
|
||||||
, m_mastering_voice(nullptr)
|
|
||||||
, m_volume(1.0f)
|
, m_volume(1.0f)
|
||||||
, m_cleanup_com(SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
|
, m_cleanup_com(SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
|
||||||
{
|
{
|
||||||
@ -197,7 +196,7 @@ bool XAudio2::Start()
|
|||||||
m_mastering_voice->SetVolume(m_volume);
|
m_mastering_voice->SetVolume(m_volume);
|
||||||
|
|
||||||
m_voice_context = std::unique_ptr<StreamingVoiceContext>
|
m_voice_context = std::unique_ptr<StreamingVoiceContext>
|
||||||
(new StreamingVoiceContext(m_xaudio2.get(), m_mixer, m_sound_sync_event));
|
(new StreamingVoiceContext(m_xaudio2.get(), m_mixer.get(), m_sound_sync_event));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ private:
|
|||||||
static bool InitLibrary();
|
static bool InitLibrary();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XAudio2(CMixer *mixer);
|
XAudio2();
|
||||||
virtual ~XAudio2();
|
virtual ~XAudio2();
|
||||||
|
|
||||||
virtual bool Start();
|
virtual bool Start();
|
||||||
@ -62,13 +62,5 @@ public:
|
|||||||
virtual void SetVolume(int volume);
|
virtual void SetVolume(int volume);
|
||||||
|
|
||||||
static bool isValid() { return InitLibrary(); }
|
static bool isValid() { return InitLibrary(); }
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
public:
|
|
||||||
XAudio2(CMixer *mixer)
|
|
||||||
: SoundStream(mixer)
|
|
||||||
{}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -143,9 +143,8 @@ bool XAudio2_7::InitLibrary()
|
|||||||
return m_xaudio2_dll != nullptr;
|
return m_xaudio2_dll != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
XAudio2_7::XAudio2_7(CMixer *mixer)
|
XAudio2_7::XAudio2_7()
|
||||||
: SoundStream(mixer)
|
: m_mastering_voice(nullptr)
|
||||||
, m_mastering_voice(nullptr)
|
|
||||||
, m_volume(1.0f)
|
, m_volume(1.0f)
|
||||||
, m_cleanup_com(SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
|
, m_cleanup_com(SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
|
||||||
{
|
{
|
||||||
@ -185,7 +184,7 @@ bool XAudio2_7::Start()
|
|||||||
m_mastering_voice->SetVolume(m_volume);
|
m_mastering_voice->SetVolume(m_volume);
|
||||||
|
|
||||||
m_voice_context = std::unique_ptr<StreamingVoiceContext2_7>
|
m_voice_context = std::unique_ptr<StreamingVoiceContext2_7>
|
||||||
(new StreamingVoiceContext2_7(m_xaudio2.get(), m_mixer, m_sound_sync_event));
|
(new StreamingVoiceContext2_7(m_xaudio2.get(), m_mixer.get(), m_sound_sync_event));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ private:
|
|||||||
static bool InitLibrary();
|
static bool InitLibrary();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
XAudio2_7(CMixer *mixer);
|
XAudio2_7();
|
||||||
virtual ~XAudio2_7();
|
virtual ~XAudio2_7();
|
||||||
|
|
||||||
virtual bool Start();
|
virtual bool Start();
|
||||||
@ -69,13 +69,5 @@ public:
|
|||||||
virtual void SetVolume(int volume);
|
virtual void SetVolume(int volume);
|
||||||
|
|
||||||
static bool isValid() { return InitLibrary(); }
|
static bool isValid() { return InitLibrary(); }
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
public:
|
|
||||||
XAudio2_7(CMixer *mixer)
|
|
||||||
: SoundStream(mixer)
|
|
||||||
{}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user