2018-01-15 03:29:11 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-07-20 05:04:25 +02:00
|
|
|
#include <array>
|
2018-09-12 03:45:20 +02:00
|
|
|
#include <cstring>
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
#include <vector>
|
2018-08-03 21:30:01 +02:00
|
|
|
|
2018-09-12 03:45:20 +02:00
|
|
|
#include "audio_core/audio_out.h"
|
2018-08-03 21:30:01 +02:00
|
|
|
#include "audio_core/codec.h"
|
2018-09-12 03:45:20 +02:00
|
|
|
#include "common/common_funcs.h"
|
2018-01-15 03:29:11 +01:00
|
|
|
#include "common/logging/log.h"
|
2018-09-12 03:45:20 +02:00
|
|
|
#include "common/swap.h"
|
2018-07-27 04:35:23 +02:00
|
|
|
#include "core/core.h"
|
2018-01-15 03:29:11 +01:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
#include "core/hle/kernel/event.h"
|
2018-01-22 04:03:36 +01:00
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
2018-01-15 03:29:11 +01:00
|
|
|
#include "core/hle/service/audio/audout_u.h"
|
2018-09-12 03:45:20 +02:00
|
|
|
#include "core/memory.h"
|
2018-01-15 03:29:11 +01:00
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
namespace Service::Audio {
|
2018-01-15 03:29:11 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
namespace ErrCodes {
|
|
|
|
enum {
|
|
|
|
ErrorUnknown = 2,
|
|
|
|
BufferCountExceeded = 8,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr std::array<char, 10> DefaultDevice{{"DeviceOut"}};
|
|
|
|
constexpr int DefaultSampleRate{48000};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-09-12 03:45:20 +02:00
|
|
|
struct AudoutParams {
|
|
|
|
s32_le sample_rate;
|
|
|
|
u16_le channel_count;
|
|
|
|
INSERT_PADDING_BYTES(2);
|
|
|
|
};
|
|
|
|
static_assert(sizeof(AudoutParams) == 0x8, "AudoutParams is an invalid size");
|
|
|
|
|
|
|
|
enum class AudioState : u32 {
|
|
|
|
Started,
|
|
|
|
Stopped,
|
|
|
|
};
|
|
|
|
|
2018-01-22 04:03:36 +01:00
|
|
|
class IAudioOut final : public ServiceFramework<IAudioOut> {
|
|
|
|
public:
|
2018-07-28 19:27:59 +02:00
|
|
|
IAudioOut(AudoutParams audio_params, AudioCore::AudioOut& audio_core)
|
2018-08-14 00:23:55 +02:00
|
|
|
: ServiceFramework("IAudioOut"), audio_core(audio_core), audio_params(audio_params) {
|
2018-07-27 04:35:23 +02:00
|
|
|
|
2018-01-22 04:03:36 +01:00
|
|
|
static const FunctionInfo functions[] = {
|
2018-04-10 17:51:50 +02:00
|
|
|
{0, &IAudioOut::GetAudioOutState, "GetAudioOutState"},
|
|
|
|
{1, &IAudioOut::StartAudioOut, "StartAudioOut"},
|
|
|
|
{2, &IAudioOut::StopAudioOut, "StopAudioOut"},
|
2018-07-12 08:57:31 +02:00
|
|
|
{3, &IAudioOut::AppendAudioOutBufferImpl, "AppendAudioOutBuffer"},
|
2018-04-10 17:51:50 +02:00
|
|
|
{4, &IAudioOut::RegisterBufferEvent, "RegisterBufferEvent"},
|
2018-07-12 08:57:31 +02:00
|
|
|
{5, &IAudioOut::GetReleasedAudioOutBufferImpl, "GetReleasedAudioOutBuffer"},
|
2018-07-27 04:35:23 +02:00
|
|
|
{6, &IAudioOut::ContainsAudioOutBuffer, "ContainsAudioOutBuffer"},
|
2018-07-12 08:57:31 +02:00
|
|
|
{7, &IAudioOut::AppendAudioOutBufferImpl, "AppendAudioOutBufferAuto"},
|
|
|
|
{8, &IAudioOut::GetReleasedAudioOutBufferImpl, "GetReleasedAudioOutBufferAuto"},
|
2018-07-27 04:35:23 +02:00
|
|
|
{9, &IAudioOut::GetAudioOutBufferCount, "GetAudioOutBufferCount"},
|
2018-04-10 17:51:50 +02:00
|
|
|
{10, nullptr, "GetAudioOutPlayedSampleCount"},
|
|
|
|
{11, nullptr, "FlushAudioOutBuffers"},
|
2018-01-22 04:03:36 +01:00
|
|
|
};
|
|
|
|
RegisterHandlers(functions);
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
|
|
|
// This is the event handle used to check if the audio buffer was released
|
2018-08-28 18:30:33 +02:00
|
|
|
auto& kernel = Core::System::GetInstance().Kernel();
|
|
|
|
buffer_event =
|
|
|
|
Kernel::Event::Create(kernel, Kernel::ResetType::Sticky, "IAudioOutBufferReleased");
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count,
|
2018-08-03 00:27:22 +02:00
|
|
|
"IAudioOut", [=]() { buffer_event->Signal(); });
|
2018-03-04 16:34:25 +01:00
|
|
|
}
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
|
|
|
private:
|
2018-07-27 04:35:23 +02:00
|
|
|
struct AudioBuffer {
|
|
|
|
u64_le next;
|
|
|
|
u64_le buffer;
|
|
|
|
u64_le buffer_capacity;
|
|
|
|
u64_le buffer_size;
|
|
|
|
u64_le offset;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(AudioBuffer) == 0x28, "AudioBuffer is an invalid size");
|
|
|
|
|
2018-04-03 05:31:29 +02:00
|
|
|
void GetAudioOutState(Kernel::HLERequestContext& ctx) {
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
2018-04-03 05:31:29 +02:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-07-27 04:35:23 +02:00
|
|
|
rb.Push(static_cast<u32>(stream->IsPlaying() ? AudioState::Started : AudioState::Stopped));
|
2018-04-03 05:31:29 +02:00
|
|
|
}
|
|
|
|
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
void StartAudioOut(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
|
|
|
|
|
|
|
if (stream->IsPlaying()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ResultCode(ErrorModule::Audio, ErrCodes::ErrorUnknown));
|
|
|
|
return;
|
|
|
|
}
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
audio_core.StartStream(stream);
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StopAudioOut(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
audio_core.StopStream(stream);
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterBufferEvent(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.PushCopyObjects(buffer_event);
|
|
|
|
}
|
|
|
|
|
2018-07-12 08:57:31 +02:00
|
|
|
void AppendAudioOutBufferImpl(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "(STUBBED) called {}", ctx.Description());
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
const auto& input_buffer{ctx.ReadBuffer()};
|
|
|
|
ASSERT_MSG(input_buffer.size() == sizeof(AudioBuffer),
|
|
|
|
"AudioBuffer input is an invalid size!");
|
|
|
|
AudioBuffer audio_buffer{};
|
|
|
|
std::memcpy(&audio_buffer, input_buffer.data(), sizeof(AudioBuffer));
|
|
|
|
const u64 tag{rp.Pop<u64>()};
|
|
|
|
|
2018-08-04 06:03:12 +02:00
|
|
|
std::vector<s16> samples(audio_buffer.buffer_size / sizeof(s16));
|
|
|
|
Memory::ReadBlock(audio_buffer.buffer, samples.data(), audio_buffer.buffer_size);
|
2018-07-27 04:35:23 +02:00
|
|
|
|
2018-08-04 06:03:12 +02:00
|
|
|
if (!audio_core.QueueBuffer(stream, tag, std::move(samples))) {
|
2018-07-27 04:35:23 +02:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ResultCode(ErrorModule::Audio, ErrCodes::BufferCountExceeded));
|
|
|
|
}
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-07-12 08:57:31 +02:00
|
|
|
void GetReleasedAudioOutBufferImpl(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called {}", ctx.Description());
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const u64 max_count{ctx.GetWriteBufferSize() / sizeof(u64)};
|
|
|
|
const auto released_buffers{audio_core.GetTagsAndReleaseBuffers(stream, max_count)};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
std::vector<u64> tags{released_buffers};
|
|
|
|
tags.resize(max_count);
|
|
|
|
ctx.WriteBuffer(tags);
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-07-27 04:35:23 +02:00
|
|
|
rb.Push<u32>(static_cast<u32>(released_buffers.size()));
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
void ContainsAudioOutBuffer(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const u64 tag{rp.Pop<u64>()};
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push(stream->ContainsBuffer(tag));
|
|
|
|
}
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
void GetAudioOutBufferCount(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push(static_cast<u32>(stream->GetQueueSize()));
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
}
|
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
AudioCore::AudioOut& audio_core;
|
|
|
|
AudioCore::StreamPtr stream;
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
AudoutParams audio_params{};
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
|
|
|
/// This is the evend handle used to check if the audio buffer was released
|
|
|
|
Kernel::SharedPtr<Kernel::Event> buffer_event;
|
2018-01-22 04:03:36 +01:00
|
|
|
};
|
|
|
|
|
2018-07-12 08:57:31 +02:00
|
|
|
void AudOutU::ListAudioOutsImpl(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
2018-01-22 04:03:36 +01:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
ctx.WriteBuffer(DefaultDevice);
|
2018-01-22 04:03:36 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb = rp.MakeBuilder(3, 0, 0);
|
2018-01-22 04:03:36 +01:00
|
|
|
|
2018-01-15 03:29:11 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-07-27 04:35:23 +02:00
|
|
|
rb.Push<u32>(1); // Amount of audio devices
|
2018-01-15 03:29:11 +01:00
|
|
|
}
|
|
|
|
|
2018-07-12 08:57:31 +02:00
|
|
|
void AudOutU::OpenAudioOutImpl(Kernel::HLERequestContext& ctx) {
|
2018-07-27 04:35:23 +02:00
|
|
|
LOG_DEBUG(Service_Audio, "called");
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
|
2018-07-27 04:35:23 +02:00
|
|
|
ctx.WriteBuffer(DefaultDevice);
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
auto params{rp.PopRaw<AudoutParams>()};
|
|
|
|
if (params.channel_count <= 2) {
|
|
|
|
// Mono does not exist for audout
|
|
|
|
params.channel_count = 2;
|
|
|
|
} else {
|
|
|
|
params.channel_count = 6;
|
audout:u OpenAudioOut and IAudioOut (#138)
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* Updated the audout:u and IAudioOut, now it might work with RetroArch without trigger an assert, however it's not the ideal implementation
* audout:u OpenAudioOut implementation and IAudioOut cmd 1,2,3,4,5 implementation
* using an enum for audio_out_state as well as changing its initialize to member initializer list
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* Minor fixes, added Service_Audio for LOG_*, changed PcmFormat enum to EnumClass
* added missing Audio loggin subclass, minor fixes, clang comment breakline
* Solving backend logging conflict
* minor fix
* Fixed duplicated Service NVDRV in backend.cpp, my bad
2018-01-25 04:17:54 +01:00
|
|
|
}
|
2018-07-27 04:35:23 +02:00
|
|
|
if (!params.sample_rate) {
|
|
|
|
params.sample_rate = DefaultSampleRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(bunnei): Support more than one IAudioOut interface. When we add this, ListAudioOutsImpl
|
|
|
|
// will likely need to be updated as well.
|
|
|
|
ASSERT_MSG(!audio_out_interface, "Unimplemented");
|
2018-07-31 16:24:36 +02:00
|
|
|
audio_out_interface = std::make_shared<IAudioOut>(params, *audio_core);
|
2018-01-22 21:27:55 +01:00
|
|
|
|
2018-01-24 01:52:18 +01:00
|
|
|
IPC::ResponseBuilder rb{ctx, 6, 0, 1};
|
2018-01-22 21:27:55 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-07-27 04:35:23 +02:00
|
|
|
rb.Push<u32>(DefaultSampleRate);
|
|
|
|
rb.Push<u32>(params.channel_count);
|
2018-08-03 21:30:01 +02:00
|
|
|
rb.Push<u32>(static_cast<u32>(AudioCore::Codec::PcmFormat::Int16));
|
2018-07-27 04:35:23 +02:00
|
|
|
rb.Push<u32>(static_cast<u32>(AudioState::Stopped));
|
2018-01-25 04:38:19 +01:00
|
|
|
rb.PushIpcInterface<Audio::IAudioOut>(audio_out_interface);
|
2018-01-22 21:27:55 +01:00
|
|
|
}
|
|
|
|
|
2018-01-15 03:29:11 +01:00
|
|
|
AudOutU::AudOutU() : ServiceFramework("audout:u") {
|
2018-07-12 08:57:31 +02:00
|
|
|
static const FunctionInfo functions[] = {{0, &AudOutU::ListAudioOutsImpl, "ListAudioOuts"},
|
|
|
|
{1, &AudOutU::OpenAudioOutImpl, "OpenAudioOut"},
|
|
|
|
{2, &AudOutU::ListAudioOutsImpl, "ListAudioOutsAuto"},
|
|
|
|
{3, &AudOutU::OpenAudioOutImpl, "OpenAudioOutAuto"}};
|
2018-01-15 03:29:11 +01:00
|
|
|
RegisterHandlers(functions);
|
2018-07-28 19:27:59 +02:00
|
|
|
audio_core = std::make_unique<AudioCore::AudioOut>();
|
2018-01-15 03:29:11 +01:00
|
|
|
}
|
|
|
|
|
hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.
The cause of the above mentioned non-obvious errors can be demonstrated
as follows:
------- Demonstrative example, if you know how the described error happens, skip forwards -------
Assume we have the following in the header, which we'll call "thing.h":
\#include <memory>
// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;
class Thing {
public:
// assume no constructors or destructors are specified here,
// or the constructors/destructors are defined as:
//
// Thing() = default;
// ~Thing() = default;
//
// ... Some interface member functions would be defined here
private:
std::shared_ptr<Object> obj;
};
If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:
1. Decrement the shared reference count of the object being pointed to,
and if the reference count decrements to zero,
2. Free the Object instance's memory (aka deallocate the memory it's
pointing to).
And so the compiler generates the code for the destructor doing this inside main.cpp.
Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.
Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.
---------------------- End example ----------------------------
Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-11 03:20:52 +02:00
|
|
|
AudOutU::~AudOutU() = default;
|
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
} // namespace Service::Audio
|