device.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <algorithm>
  4. #include "audio_core/renderer/adsp/command_list_processor.h"
  5. #include "audio_core/renderer/command/sink/device.h"
  6. #include "audio_core/sink/sink.h"
  7. namespace AudioCore::AudioRenderer {
  8. void DeviceSinkCommand::Dump([[maybe_unused]] const ADSP::CommandListProcessor& processor,
  9. std::string& string) {
  10. string += fmt::format("DeviceSinkCommand\n\t{} session {} input_count {}\n\tinputs: ",
  11. std::string_view(name), session_id, input_count);
  12. for (u32 i = 0; i < input_count; i++) {
  13. string += fmt::format("{:02X}, ", inputs[i]);
  14. }
  15. string += "\n";
  16. }
  17. void DeviceSinkCommand::Process(const ADSP::CommandListProcessor& processor) {
  18. constexpr s32 min = std::numeric_limits<s16>::min();
  19. constexpr s32 max = std::numeric_limits<s16>::max();
  20. auto stream{processor.GetOutputSinkStream()};
  21. stream->SetSystemChannels(input_count);
  22. Sink::SinkBuffer out_buffer{
  23. .frames{TargetSampleCount},
  24. .frames_played{0},
  25. .tag{0},
  26. .consumed{false},
  27. };
  28. std::vector<s16> samples(out_buffer.frames * input_count);
  29. for (u32 channel = 0; channel < input_count; channel++) {
  30. const auto offset{inputs[channel] * out_buffer.frames};
  31. for (u32 index = 0; index < out_buffer.frames; index++) {
  32. samples[index * input_count + channel] =
  33. static_cast<s16>(std::clamp(sample_buffer[offset + index], min, max));
  34. }
  35. }
  36. out_buffer.tag = reinterpret_cast<u64>(samples.data());
  37. stream->AppendBuffer(out_buffer, samples);
  38. if (stream->IsPaused()) {
  39. stream->Start();
  40. }
  41. }
  42. bool DeviceSinkCommand::Verify(const ADSP::CommandListProcessor& processor) {
  43. return true;
  44. }
  45. } // namespace AudioCore::AudioRenderer