summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/audio_core/command_generator.cpp64
-rw-r--r--src/audio_core/command_generator.h5
2 files changed, 51 insertions, 18 deletions
diff --git a/src/audio_core/command_generator.cpp b/src/audio_core/command_generator.cpp
index 1402ff280..b99d0fc91 100644
--- a/src/audio_core/command_generator.cpp
+++ b/src/audio_core/command_generator.cpp
@@ -403,7 +403,10 @@ void CommandGenerator::GenerateDataSourceCommand(ServerVoiceInfo& voice_info, Vo
403 } 403 }
404 } else { 404 } else {
405 switch (in_params.sample_format) { 405 switch (in_params.sample_format) {
406 case SampleFormat::Pcm8:
406 case SampleFormat::Pcm16: 407 case SampleFormat::Pcm16:
408 case SampleFormat::Pcm32:
409 case SampleFormat::PcmFloat:
407 DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel, 410 DecodeFromWaveBuffers(voice_info, GetChannelMixBuffer(channel), dsp_state, channel,
408 worker_params.sample_rate, worker_params.sample_count, 411 worker_params.sample_rate, worker_params.sample_count,
409 in_params.node_id); 412 in_params.node_id);
@@ -1009,9 +1012,10 @@ void CommandGenerator::GenerateFinalMixCommand() {
1009 } 1012 }
1010} 1013}
1011 1014
1012s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, 1015template <typename T>
1013 s32 sample_start_offset, s32 sample_end_offset, s32 sample_count, 1016s32 CommandGenerator::DecodePcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state,
1014 s32 channel, std::size_t mix_offset) { 1017 s32 sample_start_offset, s32 sample_end_offset, s32 sample_count,
1018 s32 channel, std::size_t mix_offset) {
1015 const auto& in_params = voice_info.GetInParams(); 1019 const auto& in_params = voice_info.GetInParams();
1016 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index]; 1020 const auto& wave_buffer = in_params.wave_buffer[dsp_state.wave_buffer_index];
1017 if (wave_buffer.buffer_address == 0) { 1021 if (wave_buffer.buffer_address == 0) {
@@ -1025,24 +1029,37 @@ s32 CommandGenerator::DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_s
1025 } 1029 }
1026 const auto samples_remaining = (sample_end_offset - sample_start_offset) - dsp_state.offset; 1030 const auto samples_remaining = (sample_end_offset - sample_start_offset) - dsp_state.offset;
1027 const auto start_offset = 1031 const auto start_offset =
1028 ((dsp_state.offset + sample_start_offset) * in_params.channel_count) * sizeof(s16); 1032 ((dsp_state.offset + sample_start_offset) * in_params.channel_count) * sizeof(T);
1029 const auto buffer_pos = wave_buffer.buffer_address + start_offset; 1033 const auto buffer_pos = wave_buffer.buffer_address + start_offset;
1030 const auto samples_processed = std::min(sample_count, samples_remaining); 1034 const auto samples_processed = std::min(sample_count, samples_remaining);
1031 1035
1032 if (in_params.channel_count == 1) { 1036 const auto channel_count = in_params.channel_count;
1033 std::vector<s16> buffer(samples_processed); 1037 std::vector<T> buffer(samples_processed * channel_count);
1034 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16)); 1038 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(T));
1035 for (std::size_t i = 0; i < buffer.size(); i++) {
1036 sample_buffer[mix_offset + i] = buffer[i];
1037 }
1038 } else {
1039 const auto channel_count = in_params.channel_count;
1040 std::vector<s16> buffer(samples_processed * channel_count);
1041 memory.ReadBlock(buffer_pos, buffer.data(), buffer.size() * sizeof(s16));
1042 1039
1040 if constexpr (std::is_floating_point_v<T>) {
1041 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) {
1042 sample_buffer[mix_offset + i] = static_cast<s32>(buffer[i * channel_count + channel] *
1043 std::numeric_limits<s16>::max());
1044 }
1045 } else if constexpr (sizeof(T) == 1) {
1046 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) {
1047 sample_buffer[mix_offset + i] =
1048 static_cast<s32>(static_cast<f32>(buffer[i * channel_count + channel] /
1049 std::numeric_limits<s8>::max()) *
1050 std::numeric_limits<s16>::max());
1051 }
1052 } else if constexpr (sizeof(T) == 2) {
1043 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) { 1053 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) {
1044 sample_buffer[mix_offset + i] = buffer[i * channel_count + channel]; 1054 sample_buffer[mix_offset + i] = buffer[i * channel_count + channel];
1045 } 1055 }
1056 } else {
1057 for (std::size_t i = 0; i < static_cast<std::size_t>(samples_processed); i++) {
1058 sample_buffer[mix_offset + i] =
1059 static_cast<s32>(static_cast<f32>(buffer[i * channel_count + channel] /
1060 std::numeric_limits<s32>::max()) *
1061 std::numeric_limits<s16>::max());
1062 }
1046 } 1063 }
1047 1064
1048 return samples_processed; 1065 return samples_processed;
@@ -1258,10 +1275,25 @@ void CommandGenerator::DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, std::s
1258 1275
1259 s32 samples_decoded{0}; 1276 s32 samples_decoded{0};
1260 switch (in_params.sample_format) { 1277 switch (in_params.sample_format) {
1278 case SampleFormat::Pcm8:
1279 samples_decoded =
1280 DecodePcm<s8>(voice_info, dsp_state, samples_offset_start, samples_offset_end,
1281 samples_to_read - samples_read, channel, temp_mix_offset);
1282 break;
1261 case SampleFormat::Pcm16: 1283 case SampleFormat::Pcm16:
1262 samples_decoded = 1284 samples_decoded =
1263 DecodePcm16(voice_info, dsp_state, samples_offset_start, samples_offset_end, 1285 DecodePcm<s16>(voice_info, dsp_state, samples_offset_start, samples_offset_end,
1264 samples_to_read - samples_read, channel, temp_mix_offset); 1286 samples_to_read - samples_read, channel, temp_mix_offset);
1287 break;
1288 case SampleFormat::Pcm32:
1289 samples_decoded =
1290 DecodePcm<s32>(voice_info, dsp_state, samples_offset_start, samples_offset_end,
1291 samples_to_read - samples_read, channel, temp_mix_offset);
1292 break;
1293 case SampleFormat::PcmFloat:
1294 samples_decoded =
1295 DecodePcm<f32>(voice_info, dsp_state, samples_offset_start, samples_offset_end,
1296 samples_to_read - samples_read, channel, temp_mix_offset);
1265 break; 1297 break;
1266 case SampleFormat::Adpcm: 1298 case SampleFormat::Adpcm:
1267 samples_decoded = 1299 samples_decoded =
diff --git a/src/audio_core/command_generator.h b/src/audio_core/command_generator.h
index ac034b0a5..59a33ba76 100644
--- a/src/audio_core/command_generator.h
+++ b/src/audio_core/command_generator.h
@@ -88,8 +88,9 @@ private:
88 std::vector<u8>& work_buffer); 88 std::vector<u8>& work_buffer);
89 void UpdateI3dl2Reverb(I3dl2ReverbParams& info, I3dl2ReverbState& state, bool should_clear); 89 void UpdateI3dl2Reverb(I3dl2ReverbParams& info, I3dl2ReverbState& state, bool should_clear);
90 // DSP Code 90 // DSP Code
91 s32 DecodePcm16(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_start_offset, 91 template <typename T>
92 s32 sample_end_offset, s32 sample_count, s32 channel, std::size_t mix_offset); 92 s32 DecodePcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_start_offset,
93 s32 sample_end_offset, s32 sample_count, s32 channel, std::size_t mix_offset);
93 s32 DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_start_offset, 94 s32 DecodeAdpcm(ServerVoiceInfo& voice_info, VoiceState& dsp_state, s32 sample_start_offset,
94 s32 sample_end_offset, s32 sample_count, s32 channel, std::size_t mix_offset); 95 s32 sample_end_offset, s32 sample_count, s32 channel, std::size_t mix_offset);
95 void DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, std::span<s32> output, 96 void DecodeFromWaveBuffers(ServerVoiceInfo& voice_info, std::span<s32> output,