mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 03:35:26 +00:00
AudioCommon: move DPL2 decoding into Mixer
This commit is contained in:
parent
0e6bd74ed6
commit
a4508e85e8
@ -21,29 +21,9 @@ long CubebStream::DataCallback(cubeb_stream* stream, void* user_data, const void
|
|||||||
auto* self = static_cast<CubebStream*>(user_data);
|
auto* self = static_cast<CubebStream*>(user_data);
|
||||||
|
|
||||||
if (self->m_stereo)
|
if (self->m_stereo)
|
||||||
{
|
|
||||||
self->m_mixer->Mix(static_cast<short*>(output_buffer), num_frames);
|
self->m_mixer->Mix(static_cast<short*>(output_buffer), num_frames);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
self->m_mixer->MixSurround(static_cast<float*>(output_buffer), num_frames);
|
||||||
size_t required_capacity = num_frames * 2;
|
|
||||||
if (required_capacity > self->m_short_buffer.capacity() ||
|
|
||||||
required_capacity > self->m_floatstereo_buffer.capacity())
|
|
||||||
{
|
|
||||||
INFO_LOG(AUDIO, "Expanding conversion buffers size: %li frames", num_frames);
|
|
||||||
self->m_short_buffer.reserve(required_capacity);
|
|
||||||
self->m_floatstereo_buffer.reserve(required_capacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
self->m_mixer->Mix(self->m_short_buffer.data(), num_frames);
|
|
||||||
|
|
||||||
// s16 to float
|
|
||||||
for (size_t i = 0; i < static_cast<size_t>(num_frames) * 2; ++i)
|
|
||||||
self->m_floatstereo_buffer[i] = self->m_short_buffer[i] / static_cast<float>(1 << 15);
|
|
||||||
|
|
||||||
// DPL2Decode output: LEFTFRONT, RIGHTFRONT, CENTREFRONT, (sub), LEFTREAR, RIGHTREAR
|
|
||||||
DPL2Decode(self->m_floatstereo_buffer.data(), num_frames, static_cast<float*>(output_buffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
return num_frames;
|
return num_frames;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "AudioCommon/DPL2Decoder.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/MathUtil.h"
|
#include "Common/MathUtil.h"
|
||||||
@ -25,6 +26,8 @@ CMixer::CMixer(unsigned int BackendSampleRate) : m_sampleRate(BackendSampleRate)
|
|||||||
m_sound_touch.setSetting(SETTING_SEQUENCE_MS, 62);
|
m_sound_touch.setSetting(SETTING_SEQUENCE_MS, 62);
|
||||||
m_sound_touch.setSetting(SETTING_SEEKWINDOW_MS, 28);
|
m_sound_touch.setSetting(SETTING_SEEKWINDOW_MS, 28);
|
||||||
m_sound_touch.setSetting(SETTING_OVERLAP_MS, 8);
|
m_sound_touch.setSetting(SETTING_OVERLAP_MS, 8);
|
||||||
|
|
||||||
|
DPL2Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
CMixer::~CMixer()
|
CMixer::~CMixer()
|
||||||
@ -159,6 +162,25 @@ 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)
|
||||||
|
{
|
||||||
|
if (!num_samples)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memset(samples, 0, num_samples * 6 * sizeof(float));
|
||||||
|
|
||||||
|
unsigned int available_samples = Mix(m_stretch_buffer.data(), num_samples);
|
||||||
|
for (size_t i = 0; i < static_cast<size_t>(available_samples) * 2; ++i)
|
||||||
|
{
|
||||||
|
m_float_conversion_buffer[i] =
|
||||||
|
m_stretch_buffer[i] / static_cast<float>(std::numeric_limits<short>::max());
|
||||||
|
}
|
||||||
|
|
||||||
|
DPL2Decode(m_float_conversion_buffer.data(), available_samples, samples);
|
||||||
|
|
||||||
|
return available_samples;
|
||||||
|
}
|
||||||
|
|
||||||
void CMixer::StretchAudio(const short* in, unsigned int num_in, short* out, unsigned int num_out)
|
void CMixer::StretchAudio(const short* in, unsigned int num_in, short* out, unsigned int num_out)
|
||||||
{
|
{
|
||||||
const double time_delta = static_cast<double>(num_out) / m_sampleRate; // seconds
|
const double time_delta = static_cast<double>(num_out) / m_sampleRate; // seconds
|
||||||
|
@ -21,6 +21,7 @@ public:
|
|||||||
|
|
||||||
// Called from audio threads
|
// Called from audio threads
|
||||||
unsigned int Mix(short* samples, unsigned int numSamples);
|
unsigned int Mix(short* samples, unsigned int numSamples);
|
||||||
|
unsigned int MixSurround(float* samples, unsigned int num_samples);
|
||||||
|
|
||||||
// Called from main thread
|
// Called from main thread
|
||||||
void PushSamples(const short* samples, unsigned int num_samples);
|
void PushSamples(const short* samples, unsigned int num_samples);
|
||||||
@ -87,6 +88,7 @@ private:
|
|||||||
double m_stretch_ratio = 1.0;
|
double m_stretch_ratio = 1.0;
|
||||||
std::array<short, 2> m_last_stretched_sample = {};
|
std::array<short, 2> m_last_stretched_sample = {};
|
||||||
std::array<short, MAX_SAMPLES * 2> m_stretch_buffer;
|
std::array<short, MAX_SAMPLES * 2> m_stretch_buffer;
|
||||||
|
std::array<float, MAX_SAMPLES * 2> m_float_conversion_buffer;
|
||||||
|
|
||||||
WaveFileWriter m_wave_writer_dtk;
|
WaveFileWriter m_wave_writer_dtk;
|
||||||
WaveFileWriter m_wave_writer_dsp;
|
WaveFileWriter m_wave_writer_dsp;
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include "AudioCommon/DPL2Decoder.h"
|
|
||||||
#include "AudioCommon/OpenALStream.h"
|
#include "AudioCommon/OpenALStream.h"
|
||||||
#include "AudioCommon/aldlist.h"
|
#include "AudioCommon/aldlist.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
@ -66,9 +65,6 @@ bool OpenALStream::Start()
|
|||||||
PanicAlertT("OpenAL: can't find sound devices");
|
PanicAlertT("OpenAL: can't find sound devices");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize DPL2 parameters
|
|
||||||
DPL2Reset();
|
|
||||||
|
|
||||||
return bReturn;
|
return bReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,23 +224,18 @@ void OpenALStream::SoundLoop()
|
|||||||
numBuffersQueued -= numBuffersProcessed;
|
numBuffersQueued -= numBuffersProcessed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DPL2 accepts 240 samples minimum (FWRDURATION)
|
|
||||||
unsigned int minSamples = surround_capable ? 240 : 0;
|
|
||||||
|
|
||||||
unsigned int numSamples = OAL_MAX_SAMPLES;
|
unsigned int numSamples = OAL_MAX_SAMPLES;
|
||||||
numSamples = m_mixer->Mix(realtimeBuffer, numSamples);
|
|
||||||
|
|
||||||
// Convert the samples from short to float
|
|
||||||
for (u32 i = 0; i < numSamples * STEREO_CHANNELS; ++i)
|
|
||||||
sampleBuffer[i] = static_cast<float>(realtimeBuffer[i]) / (1 << 15);
|
|
||||||
|
|
||||||
if (numSamples <= minSamples)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (surround_capable)
|
if (surround_capable)
|
||||||
{
|
{
|
||||||
|
// DPL2 accepts 240 samples minimum (FWRDURATION)
|
||||||
|
unsigned int minSamples = 240;
|
||||||
|
|
||||||
float dpl2[OAL_MAX_SAMPLES * OAL_MAX_BUFFERS * SURROUND_CHANNELS];
|
float dpl2[OAL_MAX_SAMPLES * OAL_MAX_BUFFERS * SURROUND_CHANNELS];
|
||||||
DPL2Decode(sampleBuffer, numSamples, dpl2);
|
numSamples = m_mixer->MixSurround(dpl2, numSamples);
|
||||||
|
|
||||||
|
if (numSamples < minSamples)
|
||||||
|
continue;
|
||||||
|
|
||||||
// zero-out the subwoofer channel - DPL2Decode generates a pretty
|
// zero-out the subwoofer channel - DPL2Decode generates a pretty
|
||||||
// good 5.0 but not a good 5.1 output. Sadly there is not a 5.0
|
// good 5.0 but not a good 5.1 output. Sadly there is not a 5.0
|
||||||
@ -311,6 +302,15 @@ void OpenALStream::SoundLoop()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
numSamples = m_mixer->Mix(realtimeBuffer, numSamples);
|
||||||
|
|
||||||
|
// Convert the samples from short to float
|
||||||
|
for (u32 i = 0; i < numSamples * STEREO_CHANNELS; ++i)
|
||||||
|
sampleBuffer[i] = static_cast<float>(realtimeBuffer[i]) / (1 << 15);
|
||||||
|
|
||||||
|
if (!numSamples)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (float32_capable)
|
if (float32_capable)
|
||||||
{
|
{
|
||||||
alBufferData(uiBuffers[nextBuffer], AL_FORMAT_STEREO_FLOAT32, sampleBuffer,
|
alBufferData(uiBuffers[nextBuffer], AL_FORMAT_STEREO_FLOAT32, sampleBuffer,
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "AudioCommon/DPL2Decoder.h"
|
|
||||||
#include "AudioCommon/PulseAudioStream.h"
|
#include "AudioCommon/PulseAudioStream.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
@ -30,9 +29,6 @@ bool PulseAudio::Start()
|
|||||||
m_run_thread.Set();
|
m_run_thread.Set();
|
||||||
m_thread = std::thread(&PulseAudio::SoundLoop, this);
|
m_thread = std::thread(&PulseAudio::SoundLoop, this);
|
||||||
|
|
||||||
// Initialize DPL2 parameters
|
|
||||||
DPL2Reset();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,23 +190,12 @@ void PulseAudio::WriteCallback(pa_stream* s, size_t length)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// get a floating point mix
|
|
||||||
s16 s16buffer_stereo[frames * 2];
|
|
||||||
m_mixer->Mix(s16buffer_stereo, frames); // implicitly mixes to 16-bit stereo
|
|
||||||
|
|
||||||
float floatbuffer_stereo[frames * 2];
|
|
||||||
// s16 to float
|
|
||||||
for (int i = 0; i < frames * 2; ++i)
|
|
||||||
{
|
|
||||||
floatbuffer_stereo[i] = s16buffer_stereo[i] / float(1 << 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_channels == 5) // Extract dpl2/5.0 Surround
|
if (m_channels == 5) // Extract dpl2/5.0 Surround
|
||||||
{
|
{
|
||||||
float floatbuffer_6chan[frames * 6];
|
float floatbuffer_6chan[frames * 6];
|
||||||
// DPL2Decode output: LEFTFRONT, RIGHTFRONT, CENTREFRONT, (sub), LEFTREAR, RIGHTREAR
|
m_mixer->MixSurround(floatbuffer_6chan, frames);
|
||||||
DPL2Decode(floatbuffer_stereo, frames, floatbuffer_6chan);
|
|
||||||
|
|
||||||
|
// DPL2Decode output: LEFTFRONT, RIGHTFRONT, CENTREFRONT, (sub), LEFTREAR, RIGHTREAR
|
||||||
// Discard the subwoofer channel - DPL2Decode generates a pretty
|
// Discard the subwoofer channel - DPL2Decode generates a pretty
|
||||||
// good 5.0 but not a good 5.1 output.
|
// good 5.0 but not a good 5.1 output.
|
||||||
const int dpl2_to_5chan[] = {0, 1, 2, 4, 5};
|
const int dpl2_to_5chan[] = {0, 1, 2, 4, 5};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user