summaryrefslogtreecommitdiffstats
path: root/src/audio_core
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2020-10-15 20:49:45 +0200
committerLioncash <mathew1800@gmail.com>2020-10-18 01:50:39 +0200
commitbe1954e04cb5a0c3a526f78ed5490a5e65310280 (patch)
tree267db7ae4be88dbbc288fa605e35d4a2a13839f6 /src/audio_core
parentMerge pull request #4787 from lioncash/conversion (diff)
downloadyuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.gz
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.bz2
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.lz
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.xz
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.zst
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.zip
Diffstat (limited to 'src/audio_core')
-rw-r--r--src/audio_core/CMakeLists.txt5
-rw-r--r--src/audio_core/algorithm/interpolate.cpp6
-rw-r--r--src/audio_core/audio_renderer.cpp4
-rw-r--r--src/audio_core/codec.cpp6
-rw-r--r--src/audio_core/command_generator.cpp212
-rw-r--r--src/audio_core/command_generator.h4
-rw-r--r--src/audio_core/cubeb_sink.cpp2
-rw-r--r--src/audio_core/cubeb_sink.h2
-rw-r--r--src/audio_core/info_updater.cpp4
-rw-r--r--src/audio_core/mix_context.cpp17
-rw-r--r--src/audio_core/sink_context.cpp5
-rw-r--r--src/audio_core/splitter_context.cpp60
-rw-r--r--src/audio_core/time_stretch.h10
-rw-r--r--src/audio_core/voice_context.cpp47
14 files changed, 215 insertions, 169 deletions
diff --git a/src/audio_core/CMakeLists.txt b/src/audio_core/CMakeLists.txt
index 54940a034..74c1453aa 100644
--- a/src/audio_core/CMakeLists.txt
+++ b/src/audio_core/CMakeLists.txt
@@ -51,8 +51,9 @@ if (NOT MSVC)
-Werror=implicit-fallthrough
-Werror=reorder
-Werror=sign-compare
- -Werror=unused-but-set-parameter
- -Werror=unused-but-set-variable
+ -Werror=sign-conversion
+ $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-parameter>
+ $<$<CXX_COMPILER_ID:GNU>:-Werror=unused-but-set-variable>
-Werror=unused-variable
)
endif()
diff --git a/src/audio_core/algorithm/interpolate.cpp b/src/audio_core/algorithm/interpolate.cpp
index 699fcb84c..587ee5b7b 100644
--- a/src/audio_core/algorithm/interpolate.cpp
+++ b/src/audio_core/algorithm/interpolate.cpp
@@ -167,8 +167,8 @@ std::vector<s16> Interpolate(InterpolationState& state, std::vector<s16> input,
output.reserve(static_cast<std::size_t>(static_cast<double>(input.size()) / ratio +
InterpolationState::taps));
- for (std::size_t frame{}; frame < num_frames; ++frame) {
- const std::size_t lut_index{(state.fraction >> 8) * InterpolationState::taps};
+ for (std::size_t frame = 0; frame < num_frames; ++frame) {
+ const auto lut_index{static_cast<size_t>(state.fraction >> 8) * InterpolationState::taps};
std::rotate(state.history.begin(), state.history.end() - 1, state.history.end());
state.history[0][0] = input[frame * 2 + 0];
@@ -225,7 +225,7 @@ void Resample(s32* output, const s32* input, s32 pitch, s32& fraction, std::size
output[i] = (l0 * s0 + l1 * s1 + l2 * s2 + l3 * s3) >> 15;
fraction += pitch;
- index += (fraction >> 15);
+ index += static_cast<size_t>(fraction >> 15);
fraction &= 0x7fff;
}
}
diff --git a/src/audio_core/audio_renderer.cpp b/src/audio_core/audio_renderer.cpp
index a7e851bb8..094bace9c 100644
--- a/src/audio_core/audio_renderer.cpp
+++ b/src/audio_core/audio_renderer.cpp
@@ -187,8 +187,8 @@ void AudioRenderer::QueueMixedBuffer(Buffer::Tag tag) {
const auto& in_params = final_mix.GetInParams();
std::vector<s32*> mix_buffers(channel_count);
for (std::size_t i = 0; i < channel_count; i++) {
- mix_buffers[i] =
- command_generator.GetMixBuffer(in_params.buffer_offset + buffer_offsets[i]);
+ mix_buffers[i] = command_generator.GetMixBuffer(
+ static_cast<u32>(in_params.buffer_offset) + buffer_offsets[i]);
}
for (std::size_t i = 0; i < BUFFER_SIZE; i++) {
diff --git a/src/audio_core/codec.cpp b/src/audio_core/codec.cpp
index 2fb91c13a..d89f94ea2 100644
--- a/src/audio_core/codec.cpp
+++ b/src/audio_core/codec.cpp
@@ -32,7 +32,7 @@ std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM
for (std::size_t framei = 0; framei < NUM_FRAMES; framei++) {
const int frame_header = data[framei * FRAME_LEN];
const int scale = 1 << (frame_header & 0xF);
- const int idx = (frame_header >> 4) & 0x7;
+ const auto idx = static_cast<size_t>((frame_header >> 4) & 0x7);
// Coefficients are fixed point with 11 bits fractional part.
const int coef1 = coeff[idx * 2 + 0];
@@ -57,11 +57,11 @@ std::vector<s16> DecodeADPCM(const u8* const data, std::size_t size, const ADPCM
std::size_t outputi = framei * SAMPLES_PER_FRAME;
std::size_t datai = framei * FRAME_LEN + 1;
for (std::size_t i = 0; i < SAMPLES_PER_FRAME && outputi < sample_count; i += 2) {
- const s16 sample1 = decode_sample(SIGNED_NIBBLES[data[datai] >> 4]);
+ const s16 sample1 = decode_sample(SIGNED_NIBBLES[static_cast<u32>(data[datai] >> 4)]);
ret[outputi] = sample1;
outputi++;
- const s16 sample2 = decode_sample(SIGNED_NIBBLES[data[datai] & 0xF]);
+ const s16 sample2 = decode_sample(SIGNED_NIBBLES[static_cast<u32>(data[datai] & 0xF)]);
ret[outputi] = sample2;
outputi++;
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;
diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h
index 53e57748b..6cba70ae3 100644
--- a/src/audio_core/command_generator.h
+++ b/src/audio_core/command_generator.h
@@ -50,12 +50,12 @@ public:
private:
void GenerateDataSourceCommand(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 channel);
void GenerateBiquadFilterCommandForVoice(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
- s32 mix_buffer_count, s32 channel);
+ u32 mix_buffer_count, s32 channel);
void GenerateVolumeRampCommand(float last_volume, float current_volume, s32 channel,
s32 node_id);
void GenerateVoiceMixCommand(const MixVolumeBuffer& mix_volumes,
const MixVolumeBuffer& last_mix_volumes, VoiceState& dsp_state,
- s32 mix_buffer_offset, s32 mix_buffer_count, s32 voice_index,
+ u32 mix_buffer_offset, u32 mix_buffer_count, u32 voice_index,
s32 node_id);
void GenerateSubMixCommand(ServerMixInfo& mix_info);
void GenerateMixCommands(ServerMixInfo& mix_info);
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp
index 6eaa60815..a20b6ad5f 100644
--- a/src/audio_core/cubeb_sink.cpp
+++ b/src/audio_core/cubeb_sink.cpp
@@ -202,7 +202,7 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const
}
const std::size_t num_channels = impl->GetNumChannels();
- const std::size_t samples_to_write = num_channels * num_frames;
+ const std::size_t samples_to_write = num_channels * static_cast<u64>(num_frames);
std::size_t samples_written;
/*
diff --git a/src/audio_core/cubeb_sink.h b/src/audio_core/cubeb_sink.h
index 7ce850f47..c50d0b7bd 100644
--- a/src/audio_core/cubeb_sink.h
+++ b/src/audio_core/cubeb_sink.h
@@ -27,7 +27,7 @@ private:
std::vector<SinkStreamPtr> sink_streams;
#ifdef _WIN32
- u32 com_init_result = 0;
+ s32 com_init_result = 0;
#endif
};
diff --git a/src/audio_core/info_updater.cpp b/src/audio_core/info_updater.cpp
index 2940e53a9..f999a8b17 100644
--- a/src/audio_core/info_updater.cpp
+++ b/src/audio_core/info_updater.cpp
@@ -350,7 +350,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf
std::size_t total_buffer_count{};
for (std::size_t i = 0; i < mix_count; i++) {
const auto& in = mix_in_params[i];
- total_buffer_count += in.buffer_count;
+ total_buffer_count += static_cast<size_t>(in.buffer_count);
if (static_cast<std::size_t>(in.dest_mix_id) > mix_count &&
in.dest_mix_id != AudioCommon::NO_MIX && in.mix_id != AudioCommon::FINAL_MIX) {
LOG_ERROR(
@@ -379,7 +379,7 @@ ResultCode InfoUpdater::UpdateMixes(MixContext& mix_context, std::size_t mix_buf
const auto& mix_in = mix_in_params[i];
std::size_t target_mix{};
if (behavior_info.IsMixInParameterDirtyOnlyUpdateSupported()) {
- target_mix = mix_in.mix_id;
+ target_mix = static_cast<size_t>(mix_in.mix_id);
} else {
// Non dirty supported games just use i instead of the actual mix_id
target_mix = i;
diff --git a/src/audio_core/mix_context.cpp b/src/audio_core/mix_context.cpp
index 4bca72eb0..c28bee453 100644
--- a/src/audio_core/mix_context.cpp
+++ b/src/audio_core/mix_context.cpp
@@ -62,7 +62,7 @@ void MixContext::UpdateDistancesFromFinalMix() {
distance_to_final_mix = AudioCommon::NO_FINAL_MIX;
break;
} else {
- const auto& dest_mix = GetInfo(mix_id);
+ const auto& dest_mix = GetInfo(static_cast<u32>(mix_id));
const auto dest_mix_distance = dest_mix.GetInParams().final_mix_distance;
if (dest_mix_distance == AudioCommon::NO_FINAL_MIX) {
@@ -129,7 +129,7 @@ bool MixContext::TsortInfo(SplitterContext& splitter_context) {
std::size_t info_id{};
for (auto itr = sorted_list.rbegin(); itr != sorted_list.rend(); ++itr) {
// Set our sorted info
- sorted_info[info_id++] = &GetInfo(*itr);
+ sorted_info[info_id++] = &GetInfo(static_cast<u32>(*itr));
}
// Calculate the mix buffer offset
@@ -218,7 +218,8 @@ bool ServerMixInfo::Update(EdgeMatrix& edge_matrix, const MixInfo::InParams& mix
for (std::size_t i = 0; i < effect_count; i++) {
auto* effect_info = effect_context.GetInfo(i);
if (effect_info->GetMixID() == in_params.mix_id) {
- effect_processing_order[effect_info->GetProcessingOrder()] = static_cast<s32>(i);
+ const auto processing_order = static_cast<u32>(effect_info->GetProcessingOrder());
+ effect_processing_order[processing_order] = static_cast<s32>(i);
}
}
@@ -265,7 +266,7 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP
if (in_params.dest_mix_id == mix_in.dest_mix_id &&
in_params.splitter_id == mix_in.splitter_id &&
((in_params.splitter_id == AudioCommon::NO_SPLITTER) ||
- !splitter_context.GetInfo(in_params.splitter_id).HasNewConnection())) {
+ !splitter_context.GetInfo(static_cast<u32>(in_params.splitter_id)).HasNewConnection())) {
return false;
}
// Remove current edges for mix id
@@ -275,11 +276,11 @@ bool ServerMixInfo::UpdateConnection(EdgeMatrix& edge_matrix, const MixInfo::InP
edge_matrix.Connect(in_params.mix_id, mix_in.dest_mix_id);
} else if (mix_in.splitter_id != AudioCommon::NO_SPLITTER) {
// Recurse our splitter linked and set our edges
- auto& splitter_info = splitter_context.GetInfo(mix_in.splitter_id);
- const auto length = splitter_info.GetLength();
- for (s32 i = 0; i < length; i++) {
+ auto& splitter_info = splitter_context.GetInfo(static_cast<u32>(mix_in.splitter_id));
+ const auto length = static_cast<size_t>(splitter_info.GetLength());
+ for (size_t i = 0; i < length; i++) {
const auto* splitter_destination =
- splitter_context.GetDestinationData(mix_in.splitter_id, i);
+ splitter_context.GetDestinationData(static_cast<u32>(mix_in.splitter_id), i);
if (splitter_destination == nullptr) {
continue;
}
diff --git a/src/audio_core/sink_context.cpp b/src/audio_core/sink_context.cpp
index 0882b411a..3d713814a 100644
--- a/src/audio_core/sink_context.cpp
+++ b/src/audio_core/sink_context.cpp
@@ -23,8 +23,9 @@ bool SinkContext::InUse() const {
}
std::vector<u8> SinkContext::OutputBuffers() const {
- std::vector<u8> buffer_ret(use_count);
- std::memcpy(buffer_ret.data(), buffers.data(), use_count);
+ const auto output_use_count = static_cast<size_t>(use_count);
+ std::vector<u8> buffer_ret(output_use_count);
+ std::memcpy(buffer_ret.data(), buffers.data(), output_use_count);
return buffer_ret;
}
diff --git a/src/audio_core/splitter_context.cpp b/src/audio_core/splitter_context.cpp
index f21b53147..f3e870648 100644
--- a/src/audio_core/splitter_context.cpp
+++ b/src/audio_core/splitter_context.cpp
@@ -109,7 +109,7 @@ std::size_t ServerSplitterInfo::Update(SplitterInfo::InInfoPrams& header) {
new_connection = true;
// We need to update the size here due to the splitter bug being present and providing an
// incorrect size. We're suppose to also update the header here but we just ignore and continue
- return (sizeof(s32_le) * (header.length - 1)) + (sizeof(s32_le) * 3);
+ return (sizeof(s32_le) * static_cast<size_t>(header.length - 1)) + (sizeof(s32_le) * 3);
}
ServerSplitterDestinationData* ServerSplitterInfo::GetHead() {
@@ -306,13 +306,14 @@ bool SplitterContext::UpdateInfo(const std::vector<u8>& input, std::size_t& inpu
break;
}
- if (header.send_id < 0 || static_cast<std::size_t>(header.send_id) > info_count) {
+ const auto send_id = static_cast<std::size_t>(header.send_id);
+ if (header.send_id < 0 || send_id > info_count) {
LOG_ERROR(Audio, "Bad splitter data id");
break;
}
UpdateOffsets(sizeof(SplitterInfo::InInfoPrams));
- auto& info = GetInfo(header.send_id);
+ auto& info = GetInfo(send_id);
if (!RecomposeDestination(info, header, input, input_offset)) {
LOG_ERROR(Audio, "Failed to recompose destination for splitter!");
return false;
@@ -348,11 +349,12 @@ bool SplitterContext::UpdateData(const std::vector<u8>& input, std::size_t& inpu
break;
}
- if (header.splitter_id < 0 || static_cast<std::size_t>(header.splitter_id) > data_count) {
+ const auto splitter_id = static_cast<std::size_t>(header.splitter_id);
+ if (header.splitter_id < 0 || splitter_id > data_count) {
LOG_ERROR(Audio, "Bad splitter data id");
break;
}
- GetData(header.splitter_id).Update(header);
+ GetData(splitter_id).Update(header);
}
return true;
}
@@ -386,9 +388,9 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info,
return true;
}
- auto* start_head = &GetData(header.resource_id_base);
+ auto* start_head = &GetData(static_cast<u32>(header.resource_id_base));
current_head = start_head;
- std::vector<s32_le> resource_ids(size - 1);
+ std::vector<s32_le> resource_ids(static_cast<size_t>(size - 1));
if (!AudioCommon::CanConsumeBuffer(input.size(), input_offset,
resource_ids.size() * sizeof(s32_le))) {
LOG_ERROR(Audio, "Buffer is an invalid size!");
@@ -397,8 +399,8 @@ bool SplitterContext::RecomposeDestination(ServerSplitterInfo& info,
std::memcpy(resource_ids.data(), input.data() + input_offset,
resource_ids.size() * sizeof(s32_le));
- for (auto resource_id : resource_ids) {
- auto* head = &GetData(resource_id);
+ for (const auto resource_id : resource_ids) {
+ auto* head = &GetData(static_cast<u32>(resource_id));
current_head->SetNextDestination(head);
current_head = head;
}
@@ -444,7 +446,7 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) {
const auto node_id = static_cast<s32>(i);
// If we don't have a state, send to our index stack for work
- if (GetState(i) == NodeStates::State::NoState) {
+ if (GetState(i) == State::NoState) {
index_stack.push(node_id);
}
@@ -453,19 +455,19 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) {
// Get the current node
const auto current_stack_index = index_stack.top();
// Check if we've seen the node yet
- const auto index_state = GetState(current_stack_index);
- if (index_state == NodeStates::State::NoState) {
+ const auto index_state = GetState(static_cast<u32>(current_stack_index));
+ if (index_state == State::NoState) {
// Mark the node as seen
- UpdateState(NodeStates::State::InFound, current_stack_index);
- } else if (index_state == NodeStates::State::InFound) {
+ UpdateState(State::InFound, static_cast<u32>(current_stack_index));
+ } else if (index_state == State::InFound) {
// We've seen this node before, mark it as completed
- UpdateState(NodeStates::State::InCompleted, current_stack_index);
+ UpdateState(State::InCompleted, static_cast<u32>(current_stack_index));
// Update our index list
PushTsortResult(current_stack_index);
// Pop the stack
index_stack.pop();
continue;
- } else if (index_state == NodeStates::State::InCompleted) {
+ } else if (index_state == State::InCompleted) {
// If our node is already sorted, clear it
index_stack.pop();
continue;
@@ -479,11 +481,11 @@ bool NodeStates::DepthFirstSearch(EdgeMatrix& edge_matrix) {
}
// Check if our node exists
- const auto node_state = GetState(j);
- if (node_state == NodeStates::State::NoState) {
+ const auto node_state = GetState(static_cast<u32>(j));
+ if (node_state == State::NoState) {
// Add more work
index_stack.push(j);
- } else if (node_state == NodeStates::State::InFound) {
+ } else if (node_state == State::InFound) {
UNREACHABLE_MSG("Node start marked as found");
ResetState();
return false;
@@ -507,17 +509,17 @@ void NodeStates::ResetState() {
}
}
-void NodeStates::UpdateState(NodeStates::State state, std::size_t i) {
+void NodeStates::UpdateState(State state, std::size_t i) {
switch (state) {
- case NodeStates::State::NoState:
+ case State::NoState:
was_node_found[i] = false;
was_node_completed[i] = false;
break;
- case NodeStates::State::InFound:
+ case State::InFound:
was_node_found[i] = true;
was_node_completed[i] = false;
break;
- case NodeStates::State::InCompleted:
+ case State::InCompleted:
was_node_found[i] = false;
was_node_completed[i] = true;
break;
@@ -528,13 +530,13 @@ NodeStates::State NodeStates::GetState(std::size_t i) {
ASSERT(i < node_count);
if (was_node_found[i]) {
// If our node exists in our found list
- return NodeStates::State::InFound;
+ return State::InFound;
} else if (was_node_completed[i]) {
// If node is in the completed list
- return NodeStates::State::InCompleted;
+ return State::InCompleted;
} else {
// If in neither
- return NodeStates::State::NoState;
+ return State::NoState;
}
}
@@ -601,16 +603,16 @@ std::size_t EdgeMatrix::GetNodeCount() const {
void EdgeMatrix::SetState(s32 a, s32 b, bool state) {
ASSERT(InRange(a, b));
- edge_matrix.at(a * node_count + b) = state;
+ edge_matrix.at(static_cast<u32>(a) * node_count + static_cast<u32>(b)) = state;
}
bool EdgeMatrix::GetState(s32 a, s32 b) {
ASSERT(InRange(a, b));
- return edge_matrix.at(a * node_count + b);
+ return edge_matrix.at(static_cast<u32>(a) * node_count + static_cast<u32>(b));
}
bool EdgeMatrix::InRange(s32 a, s32 b) const {
- const std::size_t pos = a * node_count + b;
+ const std::size_t pos = static_cast<u32>(a) * node_count + static_cast<u32>(b);
return pos < (node_count * node_count);
}
diff --git a/src/audio_core/time_stretch.h b/src/audio_core/time_stretch.h
index bb2270b96..3808e554d 100644
--- a/src/audio_core/time_stretch.h
+++ b/src/audio_core/time_stretch.h
@@ -5,9 +5,17 @@
#pragma once
#include <cstddef>
-#include <SoundTouch.h>
#include "common/common_types.h"
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsign-conversion"
+#endif
+#include <SoundTouch.h>
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
namespace AudioCore {
class TimeStretcher {
diff --git a/src/audio_core/voice_context.cpp b/src/audio_core/voice_context.cpp
index c46ee55f1..276b96ca4 100644
--- a/src/audio_core/voice_context.cpp
+++ b/src/audio_core/voice_context.cpp
@@ -98,7 +98,7 @@ void ServerVoiceInfo::UpdateParameters(const VoiceInfo::InParams& voice_in,
BehaviorInfo& behavior_info) {
in_params.in_use = voice_in.is_in_use;
in_params.id = voice_in.id;
- in_params.node_id = voice_in.node_id;
+ in_params.node_id = static_cast<s32>(voice_in.node_id);
in_params.last_playstate = in_params.current_playstate;
switch (voice_in.play_state) {
case PlayState::Paused:
@@ -220,8 +220,10 @@ void ServerVoiceInfo::UpdateWaveBuffer(ServerWaveBuffer& out_wavebuffer,
if (sample_format == SampleFormat::Pcm16) {
const auto buffer_size = in_wave_buffer.buffer_size;
if (in_wave_buffer.start_sample_offset < 0 || in_wave_buffer.end_sample_offset < 0 ||
- (buffer_size < (sizeof(s16) * in_wave_buffer.start_sample_offset)) ||
- (buffer_size < (sizeof(s16) * in_wave_buffer.end_sample_offset))) {
+ (buffer_size <
+ (sizeof(s16) * static_cast<u32>(in_wave_buffer.start_sample_offset))) ||
+ (buffer_size <
+ (sizeof(s16) * static_cast<u32>(in_wave_buffer.end_sample_offset)))) {
// TODO(ogniK): Write error info
return;
}
@@ -254,8 +256,8 @@ void ServerVoiceInfo::WriteOutStatus(
voice_out.played_sample_count = 0;
voice_out.voice_dropped = false;
} else if (!in_params.is_new) {
- voice_out.wave_buffer_consumed = voice_states[0]->wave_buffer_consumed;
- voice_out.played_sample_count = voice_states[0]->played_sample_count;
+ voice_out.wave_buffer_consumed = static_cast<u32>(voice_states[0]->wave_buffer_consumed);
+ voice_out.played_sample_count = static_cast<u64>(voice_states[0]->played_sample_count);
voice_out.voice_dropped = in_params.voice_drop_flag;
} else {
voice_out.wave_buffer_consumed = 0;
@@ -293,8 +295,8 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) {
in_params.is_new = false;
}
- const s32 channel_count = in_params.channel_count;
- for (s32 i = 0; i < channel_count; i++) {
+ const auto channel_count = static_cast<size_t>(in_params.channel_count);
+ for (size_t i = 0; i < channel_count; i++) {
const auto channel_resource = in_params.voice_channel_resource_id[i];
dsp_voice_states[i] =
&voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource));
@@ -303,8 +305,9 @@ bool ServerVoiceInfo::UpdateForCommandGeneration(VoiceContext& voice_context) {
}
void ServerVoiceInfo::ResetResources(VoiceContext& voice_context) {
- const s32 channel_count = in_params.channel_count;
- for (s32 i = 0; i < channel_count; i++) {
+ const auto channel_count = static_cast<size_t>(in_params.channel_count);
+
+ for (size_t i = 0; i < channel_count; i++) {
const auto channel_resource = in_params.voice_channel_resource_id[i];
auto& dsp_state =
voice_context.GetDspSharedState(static_cast<std::size_t>(channel_resource));
@@ -325,9 +328,9 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration(
switch (in_params.current_playstate) {
case ServerPlayState::Play: {
- for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) {
+ for (size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) {
if (!in_params.wave_buffer[i].sent_to_dsp) {
- for (s32 channel = 0; channel < channel_count; channel++) {
+ for (size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
dsp_voice_states[channel]->is_wave_buffer_valid[i] = true;
}
in_params.wave_buffer[i].sent_to_dsp = true;
@@ -344,12 +347,13 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration(
case ServerPlayState::RequestStop: {
for (std::size_t i = 0; i < AudioCommon::MAX_WAVE_BUFFERS; i++) {
in_params.wave_buffer[i].sent_to_dsp = true;
- for (s32 channel = 0; channel < channel_count; channel++) {
+ for (std::size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
auto* dsp_state = dsp_voice_states[channel];
if (dsp_state->is_wave_buffer_valid[i]) {
dsp_state->wave_buffer_index =
- (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS;
+ static_cast<s32>(static_cast<u32>(dsp_state->wave_buffer_index + 1) %
+ AudioCommon::MAX_WAVE_BUFFERS);
dsp_state->wave_buffer_consumed++;
}
@@ -357,7 +361,7 @@ bool ServerVoiceInfo::UpdateParametersForCommandGeneration(
}
}
- for (s32 channel = 0; channel < channel_count; channel++) {
+ for (size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
auto* dsp_state = dsp_voice_states[channel];
dsp_state->offset = 0;
dsp_state->played_sample_count = 0;
@@ -383,15 +387,16 @@ void ServerVoiceInfo::FlushWaveBuffers(
auto wave_head = in_params.wave_bufffer_head;
for (u8 i = 0; i < flush_count; i++) {
- in_params.wave_buffer[wave_head].sent_to_dsp = true;
- for (s32 channel = 0; channel < channel_count; channel++) {
+ in_params.wave_buffer[static_cast<u16>(wave_head)].sent_to_dsp = true;
+ for (size_t channel = 0; channel < static_cast<size_t>(channel_count); channel++) {
auto* dsp_state = dsp_voice_states[channel];
dsp_state->wave_buffer_consumed++;
- dsp_state->is_wave_buffer_valid[wave_head] = false;
- dsp_state->wave_buffer_index =
- (dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS;
+ dsp_state->is_wave_buffer_valid[static_cast<u16>(wave_head)] = false;
+ dsp_state->wave_buffer_index = static_cast<s32>(
+ static_cast<u32>(dsp_state->wave_buffer_index + 1) % AudioCommon::MAX_WAVE_BUFFERS);
}
- wave_head = (wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS;
+ wave_head =
+ static_cast<s16>(static_cast<u32>(wave_head + 1) % AudioCommon::MAX_WAVE_BUFFERS);
}
}
@@ -483,7 +488,7 @@ s32 VoiceContext::DecodePcm16(s32* output_buffer, ServerWaveBuffer* wave_buffer,
const auto samples_remaining =
(wave_buffer->end_sample_offset - wave_buffer->start_sample_offset) - buffer_offset;
const auto start_offset = (wave_buffer->start_sample_offset + buffer_offset) * channel_count;
- const auto buffer_pos = wave_buffer->buffer_address + start_offset;
+ const auto buffer_pos = wave_buffer->buffer_address + static_cast<VAddr>(start_offset);
s16* buffer_data = reinterpret_cast<s16*>(memory.GetPointer(buffer_pos));