|
|
|
@ -10,12 +10,12 @@
|
|
|
|
|
|
|
|
|
|
namespace AudioCore {
|
|
|
|
|
namespace {
|
|
|
|
|
static constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00;
|
|
|
|
|
static constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL;
|
|
|
|
|
constexpr std::size_t MIX_BUFFER_SIZE = 0x3f00;
|
|
|
|
|
constexpr std::size_t SCALED_MIX_BUFFER_SIZE = MIX_BUFFER_SIZE << 15ULL;
|
|
|
|
|
|
|
|
|
|
template <std::size_t N>
|
|
|
|
|
void ApplyMix(s32* output, const s32* input, s32 gain, s32 sample_count) {
|
|
|
|
|
for (s32 i = 0; i < sample_count; i += N) {
|
|
|
|
|
for (std::size_t i = 0; i < static_cast<std::size_t>(sample_count); i += N) {
|
|
|
|
|
for (std::size_t j = 0; j < N; j++) {
|
|
|
|
|
output[i + j] +=
|
|
|
|
|
static_cast<s32>((static_cast<s64>(input[i + j]) * gain + 0x4000) >> 15);
|
|
|
|
@ -59,13 +59,13 @@ CommandGenerator::CommandGenerator(AudioCommon::AudioRendererParameter& worker_p
|
|
|
|
|
CommandGenerator::~CommandGenerator() = default;
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::ClearMixBuffers() {
|
|
|
|
|
std::memset(mix_buffer.data(), 0, mix_buffer.size() * sizeof(s32));
|
|
|
|
|
std::memset(sample_buffer.data(), 0, sample_buffer.size() * sizeof(s32));
|
|
|
|
|
std::fill(mix_buffer.begin(), mix_buffer.end(), 0);
|
|
|
|
|
std::fill(sample_buffer.begin(), sample_buffer.end(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::GenerateVoiceCommands() {
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio, "(DSP_TRACE) GenerateVoiceCommands");
|
|
|
|
|
LOG_DEBUG(Audio, "(DSP_TRACE) GenerateVoiceCommands");
|
|
|
|
|
}
|
|
|
|
|
// Grab all our voices
|
|
|
|
|
const auto voice_count = voice_context.GetVoiceCount();
|
|
|
|
@ -168,7 +168,9 @@ void CommandGenerator::GenerateFinalMixCommands() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::PreCommand() {
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
if (!dumping_frame) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (std::size_t i = 0; i < splitter_context.GetInfoCount(); i++) {
|
|
|
|
|
const auto& base = splitter_context.GetInfo(i);
|
|
|
|
|
std::string graph = fmt::format("b[{}]", i);
|
|
|
|
@ -177,15 +179,15 @@ void CommandGenerator::PreCommand() {
|
|
|
|
|
graph += fmt::format("->{}", head->GetMixId());
|
|
|
|
|
head = head->GetNextDestination();
|
|
|
|
|
}
|
|
|
|
|
LOG_CRITICAL(Audio, "(DSP_TRACE) SplitterGraph splitter_info={}, {}", i, graph);
|
|
|
|
|
}
|
|
|
|
|
LOG_DEBUG(Audio, "(DSP_TRACE) SplitterGraph splitter_info={}, {}", i, graph);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::PostCommand() {
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
dumping_frame = false;
|
|
|
|
|
if (!dumping_frame) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dumping_frame = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
|
|
|
|
@ -194,14 +196,17 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
|
|
|
|
|
const auto depop = in_params.should_depop;
|
|
|
|
|
|
|
|
|
|
if (in_params.mix_id != AudioCommon::NO_MIX) {
|
|
|
|
|
auto& mix_info = mix_context.GetInfo(in_params.mix_id);
|
|
|
|
|
[[maybe_unused]] auto& mix_info = mix_context.GetInfo(in_params.mix_id);
|
|
|
|
|
// mix_info.
|
|
|
|
|
// TODO(ogniK): Depop to destination mix
|
|
|
|
|
} else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) {
|
|
|
|
|
// TODO(ogniK): Depop to splitter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!depop) {
|
|
|
|
|
if (depop) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (in_params.sample_format) {
|
|
|
|
|
case SampleFormat::Pcm16:
|
|
|
|
|
DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel,
|
|
|
|
@ -217,7 +222,6 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
|
|
|
|
|
default:
|
|
|
|
|
UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info,
|
|
|
|
@ -233,8 +237,7 @@ void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voic
|
|
|
|
|
|
|
|
|
|
// Reinitialize our biquad filter state if it was enabled previously
|
|
|
|
|
if (!in_params.was_biquad_filter_enabled[i]) {
|
|
|
|
|
std::memset(dsp_state.biquad_filter_state.data(), 0,
|
|
|
|
|
dsp_state.biquad_filter_state.size() * sizeof(s64));
|
|
|
|
|
dsp_state.biquad_filter_state.fill(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate biquad filter
|
|
|
|
@ -248,7 +251,7 @@ void AudioCore::CommandGenerator::GenerateBiquadFilterCommand(
|
|
|
|
|
s32 mix_buffer, const BiquadFilterParameter& params, std::array<s64, 2>& state,
|
|
|
|
|
std::size_t input_offset, std::size_t output_offset, s32 sample_count, s32 node_id) {
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio,
|
|
|
|
|
LOG_DEBUG(Audio,
|
|
|
|
|
"(DSP_TRACE) GenerateBiquadFilterCommand node_id={}, "
|
|
|
|
|
"input_mix_buffer={}, output_mix_buffer={}",
|
|
|
|
|
node_id, input_offset, output_offset);
|
|
|
|
@ -257,30 +260,25 @@ void AudioCore::CommandGenerator::GenerateBiquadFilterCommand(
|
|
|
|
|
auto* output = GetMixBuffer(output_offset);
|
|
|
|
|
|
|
|
|
|
// Biquad filter parameters
|
|
|
|
|
const auto n0 = params.numerator[0];
|
|
|
|
|
const auto n1 = params.numerator[1];
|
|
|
|
|
const auto n2 = params.numerator[2];
|
|
|
|
|
const auto d0 = params.denominator[0];
|
|
|
|
|
const auto d1 = params.denominator[1];
|
|
|
|
|
const auto [n0, n1, n2] = params.numerator;
|
|
|
|
|
const auto [d0, d1] = params.denominator;
|
|
|
|
|
|
|
|
|
|
// Biquad filter states
|
|
|
|
|
auto s0 = state[0];
|
|
|
|
|
auto s1 = state[1];
|
|
|
|
|
auto [s0, s1] = state;
|
|
|
|
|
|
|
|
|
|
constexpr s64 MIN = std::numeric_limits<int32_t>::min();
|
|
|
|
|
constexpr s64 MAX = std::numeric_limits<int32_t>::max();
|
|
|
|
|
constexpr s64 int32_min = std::numeric_limits<s32>::min();
|
|
|
|
|
constexpr s64 int32_max = std::numeric_limits<s32>::max();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sample_count; ++i) {
|
|
|
|
|
const auto sample = static_cast<int64_t>(input[i]);
|
|
|
|
|
const auto sample = static_cast<s64>(input[i]);
|
|
|
|
|
const auto f = (sample * n0 + s0 + 0x4000) >> 15;
|
|
|
|
|
const auto y = std::clamp(f, MIN, MAX);
|
|
|
|
|
const auto y = std::clamp(f, int32_min, int32_max);
|
|
|
|
|
s0 = sample * n1 + y * d0 + s1;
|
|
|
|
|
s1 = sample * n2 + y * d1;
|
|
|
|
|
output[i] = static_cast<s32>(y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state[0] = s0;
|
|
|
|
|
state[1] = s1;
|
|
|
|
|
state = {s0, s1};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter_id, s32 index) {
|
|
|
|
@ -298,11 +296,11 @@ void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float curren
|
|
|
|
|
static_cast<float>(worker_params.sample_count));
|
|
|
|
|
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio,
|
|
|
|
|
LOG_DEBUG(Audio,
|
|
|
|
|
"(DSP_TRACE) GenerateVolumeRampCommand node_id={}, input={}, output={}, "
|
|
|
|
|
"last_volume={}, current_volume={}",
|
|
|
|
|
node_id, GetMixChannelBufferOffset(channel),
|
|
|
|
|
GetMixChannelBufferOffset(channel), last_volume, current_volume);
|
|
|
|
|
node_id, GetMixChannelBufferOffset(channel), GetMixChannelBufferOffset(channel),
|
|
|
|
|
last_volume, current_volume);
|
|
|
|
|
}
|
|
|
|
|
// Apply generic gain on samples
|
|
|
|
|
ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta,
|
|
|
|
@ -320,7 +318,7 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume
|
|
|
|
|
static_cast<float>(worker_params.sample_count);
|
|
|
|
|
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio,
|
|
|
|
|
LOG_DEBUG(Audio,
|
|
|
|
|
"(DSP_TRACE) GenerateVoiceMixCommand node_id={}, input={}, "
|
|
|
|
|
"output={}, last_volume={}, current_volume={}",
|
|
|
|
|
node_id, voice_index, mix_buffer_offset + i, last_mix_volumes[i],
|
|
|
|
@ -338,7 +336,7 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) {
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio, "(DSP_TRACE) GenerateSubMixCommand");
|
|
|
|
|
LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand");
|
|
|
|
|
}
|
|
|
|
|
// TODO(ogniK): Depop
|
|
|
|
|
// TODO(ogniK): Effects
|
|
|
|
@ -391,7 +389,7 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t
|
|
|
|
|
float volume, s32 node_id) {
|
|
|
|
|
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio,
|
|
|
|
|
LOG_DEBUG(Audio,
|
|
|
|
|
"(DSP_TRACE) GenerateMixCommand node_id={}, input={}, output={}, volume={}",
|
|
|
|
|
node_id, input_offset, output_offset, volume);
|
|
|
|
|
}
|
|
|
|
@ -412,7 +410,7 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t
|
|
|
|
|
|
|
|
|
|
void CommandGenerator::GenerateFinalMixCommand() {
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio, "(DSP_TRACE) GenerateFinalMixCommand");
|
|
|
|
|
LOG_DEBUG(Audio, "(DSP_TRACE) GenerateFinalMixCommand");
|
|
|
|
|
}
|
|
|
|
|
// TODO(ogniK): Depop
|
|
|
|
|
// TODO(ogniK): Effects
|
|
|
|
@ -421,7 +419,7 @@ void CommandGenerator::GenerateFinalMixCommand() {
|
|
|
|
|
for (s32 i = 0; i < in_params.buffer_count; i++) {
|
|
|
|
|
const s32 gain = static_cast<s32>(in_params.volume * 32768.0f);
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(
|
|
|
|
|
LOG_DEBUG(
|
|
|
|
|
Audio,
|
|
|
|
|
"(DSP_TRACE) ApplyGainWithoutDelta node_id={}, input={}, output={}, volume={}",
|
|
|
|
|
in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i,
|
|
|
|
@ -544,7 +542,7 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
|
|
|
|
|
s32 node_id) {
|
|
|
|
|
auto& in_params = voice_info.GetInParams();
|
|
|
|
|
if (dumping_frame) {
|
|
|
|
|
LOG_CRITICAL(Audio,
|
|
|
|
|
LOG_DEBUG(Audio,
|
|
|
|
|
"(DSP_TRACE) DecodeFromWaveBuffers, node_id={}, channel={}, "
|
|
|
|
|
"format={}, sample_count={}, sample_rate={}, mix_id={}, splitter_id={}",
|
|
|
|
|
node_id, channel, in_params.sample_format, sample_count, in_params.sample_rate,
|
|
|
|
@ -649,10 +647,11 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
|
|
|
|
|
|
|
|
|
|
if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) {
|
|
|
|
|
// No need to resample
|
|
|
|
|
memcpy(output, sample_buffer.data(), samples_read * sizeof(s32));
|
|
|
|
|
std::memcpy(output, sample_buffer.data(), samples_read * sizeof(s32));
|
|
|
|
|
} else {
|
|
|
|
|
std::memset(sample_buffer.data() + temp_mix_offset, 0,
|
|
|
|
|
sizeof(s32) * (samples_to_read - samples_read));
|
|
|
|
|
std::fill(sample_buffer.begin() + temp_mix_offset,
|
|
|
|
|
sample_buffer.begin() + temp_mix_offset + (samples_to_read - samples_read),
|
|
|
|
|
0);
|
|
|
|
|
AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction,
|
|
|
|
|
samples_to_output);
|
|
|
|
|
// Resample
|
|
|
|
|