XT-Audio
XtAudio.hpp
Go to the documentation of this file.
1 #ifndef XT_API_AUDIO_HPP
2 #define XT_API_AUDIO_HPP
3 
6 #include <xt/cpp/Core.hpp>
7 #include <xt/cpp/Error.hpp>
8 #include <xt/api/Structs.hpp>
9 #include <xt/api/XtService.hpp>
10 #include <xt/api/XtPlatform.hpp>
11 
12 #include <memory>
13 #include <vector>
14 #include <string>
17 namespace Xt {
18 
19 using namespace Detail;
20 
21 class Audio final
22 {
23  Audio() = default;
24 public:
25  static Version GetVersion();
26  static void SetOnError(OnError onError);
27  static ErrorInfo GetErrorInfo(uint64_t error);
28  static Attributes GetSampleAttributes(Sample sample);
29  static std::unique_ptr<Platform> Init(std::string const& id, void* window);
30 };
31 
32 inline Version
34 {
35  auto result = Detail::HandleAssert(XtAudioGetVersion());
36  return *reinterpret_cast<Version*>(&result);
37 }
38 
39 inline ErrorInfo
40 Audio::GetErrorInfo(uint64_t error)
41 {
42  ErrorInfo result;
43  auto info = Detail::HandleAssert(XtAudioGetErrorInfo(error));
44  result.fault = info.fault;
45  result.system = static_cast<System>(info.system);
46  result.service.text = std::string(info.service.text);
47  result.service.cause = static_cast<Cause>(info.service.cause);
48  return result;
49 }
50 
51 inline Attributes
53 {
54  Attributes result;
55  auto coreSample = static_cast<XtSample>(sample);
56  auto attrs = Detail::HandleAssert(XtAudioGetSampleAttributes(coreSample));
57  result.size = attrs.size;
58  result.count = attrs.count;
59  result.isFloat = attrs.isFloat != XtFalse;
60  result.isSigned = attrs.isSigned != XtFalse;
61  return result;
62 }
63 
64 inline std::unique_ptr<Platform>
65 Audio::Init(std::string const& id, void* window)
66 {
67  XtPlatform* result = Detail::HandleAssert(XtAudioInit(id.c_str(), window));
68  return std::unique_ptr<Platform>(new Platform(result));
69 }
70 
71 inline void
73 {
74  Detail::_onError = onError;
75  XtOnError coreOnError = onError == nullptr? nullptr: &Detail::ForwardOnError;
76  Detail::HandleAssert(XtAudioSetOnError, coreOnError);
77 }
78 
79 } // namespace Xt
80 #endif // XT_API_AUDIO_HPP
ServiceError service
Definition: Structs.hpp:47
std::string text
Definition: Structs.hpp:40
Cause cause
Definition: Structs.hpp:39
Definition: Structs.hpp:31
Cause
Definition: Enums.hpp:10
System system
Definition: Structs.hpp:46
int32_t size
Definition: Structs.hpp:59
static std::unique_ptr< Platform > Init(std::string const &id, void *window)
Definition: XtAudio.hpp:65
Definition: Structs.hpp:57
void(* OnError)(std::string const &message)
Definition: Callbacks.hpp:13
int32_t count
Definition: Structs.hpp:60
Definition: XtAudio.hpp:21
static ErrorInfo GetErrorInfo(uint64_t error)
Definition: XtAudio.hpp:40
static Attributes GetSampleAttributes(Sample sample)
Definition: XtAudio.hpp:52
bool isSigned
Definition: Structs.hpp:62
bool isFloat
Definition: Structs.hpp:61
Definition: Structs.hpp:43
Definition: XtPlatform.hpp:19
static void SetOnError(OnError onError)
Definition: XtAudio.hpp:72
Definition: Callbacks.hpp:10
Sample
Definition: Enums.hpp:9
System
Definition: Enums.hpp:11
uint32_t fault
Definition: Structs.hpp:45
static Version GetVersion()
Definition: XtAudio.hpp:33