Project Andio

This commit is contained in:
Kelebek1
2022-07-16 23:48:45 +01:00
parent 6e36f4d230
commit 458da8a948
270 changed files with 33712 additions and 8445 deletions

View File

@ -0,0 +1,48 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <vector>
#include "audio_core/renderer/adsp/command_list_processor.h"
#include "audio_core/renderer/command/sink/circular_buffer.h"
#include "core/memory.h"
namespace AudioCore::AudioRenderer {
void CircularBufferSinkCommand::Dump([[maybe_unused]] const ADSP::CommandListProcessor& processor,
std::string& string) {
string += fmt::format(
"CircularBufferSinkCommand\n\tinput_count {} ring size {:04X} ring pos {:04X}\n\tinputs: ",
input_count, size, pos);
for (u32 i = 0; i < input_count; i++) {
string += fmt::format("{:02X}, ", inputs[i]);
}
string += "\n";
}
void CircularBufferSinkCommand::Process(const ADSP::CommandListProcessor& processor) {
constexpr s32 min{std::numeric_limits<s16>::min()};
constexpr s32 max{std::numeric_limits<s16>::max()};
std::vector<s16> output(processor.sample_count);
for (u32 channel = 0; channel < input_count; channel++) {
auto input{processor.mix_buffers.subspan(inputs[channel] * processor.sample_count,
processor.sample_count)};
for (u32 sample_index = 0; sample_index < processor.sample_count; sample_index++) {
output[sample_index] = static_cast<s16>(std::clamp(input[sample_index], min, max));
}
processor.memory->WriteBlockUnsafe(address + pos, output.data(),
output.size() * sizeof(s16));
pos += static_cast<u32>(processor.sample_count * sizeof(s16));
if (pos >= size) {
pos = 0;
}
}
}
bool CircularBufferSinkCommand::Verify(const ADSP::CommandListProcessor& processor) {
return true;
}
} // namespace AudioCore::AudioRenderer

View File

@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <string>
#include "audio_core/renderer/command/icommand.h"
#include "common/common_types.h"
namespace AudioCore::AudioRenderer {
namespace ADSP {
class CommandListProcessor;
}
/**
* AudioRenderer command for sinking samples to a circular buffer.
*/
struct CircularBufferSinkCommand : ICommand {
/**
* Print this command's information to a string.
*
* @param processor - The CommandListProcessor processing this command.
* @param string - The string to print into.
*/
void Dump(const ADSP::CommandListProcessor& processor, std::string& string) override;
/**
* Process this command.
*
* @param processor - The CommandListProcessor processing this command.
*/
void Process(const ADSP::CommandListProcessor& processor) override;
/**
* Verify this command's data is valid.
*
* @param processor - The CommandListProcessor processing this command.
* @return True if the command is valid, otherwise false.
*/
bool Verify(const ADSP::CommandListProcessor& processor) override;
/// Number of input mix buffers
u32 input_count;
/// Input mix buffer indexes
std::array<s16, MaxChannels> inputs;
/// Circular buffer address
CpuAddr address;
/// Circular buffer size
u32 size;
/// Current buffer offset
u32 pos;
};
} // namespace AudioCore::AudioRenderer

View File

@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm>
#include "audio_core/renderer/adsp/command_list_processor.h"
#include "audio_core/renderer/command/sink/device.h"
#include "audio_core/sink/sink.h"
namespace AudioCore::AudioRenderer {
void DeviceSinkCommand::Dump([[maybe_unused]] const ADSP::CommandListProcessor& processor,
std::string& string) {
string += fmt::format("DeviceSinkCommand\n\t{} session {} input_count {}\n\tinputs: ",
std::string_view(name), session_id, input_count);
for (u32 i = 0; i < input_count; i++) {
string += fmt::format("{:02X}, ", inputs[i]);
}
string += "\n";
}
void DeviceSinkCommand::Process(const ADSP::CommandListProcessor& processor) {
constexpr s32 min = std::numeric_limits<s16>::min();
constexpr s32 max = std::numeric_limits<s16>::max();
auto stream{processor.GetOutputSinkStream()};
stream->SetSystemChannels(input_count);
Sink::SinkBuffer out_buffer{
.frames{TargetSampleCount},
.frames_played{0},
.tag{0},
.consumed{false},
};
std::vector<s16> samples(out_buffer.frames * input_count);
for (u32 channel = 0; channel < input_count; channel++) {
const auto offset{inputs[channel] * out_buffer.frames};
for (u32 index = 0; index < out_buffer.frames; index++) {
samples[index * input_count + channel] =
static_cast<s16>(std::clamp(sample_buffer[offset + index], min, max));
}
}
out_buffer.tag = reinterpret_cast<u64>(samples.data());
stream->AppendBuffer(out_buffer, samples);
}
bool DeviceSinkCommand::Verify(const ADSP::CommandListProcessor& processor) {
return true;
}
} // namespace AudioCore::AudioRenderer

View File

@ -0,0 +1,57 @@
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <span>
#include <string>
#include "audio_core/renderer/command/icommand.h"
#include "common/common_types.h"
namespace AudioCore::AudioRenderer {
namespace ADSP {
class CommandListProcessor;
}
/**
* AudioRenderer command for sinking samples to an output device.
*/
struct DeviceSinkCommand : ICommand {
/**
* Print this command's information to a string.
*
* @param processor - The CommandListProcessor processing this command.
* @param string - The string to print into.
*/
void Dump(const ADSP::CommandListProcessor& processor, std::string& string) override;
/**
* Process this command.
*
* @param processor - The CommandListProcessor processing this command.
*/
void Process(const ADSP::CommandListProcessor& processor) override;
/**
* Verify this command's data is valid.
*
* @param processor - The CommandListProcessor processing this command.
* @return True if the command is valid, otherwise false.
*/
bool Verify(const ADSP::CommandListProcessor& processor) override;
/// Device name
char name[0x100];
/// System session id (unused)
s32 session_id;
/// Sample buffer to sink
std::span<s32> sample_buffer;
/// Number of input channels
u32 input_count;
/// Mix buffer indexes for each channel
std::array<s16, MaxChannels> inputs;
};
} // namespace AudioCore::AudioRenderer