summaryrefslogtreecommitdiffstats
path: root/src/audio_core/command_generator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio_core/command_generator.cpp')
-rw-r--r--src/audio_core/command_generator.cpp212
1 files changed, 120 insertions, 92 deletions
diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp
index fb8700ccf..c0edb625d 100644
--- a/src/audio_core/command_generator.cpp
+++ b/src/audio_core/command_generator.cpp
@@ -15,8 +15,8 @@ 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 (std::size_t i = 0; i < static_cast<std::size_t>(sample_count); i += N) {
+void ApplyMix(s32* output, const s32* input, s32 gain, std::size_t sample_count) {
+ for (std::size_t i = 0; i < 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);
@@ -111,7 +111,8 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) {
const auto channel_count = in_params.channel_count;
for (s32 channel = 0; channel < channel_count; channel++) {
- const auto resource_id = in_params.voice_channel_resource_id[channel];
+ const auto resource_id =
+ static_cast<u32>(in_params.voice_channel_resource_id[static_cast<u32>(channel)]);
auto& dsp_state = voice_context.GetDspSharedState(resource_id);
auto& channel_resource = voice_context.GetChannelResource(resource_id);
@@ -132,14 +133,15 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) {
if (in_params.mix_id != AudioCommon::NO_MIX) {
// If we're using a mix id
- auto& mix_info = mix_context.GetInfo(in_params.mix_id);
+ auto& mix_info = mix_context.GetInfo(static_cast<u32>(in_params.mix_id));
const auto& dest_mix_params = mix_info.GetInParams();
// Voice Mixing
GenerateVoiceMixCommand(
channel_resource.GetCurrentMixVolume(), channel_resource.GetLastMixVolume(),
- dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count,
- worker_params.mix_buffer_count + channel, in_params.node_id);
+ dsp_state, static_cast<u32>(dest_mix_params.buffer_offset),
+ static_cast<u32>(dest_mix_params.buffer_count),
+ worker_params.mix_buffer_count + static_cast<u32>(channel), in_params.node_id);
// Update last mix volumes
channel_resource.UpdateLastMixVolumes();
@@ -156,12 +158,15 @@ void CommandGenerator::GenerateVoiceCommand(ServerVoiceInfo& voice_info) {
continue;
}
- const auto& mix_info = mix_context.GetInfo(destination_data->GetMixId());
+ const auto& mix_info =
+ mix_context.GetInfo(static_cast<u32>(destination_data->GetMixId()));
const auto& dest_mix_params = mix_info.GetInParams();
GenerateVoiceMixCommand(
destination_data->CurrentMixVolumes(), destination_data->LastMixVolumes(),
- dsp_state, dest_mix_params.buffer_offset, dest_mix_params.buffer_count,
- worker_params.mix_buffer_count + channel, in_params.node_id);
+ dsp_state, static_cast<u32>(dest_mix_params.buffer_offset),
+ static_cast<u32>(dest_mix_params.buffer_count),
+ worker_params.mix_buffer_count + static_cast<u32>(channel),
+ in_params.node_id);
destination_data->MarkDirty();
}
}
@@ -219,9 +224,10 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
if (depop) {
if (in_params.mix_id != AudioCommon::NO_MIX) {
- auto& mix_info = mix_context.GetInfo(in_params.mix_id);
+ auto& mix_info = mix_context.GetInfo(static_cast<u32>(in_params.mix_id));
const auto& mix_in = mix_info.GetInParams();
- GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset);
+ GenerateDepopPrepareCommand(dsp_state, static_cast<u32>(mix_in.buffer_count),
+ static_cast<u32>(mix_in.buffer_offset));
} else if (in_params.splitter_info_id != AudioCommon::NO_SPLITTER) {
s32 index{};
while (const auto* destination =
@@ -229,23 +235,24 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
if (!destination->IsConfigured()) {
continue;
}
- auto& mix_info = mix_context.GetInfo(destination->GetMixId());
+ auto& mix_info = mix_context.GetInfo(static_cast<u32>(destination->GetMixId()));
const auto& mix_in = mix_info.GetInParams();
- GenerateDepopPrepareCommand(dsp_state, mix_in.buffer_count, mix_in.buffer_offset);
+ GenerateDepopPrepareCommand(dsp_state, static_cast<u32>(mix_in.buffer_count),
+ static_cast<u32>(mix_in.buffer_offset));
}
}
} else {
switch (in_params.sample_format) {
case SampleFormat::Pcm16:
DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel,
- worker_params.sample_rate, worker_params.sample_count,
- in_params.node_id);
+ static_cast<s32>(worker_params.sample_rate),
+ static_cast<s32>(worker_params.sample_count), in_params.node_id);
break;
case SampleFormat::Adpcm:
ASSERT(channel == 0 && in_params.channel_count == 1);
DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(0), dsp_state, 0,
- worker_params.sample_rate, worker_params.sample_count,
- in_params.node_id);
+ static_cast<s32>(worker_params.sample_rate),
+ static_cast<s32>(worker_params.sample_count), in_params.node_id);
break;
default:
UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format);
@@ -255,7 +262,7 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
void CommandGenerator::GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info,
VoiceState& dsp_state,
- s32 mix_buffer_count, s32 channel) {
+ u32 mix_buffer_count, s32 channel) {
for (std::size_t i = 0; i < AudioCommon::MAX_BIQUAD_FILTERS; i++) {
const auto& in_params = voice_info.GetInParams();
auto& biquad_filter = in_params.biquad_filter[i];
@@ -335,8 +342,8 @@ void CommandGenerator::GenerateDepopForMixBuffersCommand(std::size_t mix_buffer_
continue;
}
- depop_buffer[i] =
- ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta, worker_params.sample_count);
+ depop_buffer[i] = ApplyMixDepop(GetMixBuffer(i), depop_buffer[i], delta,
+ static_cast<s32>(worker_params.sample_count));
}
}
@@ -348,7 +355,7 @@ void CommandGenerator::GenerateEffectCommand(ServerMixInfo& mix_info) {
if (index == AudioCommon::NO_EFFECT_ORDER) {
break;
}
- auto* info = effect_context.GetInfo(index);
+ auto* info = effect_context.GetInfo(static_cast<u32>(index));
const auto type = info->GetType();
// TODO(ogniK): Finish remaining effects
@@ -377,11 +384,11 @@ void CommandGenerator::GenerateI3dl2ReverbEffectCommand(s32 mix_buffer_offset, E
}
const auto& params = dynamic_cast<EffectI3dl2Reverb*>(info)->GetParams();
const auto channel_count = params.channel_count;
- for (s32 i = 0; i < channel_count; i++) {
+ for (size_t i = 0; i < channel_count; i++) {
// TODO(ogniK): Actually implement reverb
if (params.input[i] != params.output[i]) {
- const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]);
- auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]);
+ const auto* input = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.input[i]));
+ auto* output = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.output[i]));
ApplyMix<1>(output, input, 32768, worker_params.sample_count);
}
}
@@ -392,13 +399,14 @@ void CommandGenerator::GenerateBiquadFilterEffectCommand(s32 mix_buffer_offset,
if (!enabled) {
return;
}
+
const auto& params = dynamic_cast<EffectBiquadFilter*>(info)->GetParams();
- const auto channel_count = params.channel_count;
- for (s32 i = 0; i < channel_count; i++) {
+ const auto channel_count = static_cast<u32>(params.channel_count);
+ for (size_t i = 0; i < channel_count; i++) {
// TODO(ogniK): Actually implement biquad filter
if (params.input[i] != params.output[i]) {
- const auto* input = GetMixBuffer(mix_buffer_offset + params.input[i]);
- auto* output = GetMixBuffer(mix_buffer_offset + params.output[i]);
+ const auto* input = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.input[i]));
+ auto* output = GetMixBuffer(static_cast<u32>(mix_buffer_offset + params.output[i]));
ApplyMix<1>(output, input, 32768, worker_params.sample_count);
}
}
@@ -425,26 +433,30 @@ void CommandGenerator::GenerateAuxCommand(s32 mix_buffer_offset, EffectBase* inf
memory.ReadBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP));
memory.ReadBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP));
- WriteAuxBuffer(send_info, aux->GetSendBuffer(), params.sample_count,
- GetMixBuffer(input_index), worker_params.sample_count, offset,
- write_count);
+ WriteAuxBuffer(send_info, aux->GetSendBuffer(),
+ static_cast<u32>(params.sample_count),
+ GetMixBuffer(static_cast<u32>(input_index)),
+ worker_params.sample_count, offset, write_count);
memory.WriteBlock(aux->GetSendInfo(), &send_info, sizeof(AuxInfoDSP));
const auto samples_read = ReadAuxBuffer(
- recv_info, aux->GetRecvBuffer(), params.sample_count,
- GetMixBuffer(output_index), worker_params.sample_count, offset, write_count);
+ recv_info, aux->GetRecvBuffer(), static_cast<u32>(params.sample_count),
+ GetMixBuffer(static_cast<u32>(output_index)), worker_params.sample_count,
+ offset, write_count);
memory.WriteBlock(aux->GetRecvInfo(), &recv_info, sizeof(AuxInfoDSP));
if (samples_read != static_cast<int>(worker_params.sample_count) &&
samples_read <= params.sample_count) {
- std::memset(GetMixBuffer(output_index), 0, params.sample_count - samples_read);
+ std::memset(GetMixBuffer(static_cast<u32>(output_index)), 0,
+ static_cast<size_t>(params.sample_count - samples_read));
}
} else {
AuxInfoDSP empty{};
memory.WriteBlock(aux->GetSendInfo(), &empty, sizeof(AuxInfoDSP));
memory.WriteBlock(aux->GetRecvInfo(), &empty, sizeof(AuxInfoDSP));
if (output_index != input_index) {
- std::memcpy(GetMixBuffer(output_index), GetMixBuffer(input_index),
+ std::memcpy(GetMixBuffer(static_cast<u32>(output_index)),
+ GetMixBuffer(static_cast<u32>(input_index)),
worker_params.sample_count * sizeof(s32));
}
}
@@ -458,7 +470,8 @@ ServerSplitterDestinationData* CommandGenerator::GetDestinationData(s32 splitter
if (splitter_id == AudioCommon::NO_SPLITTER) {
return nullptr;
}
- return splitter_context.GetDestinationData(splitter_id, index);
+ return splitter_context.GetDestinationData(static_cast<u32>(splitter_id),
+ static_cast<u32>(index));
}
s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u32 max_samples,
@@ -488,7 +501,7 @@ s32 CommandGenerator::WriteAuxBuffer(AuxInfoDSP& dsp_info, VAddr send_buffer, u3
if (write_count != 0) {
dsp_info.write_offset = (dsp_info.write_offset + write_count) % max_samples;
}
- return sample_count;
+ return static_cast<s32>(sample_count);
}
s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u32 max_samples,
@@ -518,7 +531,7 @@ s32 CommandGenerator::ReadAuxBuffer(AuxInfoDSP& recv_info, VAddr recv_buffer, u3
if (read_count != 0) {
recv_info.read_offset = (recv_info.read_offset + read_count) % max_samples;
}
- return sample_count;
+ return static_cast<s32>(sample_count);
}
void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float current_volume,
@@ -537,15 +550,15 @@ void CommandGenerator::GenerateVolumeRampCommand(float last_volume, float curren
}
// Apply generic gain on samples
ApplyGain(GetChannelMixBuffer(channel), GetChannelMixBuffer(channel), last, delta,
- worker_params.sample_count);
+ static_cast<s32>(worker_params.sample_count));
}
void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes,
const MixVolumeBuffer& last_mix_volumes,
- VoiceState& dsp_state, s32 mix_buffer_offset,
- s32 mix_buffer_count, s32 voice_index, s32 node_id) {
+ VoiceState& dsp_state, u32 mix_buffer_offset,
+ u32 mix_buffer_count, u32 voice_index, s32 node_id) {
// Loop all our mix buffers
- for (s32 i = 0; i < mix_buffer_count; i++) {
+ for (size_t i = 0; i < mix_buffer_count; i++) {
if (last_mix_volumes[i] != 0.0f || mix_volumes[i] != 0.0f) {
const auto delta = static_cast<float>((mix_volumes[i] - last_mix_volumes[i])) /
static_cast<float>(worker_params.sample_count);
@@ -558,9 +571,9 @@ void CommandGenerator::GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volume
mix_volumes[i]);
}
- dsp_state.previous_samples[i] =
- ApplyMixRamp(GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index),
- last_mix_volumes[i], delta, worker_params.sample_count);
+ dsp_state.previous_samples[i] = ApplyMixRamp(
+ GetMixBuffer(mix_buffer_offset + i), GetMixBuffer(voice_index), last_mix_volumes[i],
+ delta, static_cast<s32>(worker_params.sample_count));
} else {
dsp_state.previous_samples[i] = 0;
}
@@ -572,7 +585,8 @@ void CommandGenerator::GenerateSubMixCommand(ServerMixInfo& mix_info) {
LOG_DEBUG(Audio, "(DSP_TRACE) GenerateSubMixCommand");
}
const auto& in_params = mix_info.GetInParams();
- GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset,
+ GenerateDepopForMixBuffersCommand(static_cast<u32>(in_params.buffer_count),
+ static_cast<u32>(in_params.buffer_offset),
in_params.sample_rate);
GenerateEffectCommand(mix_info);
@@ -586,18 +600,18 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) {
}
const auto& in_params = mix_info.GetInParams();
if (in_params.dest_mix_id != AudioCommon::NO_MIX) {
- const auto& dest_mix = mix_context.GetInfo(in_params.dest_mix_id);
+ const auto& dest_mix = mix_context.GetInfo(static_cast<u32>(in_params.dest_mix_id));
const auto& dest_in_params = dest_mix.GetInParams();
- const auto buffer_count = in_params.buffer_count;
+ const auto buffer_count = static_cast<u32>(in_params.buffer_count);
- for (s32 i = 0; i < buffer_count; i++) {
- for (s32 j = 0; j < dest_in_params.buffer_count; j++) {
+ for (u32 i = 0; i < buffer_count; i++) {
+ for (u32 j = 0; j < static_cast<u32>(dest_in_params.buffer_count); j++) {
const auto mixed_volume = in_params.volume * in_params.mix_volume[i][j];
if (mixed_volume != 0.0f) {
- GenerateMixCommand(dest_in_params.buffer_offset + j,
- in_params.buffer_offset + i, mixed_volume,
- in_params.node_id);
+ GenerateMixCommand(static_cast<size_t>(dest_in_params.buffer_offset) + j,
+ static_cast<size_t>(in_params.buffer_offset) + i,
+ mixed_volume, static_cast<s32>(in_params.node_id));
}
}
}
@@ -608,15 +622,17 @@ void CommandGenerator::GenerateMixCommands(ServerMixInfo& mix_info) {
continue;
}
- const auto& dest_mix = mix_context.GetInfo(destination_data->GetMixId());
+ const auto& dest_mix =
+ mix_context.GetInfo(static_cast<u32>(destination_data->GetMixId()));
const auto& dest_in_params = dest_mix.GetInParams();
const auto mix_index = (base - 1) % in_params.buffer_count + in_params.buffer_offset;
for (std::size_t i = 0; i < static_cast<std::size_t>(dest_in_params.buffer_count);
i++) {
const auto mixed_volume = in_params.volume * destination_data->GetMixVolume(i);
if (mixed_volume != 0.0f) {
- GenerateMixCommand(dest_in_params.buffer_offset + i, mix_index, mixed_volume,
- in_params.node_id);
+ GenerateMixCommand(static_cast<size_t>(dest_in_params.buffer_offset) + i,
+ static_cast<size_t>(mix_index), mixed_volume,
+ static_cast<s32>(in_params.node_id));
}
}
}
@@ -635,7 +651,8 @@ void CommandGenerator::GenerateMixCommand(std::size_t output_offset, std::size_t
auto* output = GetMixBuffer(output_offset);
const auto* input = GetMixBuffer(input_offset);
- const s32 gain = static_cast<s32>(volume * 32768.0f);
+ const auto gain = static_cast<s32>(volume * 32768.0f);
+
// Mix with loop unrolling
if (worker_params.sample_count % 4 == 0) {
ApplyMix<4>(output, input, gain, worker_params.sample_count);
@@ -653,7 +670,8 @@ void CommandGenerator::GenerateFinalMixCommand() {
auto& mix_info = mix_context.GetFinalMixInfo();
const auto& in_params = mix_info.GetInParams();
- GenerateDepopForMixBuffersCommand(in_params.buffer_count, in_params.buffer_offset,
+ GenerateDepopForMixBuffersCommand(static_cast<u32>(in_params.buffer_count),
+ static_cast<u32>(in_params.buffer_offset),
in_params.sample_rate);
GenerateEffectCommand(mix_info);
@@ -667,16 +685,16 @@ void CommandGenerator::GenerateFinalMixCommand() {
in_params.node_id, in_params.buffer_offset + i, in_params.buffer_offset + i,
in_params.volume);
}
- ApplyGainWithoutDelta(GetMixBuffer(in_params.buffer_offset + i),
- GetMixBuffer(in_params.buffer_offset + i), gain,
- worker_params.sample_count);
+ ApplyGainWithoutDelta(GetMixBuffer(static_cast<size_t>(in_params.buffer_offset + i)),
+ GetMixBuffer(static_cast<size_t>(in_params.buffer_offset + i)), gain,
+ static_cast<s32>(worker_params.sample_count));
}
}
s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
s32 sample_count, s32 channel, std::size_t mix_offset) {
const auto& in_params = voice_info.GetInParams();
- const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index];
+ const auto& wave_buffer = in_params.wave_buffer[static_cast<u32>(dsp_state.wave_buffer_index)];
if (wave_buffer.buffer_address == 0) {
return 0;
}
@@ -689,24 +707,26 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s
const auto samples_remaining =
(wave_buffer.end_sample_offset - wave_buffer.start_sample_offset) - dsp_state.offset;
const auto start_offset =
- ((wave_buffer.start_sample_offset + dsp_state.offset) * in_params.channel_count) *
+ static_cast<size_t>((wave_buffer.start_sample_offset + dsp_state.offset) *
+ in_params.channel_count) *
sizeof(s16);
const auto buffer_pos = wave_buffer.buffer_address + start_offset;
const auto samples_processed = std::min(sample_count, samples_remaining);
if (in_params.channel_count == 1) {
- std::vector<s16> buffer(samples_processed);
+ std::vector<s16> buffer(static_cast<size_t>(samples_processed));
memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16));
for (std::size_t i = 0; i < buffer.size(); i++) {
sample_buffer[mix_offset + i] = buffer[i];
}
} else {
const auto channel_count = in_params.channel_count;
- std::vector<s16> buffer(samples_processed * channel_count);
+ std::vector<s16> buffer(static_cast<size_t>(samples_processed * channel_count));
memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16));
for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) {
- sample_buffer[mix_offset + i] = buffer[i * channel_count + channel];
+ sample_buffer[mix_offset + i] =
+ buffer[i * static_cast<u32>(channel_count) + static_cast<u32>(channel)];
}
}
@@ -716,7 +736,7 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s
s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
s32 sample_count, s32 channel, std::size_t mix_offset) {
const auto& in_params = voice_info.GetInParams();
- const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index];
+ const auto& wave_buffer = in_params.wave_buffer[static_cast<u32>(dsp_state.wave_buffer_index)];
if (wave_buffer.buffer_address == 0) {
return 0;
}
@@ -736,7 +756,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
constexpr std::size_t SAMPLES_PER_FRAME = 14;
auto frame_header = dsp_state.context.header;
- s32 idx = (frame_header >> 4) & 0xf;
+ auto idx = static_cast<size_t>((frame_header >> 4) & 0xf);
s32 scale = frame_header & 0xf;
s16 yn1 = dsp_state.context.yn1;
s16 yn2 = dsp_state.context.yn2;
@@ -753,9 +773,10 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
const auto samples_processed = std::min(sample_count, samples_remaining);
const auto sample_pos = wave_buffer.start_sample_offset + dsp_state.offset;
- const auto samples_remaining_in_frame = sample_pos % SAMPLES_PER_FRAME;
- auto position_in_frame = ((sample_pos / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) +
- samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0);
+ const auto samples_remaining_in_frame = static_cast<u32>(sample_pos) % SAMPLES_PER_FRAME;
+ auto position_in_frame =
+ ((static_cast<u32>(sample_pos) / SAMPLES_PER_FRAME) * NIBBLES_PER_SAMPLE) +
+ samples_remaining_in_frame + (samples_remaining_in_frame != 0 ? 2 : 0);
const auto decode_sample = [&](const int nibble) -> s16 {
const int xn = nibble * (1 << scale);
@@ -774,7 +795,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
std::size_t buffer_offset{};
std::vector<u8> buffer(
- std::max((samples_processed / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN));
+ std::max((static_cast<u32>(samples_processed) / FRAME_LEN) * SAMPLES_PER_FRAME, FRAME_LEN));
memory.ReadBlock(wave_buffer.buffer_address + (position_in_frame / 2), buffer.data(),
buffer.size());
std::size_t cur_mix_offset = mix_offset;
@@ -784,7 +805,7 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
if (position_in_frame % NIBBLES_PER_SAMPLE == 0) {
// Read header
frame_header = buffer[buffer_offset++];
- idx = (frame_header >> 4) & 0xf;
+ idx = static_cast<size_t>((frame_header >> 4) & 0xf);
scale = frame_header & 0xf;
coef1 = coeffs[idx * 2];
coef2 = coeffs[idx * 2 + 1];
@@ -794,8 +815,8 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
if (remaining_samples >= static_cast<int>(SAMPLES_PER_FRAME)) {
for (std::size_t i = 0; i < SAMPLES_PER_FRAME / 2; i++) {
// Sample 1
- const s32 s0 = SIGNED_NIBBLES[buffer[buffer_offset] >> 4];
- const s32 s1 = SIGNED_NIBBLES[buffer[buffer_offset++] & 0xf];
+ const s32 s0 = SIGNED_NIBBLES[static_cast<u32>(buffer[buffer_offset] >> 4)];
+ const s32 s1 = SIGNED_NIBBLES[static_cast<u32>(buffer[buffer_offset++] & 0xf)];
const s16 sample_1 = decode_sample(s0);
const s16 sample_2 = decode_sample(s1);
sample_buffer[cur_mix_offset++] = sample_1;
@@ -807,14 +828,14 @@ s32 CommandGenerator::DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_s
}
}
// Decode mid frame
- s32 current_nibble = buffer[buffer_offset];
- if (position_in_frame++ & 0x1) {
+ auto current_nibble = static_cast<s32>(buffer[buffer_offset]);
+ if ((position_in_frame++ & 1) != 0) {
current_nibble &= 0xf;
buffer_offset++;
} else {
current_nibble >>= 4;
}
- const s16 sample = decode_sample(SIGNED_NIBBLES[current_nibble]);
+ const s16 sample = decode_sample(SIGNED_NIBBLES[static_cast<u32>(current_nibble)]);
sample_buffer[cur_mix_offset++] = sample;
remaining_samples--;
}
@@ -835,7 +856,7 @@ const s32* CommandGenerator::GetMixBuffer(std::size_t index) const {
}
std::size_t CommandGenerator::GetMixChannelBufferOffset(s32 channel) const {
- return worker_params.mix_buffer_count + channel;
+ return worker_params.mix_buffer_count + static_cast<u32>(channel);
}
std::size_t CommandGenerator::GetTotalMixBufferCount() const {
@@ -843,11 +864,11 @@ std::size_t CommandGenerator::GetTotalMixBufferCount() const {
}
s32* CommandGenerator::GetChannelMixBuffer(s32 channel) {
- return GetMixBuffer(worker_params.mix_buffer_count + channel);
+ return GetMixBuffer(worker_params.mix_buffer_count + static_cast<u32>(channel));
}
const s32* CommandGenerator::GetChannelMixBuffer(s32 channel) const {
- return GetMixBuffer(worker_params.mix_buffer_count + channel);
+ return GetMixBuffer(worker_params.mix_buffer_count + static_cast<u32>(channel));
}
void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* output,
@@ -895,9 +916,10 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
s32 samples_read{};
while (samples_read < samples_to_read) {
- const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index];
+ const auto& wave_buffer =
+ in_params.wave_buffer[static_cast<u32>(dsp_state.wave_buffer_index)];
// No more data can be read
- if (!dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index]) {
+ if (!dsp_state.is_wave_buffer_valid[static_cast<u32>(dsp_state.wave_buffer_index)]) {
is_buffer_completed = true;
break;
}
@@ -921,7 +943,7 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
UNREACHABLE_MSG("Unimplemented sample format={}", in_params.sample_format);
}
- temp_mix_offset += samples_decoded;
+ temp_mix_offset += static_cast<size_t>(samples_decoded);
samples_read += samples_decoded;
dsp_state.offset += samples_decoded;
dsp_state.played_sample_count += samples_decoded;
@@ -944,10 +966,12 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
} else {
// Update our wave buffer states
- dsp_state.is_wave_buffer_valid[dsp_state.wave_buffer_index] = false;
+ dsp_state.is_wave_buffer_valid[static_cast<u32>(dsp_state.wave_buffer_index)] =
+ false;
dsp_state.wave_buffer_consumed++;
dsp_state.wave_buffer_index =
- (dsp_state.wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS;
+ static_cast<u32>(dsp_state.wave_buffer_index + 1) %
+ AudioCommon::MAX_WAVE_BUFFERS;
if (wave_buffer.end_of_stream) {
dsp_state.played_sample_count = 0;
}
@@ -957,16 +981,20 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, s32* o
if (in_params.behavior_flags.is_pitch_and_src_skipped.Value()) {
// No need to resample
- std::memcpy(output, sample_buffer.data(), samples_read * sizeof(s32));
+ std::memcpy(output, sample_buffer.data(),
+ static_cast<size_t>(samples_read) * sizeof(s32));
} else {
- std::fill(sample_buffer.begin() + temp_mix_offset,
- sample_buffer.begin() + temp_mix_offset + (samples_to_read - samples_read),
- 0);
+ {
+ const auto begin = sample_buffer.begin() + static_cast<ptrdiff_t>(temp_mix_offset);
+ const auto end = begin + (samples_to_read - samples_read);
+ std::fill(begin, end, 0);
+ }
AudioCore::Resample(output, sample_buffer.data(), resample_rate, dsp_state.fraction,
- samples_to_output);
+ static_cast<size_t>(samples_to_output));
// Resample
for (std::size_t i = 0; i < AudioCommon::MAX_SAMPLE_HISTORY; i++) {
- dsp_state.sample_history[i] = sample_buffer[samples_to_read + i];
+ dsp_state.sample_history[i] =
+ sample_buffer[static_cast<size_t>(samples_to_read) + i];
}
}
output += samples_to_output;