2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-01-17 14:28:09 +00:00
|
|
|
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "AudioCommon/Mixer.h"
|
2019-03-18 11:22:27 +00:00
|
|
|
#include "AudioCommon/Enums.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
|
2017-12-25 23:38:44 +00:00
|
|
|
#include <algorithm>
|
2017-04-10 16:44:17 +00:00
|
|
|
#include <cmath>
|
2015-09-28 15:57:16 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-11-06 08:15:05 +00:00
|
|
|
#include "Common/ChunkFile.h"
|
2016-01-14 06:19:25 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
2017-03-03 19:43:52 +00:00
|
|
|
#include "Common/Swap.h"
|
2019-03-18 11:22:27 +00:00
|
|
|
#include "Core/Config/MainSettings.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
2011-01-28 18:39:30 +00:00
|
|
|
|
2019-03-18 11:22:27 +00:00
|
|
|
static u32 DPL2QualityToFrameBlockSize(AudioCommon::DPL2Quality quality)
|
|
|
|
{
|
|
|
|
switch (quality)
|
|
|
|
{
|
2019-06-15 11:36:47 +00:00
|
|
|
case AudioCommon::DPL2Quality::Lowest:
|
2019-03-18 11:22:27 +00:00
|
|
|
return 512;
|
2019-06-15 11:36:47 +00:00
|
|
|
case AudioCommon::DPL2Quality::Low:
|
2019-03-18 11:22:27 +00:00
|
|
|
return 1024;
|
|
|
|
case AudioCommon::DPL2Quality::Highest:
|
|
|
|
return 4096;
|
|
|
|
default:
|
|
|
|
return 2048;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
Mixer::Mixer(unsigned int BackendSampleRate)
|
2017-08-09 19:57:26 +00:00
|
|
|
: m_sampleRate(BackendSampleRate), m_stretcher(BackendSampleRate),
|
2019-03-18 11:22:27 +00:00
|
|
|
m_surround_decoder(BackendSampleRate,
|
|
|
|
DPL2QualityToFrameBlockSize(Config::Get(Config::MAIN_DPL2_QUALITY)))
|
2015-09-26 21:13:07 +00:00
|
|
|
{
|
|
|
|
INFO_LOG(AUDIO_INTERFACE, "Mixer is initialized");
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
Mixer::~Mixer()
|
2016-01-14 05:58:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-06 08:15:05 +00:00
|
|
|
void Mixer::DoState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
m_dma_mixer.DoState(p);
|
|
|
|
m_streaming_mixer.DoState(p);
|
|
|
|
m_wiimote_speaker_mixer.DoState(p);
|
|
|
|
}
|
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
// Executed from sound stream thread
|
2017-06-26 21:41:12 +00:00
|
|
|
unsigned int Mixer::MixerFifo::Mix(short* samples, unsigned int numSamples,
|
|
|
|
bool consider_framelimit)
|
2015-01-30 08:29:49 +00:00
|
|
|
{
|
2015-02-23 17:43:13 +00:00
|
|
|
unsigned int currentSample = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
// Cache access in non-volatile variable
|
|
|
|
// This is the only function changing the read value, so it's safe to
|
|
|
|
// cache it locally although it's written here.
|
|
|
|
// The writing pointer will be modified outside, but it will only increase,
|
|
|
|
// so we will just ignore new written data while interpolating.
|
|
|
|
// Without this cache, the compiler wouldn't be allowed to optimize the
|
|
|
|
// interpolation loop.
|
2015-05-10 03:50:45 +00:00
|
|
|
u32 indexR = m_indexR.load();
|
|
|
|
u32 indexW = m_indexW.load();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
// render numleft sample pairs to samples[]
|
|
|
|
// advance indexR with sample position
|
|
|
|
// remember fractional offset
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-12-15 23:10:47 +00:00
|
|
|
float emulationspeed = SConfig::GetInstance().m_EmulationSpeed;
|
2017-04-11 09:07:21 +00:00
|
|
|
float aid_sample_rate = static_cast<float>(m_input_sample_rate);
|
2015-12-15 23:10:47 +00:00
|
|
|
if (consider_framelimit && emulationspeed > 0.0f)
|
2014-02-11 13:53:53 +00:00
|
|
|
{
|
2017-04-11 09:07:21 +00:00
|
|
|
float numLeft = static_cast<float>(((indexW - indexR) & INDEX_MASK) / 2);
|
|
|
|
|
|
|
|
u32 low_waterwark = m_input_sample_rate * SConfig::GetInstance().iTimingVariance / 1000;
|
|
|
|
low_waterwark = std::min(low_waterwark, MAX_SAMPLES / 2);
|
|
|
|
|
|
|
|
m_numLeftI = (numLeft + m_numLeftI * (CONTROL_AVG - 1)) / CONTROL_AVG;
|
|
|
|
float offset = (m_numLeftI - low_waterwark) * CONTROL_FACTOR;
|
|
|
|
if (offset > MAX_FREQ_SHIFT)
|
|
|
|
offset = MAX_FREQ_SHIFT;
|
|
|
|
if (offset < -MAX_FREQ_SHIFT)
|
|
|
|
offset = -MAX_FREQ_SHIFT;
|
|
|
|
|
|
|
|
aid_sample_rate = (aid_sample_rate + offset) * emulationspeed;
|
2014-02-11 13:53:53 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
const u32 ratio = (u32)(65536.0f * aid_sample_rate / (float)m_mixer->m_sampleRate);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-05-10 03:50:45 +00:00
|
|
|
s32 lvolume = m_LVolume.load();
|
|
|
|
s32 rvolume = m_RVolume.load();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
// TODO: consider a higher-quality resampling algorithm.
|
|
|
|
for (; currentSample < numSamples * 2 && ((indexW - indexR) & INDEX_MASK) > 2; currentSample += 2)
|
|
|
|
{
|
|
|
|
u32 indexR2 = indexR + 2; // next sample
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
s16 l1 = Common::swap16(m_buffer[indexR & INDEX_MASK]); // current
|
|
|
|
s16 l2 = Common::swap16(m_buffer[indexR2 & INDEX_MASK]); // next
|
|
|
|
int sampleL = ((l1 << 16) + (l2 - l1) * (u16)m_frac) >> 16;
|
|
|
|
sampleL = (sampleL * lvolume) >> 8;
|
|
|
|
sampleL += samples[currentSample + 1];
|
2017-12-25 23:38:44 +00:00
|
|
|
samples[currentSample + 1] = std::clamp(sampleL, -32767, 32767);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
s16 r1 = Common::swap16(m_buffer[(indexR + 1) & INDEX_MASK]); // current
|
|
|
|
s16 r2 = Common::swap16(m_buffer[(indexR2 + 1) & INDEX_MASK]); // next
|
|
|
|
int sampleR = ((r1 << 16) + (r2 - r1) * (u16)m_frac) >> 16;
|
|
|
|
sampleR = (sampleR * rvolume) >> 8;
|
|
|
|
sampleR += samples[currentSample];
|
2017-12-25 23:38:44 +00:00
|
|
|
samples[currentSample] = std::clamp(sampleR, -32767, 32767);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
m_frac += ratio;
|
|
|
|
indexR += 2 * (u16)(m_frac >> 16);
|
|
|
|
m_frac &= 0xffff;
|
2009-12-23 15:34:14 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-10 15:58:55 +00:00
|
|
|
// Actual number of samples written to the buffer without padding.
|
|
|
|
unsigned int actual_sample_count = currentSample / 2;
|
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
// Padding
|
|
|
|
short s[2];
|
|
|
|
s[0] = Common::swap16(m_buffer[(indexR - 1) & INDEX_MASK]);
|
|
|
|
s[1] = Common::swap16(m_buffer[(indexR - 2) & INDEX_MASK]);
|
|
|
|
s[0] = (s[0] * rvolume) >> 8;
|
|
|
|
s[1] = (s[1] * lvolume) >> 8;
|
|
|
|
for (; currentSample < numSamples * 2; currentSample += 2)
|
2011-03-12 22:02:46 +00:00
|
|
|
{
|
2017-12-25 23:38:44 +00:00
|
|
|
int sampleR = std::clamp(s[0] + samples[currentSample + 0], -32767, 32767);
|
|
|
|
int sampleL = std::clamp(s[1] + samples[currentSample + 1], -32767, 32767);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-09-12 03:43:17 +00:00
|
|
|
samples[currentSample + 0] = sampleR;
|
2015-02-23 17:43:13 +00:00
|
|
|
samples[currentSample + 1] = sampleL;
|
2011-03-12 22:02:46 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
// Flush cached variable
|
2015-05-10 03:50:45 +00:00
|
|
|
m_indexR.store(indexR);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-04-10 15:58:55 +00:00
|
|
|
return actual_sample_count;
|
2009-12-23 15:34:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
unsigned int Mixer::Mix(short* samples, unsigned int num_samples)
|
2014-04-11 01:28:19 +00:00
|
|
|
{
|
|
|
|
if (!samples)
|
|
|
|
return 0;
|
2009-12-23 15:34:14 +00:00
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
memset(samples, 0, num_samples * 2 * sizeof(short));
|
2014-04-11 01:28:19 +00:00
|
|
|
|
2017-04-11 11:41:35 +00:00
|
|
|
if (SConfig::GetInstance().m_audio_stretch)
|
|
|
|
{
|
2017-04-12 11:56:07 +00:00
|
|
|
unsigned int available_samples =
|
|
|
|
std::min(m_dma_mixer.AvailableSamples(), m_streaming_mixer.AvailableSamples());
|
2017-04-10 16:44:17 +00:00
|
|
|
|
2017-04-24 02:11:43 +00:00
|
|
|
m_scratch_buffer.fill(0);
|
2017-04-12 11:56:07 +00:00
|
|
|
|
2017-04-24 02:11:43 +00:00
|
|
|
m_dma_mixer.Mix(m_scratch_buffer.data(), available_samples, false);
|
|
|
|
m_streaming_mixer.Mix(m_scratch_buffer.data(), available_samples, false);
|
|
|
|
m_wiimote_speaker_mixer.Mix(m_scratch_buffer.data(), available_samples, false);
|
2017-04-10 16:56:24 +00:00
|
|
|
|
2017-04-11 11:41:35 +00:00
|
|
|
if (!m_is_stretching)
|
|
|
|
{
|
2017-04-24 02:08:33 +00:00
|
|
|
m_stretcher.Clear();
|
2017-04-11 11:41:35 +00:00
|
|
|
m_is_stretching = true;
|
|
|
|
}
|
2017-04-24 02:11:43 +00:00
|
|
|
m_stretcher.ProcessSamples(m_scratch_buffer.data(), available_samples, num_samples);
|
|
|
|
m_stretcher.GetStretchedSamples(samples, num_samples);
|
2017-04-10 16:56:24 +00:00
|
|
|
}
|
2017-04-11 11:41:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dma_mixer.Mix(samples, num_samples, true);
|
|
|
|
m_streaming_mixer.Mix(samples, num_samples, true);
|
|
|
|
m_wiimote_speaker_mixer.Mix(samples, num_samples, true);
|
|
|
|
m_is_stretching = false;
|
|
|
|
}
|
2017-04-10 16:44:17 +00:00
|
|
|
|
2014-04-11 01:28:19 +00:00
|
|
|
return num_samples;
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
unsigned int Mixer::MixSurround(float* samples, unsigned int num_samples)
|
2017-04-24 01:05:21 +00:00
|
|
|
{
|
|
|
|
if (!num_samples)
|
|
|
|
return 0;
|
|
|
|
|
2017-08-09 19:57:26 +00:00
|
|
|
memset(samples, 0, num_samples * SURROUND_CHANNELS * sizeof(float));
|
2017-04-24 01:05:21 +00:00
|
|
|
|
2017-08-09 19:57:26 +00:00
|
|
|
size_t needed_frames = m_surround_decoder.QueryFramesNeededForSurroundOutput(num_samples);
|
|
|
|
|
|
|
|
// Mix() may also use m_scratch_buffer internally, but is safe because it alternates reads
|
|
|
|
// and writes.
|
|
|
|
size_t available_frames = Mix(m_scratch_buffer.data(), static_cast<u32>(needed_frames));
|
|
|
|
if (available_frames != needed_frames)
|
2017-04-24 01:05:21 +00:00
|
|
|
{
|
2017-08-09 19:57:26 +00:00
|
|
|
ERROR_LOG(AUDIO, "Error decoding surround frames.");
|
|
|
|
return 0;
|
2017-04-24 01:05:21 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 19:57:26 +00:00
|
|
|
m_surround_decoder.PutFrames(m_scratch_buffer.data(), needed_frames);
|
|
|
|
m_surround_decoder.ReceiveFrames(samples, num_samples);
|
2017-04-24 01:05:21 +00:00
|
|
|
|
2017-08-09 19:57:26 +00:00
|
|
|
return num_samples;
|
2017-04-24 01:05:21 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::MixerFifo::PushSamples(const short* samples, unsigned int num_samples)
|
2009-12-23 15:34:14 +00:00
|
|
|
{
|
2013-07-11 19:22:38 +00:00
|
|
|
// Cache access in non-volatile variable
|
|
|
|
// indexR isn't allowed to cache in the audio throttling loop as it
|
|
|
|
// needs to get updates to not deadlock.
|
2015-05-10 03:50:45 +00:00
|
|
|
u32 indexW = m_indexW.load();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-12-23 15:34:14 +00:00
|
|
|
// Check if we have enough free space
|
2013-07-11 19:22:38 +00:00
|
|
|
// indexW == m_indexR results in empty buffer, so indexR must always be smaller than indexW
|
2015-05-10 03:50:45 +00:00
|
|
|
if (num_samples * 2 + ((indexW - m_indexR.load()) & INDEX_MASK) >= MAX_SAMPLES * 2)
|
2009-12-23 15:34:14 +00:00
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2009-12-23 15:34:14 +00:00
|
|
|
// AyuanX: Actual re-sampling work has been moved to sound thread
|
2009-12-25 11:59:04 +00:00
|
|
|
// to alleviate the workload on main thread
|
2015-02-23 17:43:13 +00:00
|
|
|
// and we simply store raw data here to make fast mem copy
|
|
|
|
int over_bytes = num_samples * 4 - (MAX_SAMPLES * 2 - (indexW & INDEX_MASK)) * sizeof(short);
|
|
|
|
if (over_bytes > 0)
|
|
|
|
{
|
|
|
|
memcpy(&m_buffer[indexW & INDEX_MASK], samples, num_samples * 4 - over_bytes);
|
|
|
|
memcpy(&m_buffer[0], samples + (num_samples * 4 - over_bytes) / sizeof(short), over_bytes);
|
|
|
|
}
|
|
|
|
else
|
2009-12-23 15:34:14 +00:00
|
|
|
{
|
2015-02-23 17:43:13 +00:00
|
|
|
memcpy(&m_buffer[indexW & INDEX_MASK], samples, num_samples * 4);
|
2009-12-23 15:34:14 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-05-10 03:50:45 +00:00
|
|
|
m_indexW.fetch_add(num_samples * 2);
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-12-20 02:23:26 +00:00
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::PushSamples(const short* samples, unsigned int num_samples)
|
2014-04-11 01:28:19 +00:00
|
|
|
{
|
|
|
|
m_dma_mixer.PushSamples(samples, num_samples);
|
2016-06-11 22:52:45 +00:00
|
|
|
int sample_rate = m_dma_mixer.GetInputSampleRate();
|
2014-10-04 07:28:01 +00:00
|
|
|
if (m_log_dsp_audio)
|
2016-06-11 22:52:45 +00:00
|
|
|
m_wave_writer_dsp.AddStereoSamplesBE(samples, num_samples, sample_rate);
|
2014-04-11 01:28:19 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::PushStreamingSamples(const short* samples, unsigned int num_samples)
|
2014-04-11 01:28:19 +00:00
|
|
|
{
|
|
|
|
m_streaming_mixer.PushSamples(samples, num_samples);
|
2016-06-11 22:52:45 +00:00
|
|
|
int sample_rate = m_streaming_mixer.GetInputSampleRate();
|
2014-10-04 07:28:01 +00:00
|
|
|
if (m_log_dtk_audio)
|
2016-06-11 22:52:45 +00:00
|
|
|
m_wave_writer_dtk.AddStereoSamplesBE(samples, num_samples, sample_rate);
|
2014-04-11 01:28:19 +00:00
|
|
|
}
|
2014-06-26 23:15:18 +00:00
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::PushWiimoteSpeakerSamples(const short* samples, unsigned int num_samples,
|
|
|
|
unsigned int sample_rate)
|
2014-09-05 12:32:48 +00:00
|
|
|
{
|
2015-02-23 17:43:13 +00:00
|
|
|
short samples_stereo[MAX_SAMPLES * 2];
|
2014-09-05 12:32:48 +00:00
|
|
|
|
|
|
|
if (num_samples < MAX_SAMPLES)
|
|
|
|
{
|
|
|
|
m_wiimote_speaker_mixer.SetInputSampleRate(sample_rate);
|
|
|
|
|
2015-02-23 17:43:13 +00:00
|
|
|
for (unsigned int i = 0; i < num_samples; ++i)
|
2014-09-05 12:32:48 +00:00
|
|
|
{
|
2014-09-05 15:23:54 +00:00
|
|
|
samples_stereo[i * 2] = Common::swap16(samples[i]);
|
|
|
|
samples_stereo[i * 2 + 1] = Common::swap16(samples[i]);
|
2014-09-05 12:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_wiimote_speaker_mixer.PushSamples(samples_stereo, num_samples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::SetDMAInputSampleRate(unsigned int rate)
|
2014-07-24 03:20:19 +00:00
|
|
|
{
|
|
|
|
m_dma_mixer.SetInputSampleRate(rate);
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::SetStreamInputSampleRate(unsigned int rate)
|
2014-07-24 03:20:19 +00:00
|
|
|
{
|
|
|
|
m_streaming_mixer.SetInputSampleRate(rate);
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::SetStreamingVolume(unsigned int lvolume, unsigned int rvolume)
|
2014-06-26 23:15:18 +00:00
|
|
|
{
|
|
|
|
m_streaming_mixer.SetVolume(lvolume, rvolume);
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::SetWiimoteSpeakerVolume(unsigned int lvolume, unsigned int rvolume)
|
2014-09-05 12:32:48 +00:00
|
|
|
{
|
|
|
|
m_wiimote_speaker_mixer.SetVolume(lvolume, rvolume);
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::StartLogDTKAudio(const std::string& filename)
|
2015-06-21 01:46:18 +00:00
|
|
|
{
|
|
|
|
if (!m_log_dtk_audio)
|
|
|
|
{
|
2016-12-18 03:35:27 +00:00
|
|
|
bool success = m_wave_writer_dtk.Start(filename, m_streaming_mixer.GetInputSampleRate());
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
m_log_dtk_audio = true;
|
|
|
|
m_wave_writer_dtk.SetSkipSilence(false);
|
|
|
|
NOTICE_LOG(AUDIO, "Starting DTK Audio logging");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_wave_writer_dtk.Stop();
|
|
|
|
NOTICE_LOG(AUDIO, "Unable to start DTK Audio logging");
|
|
|
|
}
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-10 01:36:00 +00:00
|
|
|
WARN_LOG(AUDIO, "DTK Audio logging has already been started");
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::StopLogDTKAudio()
|
2015-06-21 01:46:18 +00:00
|
|
|
{
|
|
|
|
if (m_log_dtk_audio)
|
|
|
|
{
|
|
|
|
m_log_dtk_audio = false;
|
2015-06-21 01:48:50 +00:00
|
|
|
m_wave_writer_dtk.Stop();
|
2015-08-10 01:36:00 +00:00
|
|
|
NOTICE_LOG(AUDIO, "Stopping DTK Audio logging");
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-10 01:36:00 +00:00
|
|
|
WARN_LOG(AUDIO, "DTK Audio logging has already been stopped");
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::StartLogDSPAudio(const std::string& filename)
|
2015-06-21 01:46:18 +00:00
|
|
|
{
|
|
|
|
if (!m_log_dsp_audio)
|
|
|
|
{
|
2016-12-18 03:35:27 +00:00
|
|
|
bool success = m_wave_writer_dsp.Start(filename, m_dma_mixer.GetInputSampleRate());
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
m_log_dsp_audio = true;
|
|
|
|
m_wave_writer_dsp.SetSkipSilence(false);
|
|
|
|
NOTICE_LOG(AUDIO, "Starting DSP Audio logging");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_wave_writer_dsp.Stop();
|
|
|
|
NOTICE_LOG(AUDIO, "Unable to start DSP Audio logging");
|
|
|
|
}
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-10 01:36:00 +00:00
|
|
|
WARN_LOG(AUDIO, "DSP Audio logging has already been started");
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::StopLogDSPAudio()
|
2015-06-21 01:46:18 +00:00
|
|
|
{
|
|
|
|
if (m_log_dsp_audio)
|
|
|
|
{
|
|
|
|
m_log_dsp_audio = false;
|
2015-06-21 01:48:50 +00:00
|
|
|
m_wave_writer_dsp.Stop();
|
2015-08-10 01:36:00 +00:00
|
|
|
NOTICE_LOG(AUDIO, "Stopping DSP Audio logging");
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-08-10 01:36:00 +00:00
|
|
|
WARN_LOG(AUDIO, "DSP Audio logging has already been stopped");
|
2015-06-21 01:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 08:15:05 +00:00
|
|
|
void Mixer::MixerFifo::DoState(PointerWrap& p)
|
|
|
|
{
|
|
|
|
p.Do(m_input_sample_rate);
|
|
|
|
p.Do(m_LVolume);
|
|
|
|
p.Do(m_RVolume);
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::MixerFifo::SetInputSampleRate(unsigned int rate)
|
2014-07-24 03:20:19 +00:00
|
|
|
{
|
|
|
|
m_input_sample_rate = rate;
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
unsigned int Mixer::MixerFifo::GetInputSampleRate() const
|
2016-06-11 22:52:45 +00:00
|
|
|
{
|
|
|
|
return m_input_sample_rate;
|
|
|
|
}
|
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
void Mixer::MixerFifo::SetVolume(unsigned int lvolume, unsigned int rvolume)
|
2014-06-26 23:15:18 +00:00
|
|
|
{
|
2015-05-10 03:50:45 +00:00
|
|
|
m_LVolume.store(lvolume + (lvolume >> 7));
|
|
|
|
m_RVolume.store(rvolume + (rvolume >> 7));
|
2014-06-26 23:15:18 +00:00
|
|
|
}
|
2017-04-11 11:41:35 +00:00
|
|
|
|
2017-06-26 21:41:12 +00:00
|
|
|
unsigned int Mixer::MixerFifo::AvailableSamples() const
|
2017-04-11 11:41:35 +00:00
|
|
|
{
|
|
|
|
unsigned int samples_in_fifo = ((m_indexW.load() - m_indexR.load()) & INDEX_MASK) / 2;
|
|
|
|
if (samples_in_fifo <= 1)
|
2017-06-26 21:41:12 +00:00
|
|
|
return 0; // Mixer::MixerFifo::Mix always keeps one sample in the buffer.
|
2017-04-11 11:41:35 +00:00
|
|
|
return (samples_in_fifo - 1) * m_mixer->m_sampleRate / m_input_sample_rate;
|
|
|
|
}
|