Unravel Engine C++ Reference
Loading...
Searching...
No Matches
audio_clip.cpp
Go to the documentation of this file.
1#include "audio_clip.hpp"
2#include <audiopp/loaders/loader.h>
3#include <fstream>
7
8namespace audio
9{
10REFLECT_EXTERN(sound_info);
11REFLECT(sound_info)
12{
13 entt::meta_factory<sound_info>{}
14 .type("sound_info"_hs)
16 entt::attribute{"name", "sound_info"},
17 entt::attribute{"pretty_name", "Sound Info"},
18 })
19 .data<nullptr, &sound_info::bits_per_sample>("bytes_per_sample"_hs)
21 entt::attribute{"name", "bytes_per_sample"},
22 entt::attribute{"pretty_name", "Bits per sample"},
23 entt::attribute{"tooltip", "Bit depth."},
24 })
25 .data<nullptr, &sound_info::sample_rate>("sample_rate"_hs)
27 entt::attribute{"name", "sample_rate"},
28 entt::attribute{"pretty_name", "Sample rate"},
29 entt::attribute{"tooltip", "Sample rate."},
30 })
31 .data<nullptr, &sound_info::channels>("channels"_hs)
33 entt::attribute{"name", "channels"},
34 entt::attribute{"pretty_name", "Channels"},
35 entt::attribute{"tooltip", "Mono or Stereo."},
36 })
37 .data<nullptr, &sound_info::duration>("duration"_hs)
39 entt::attribute{"name", "duration"},
40 entt::attribute{"pretty_name", "Duration"},
41 entt::attribute{"tooltip", "Duration in seconds."},
42 })
43 .data<nullptr, &sound_info::frames>("frames"_hs)
45 entt::attribute{"name", "frames"},
46 entt::attribute{"pretty_name", "Frames"},
47 entt::attribute{"tooltip", "Fames count (samples per channel)."},
48 });
49}
50
51SAVE(audio::sound_info)
52{
53 try_save(ar, ser20::make_nvp("bits_per_sample", obj.bits_per_sample));
54 try_save(ar, ser20::make_nvp("sample_rate", obj.sample_rate));
55 try_save(ar, ser20::make_nvp("channels", obj.channels));
56 try_save(ar, ser20::make_nvp("duration", obj.duration));
57 try_save(ar, ser20::make_nvp("frames", obj.frames));
58}
59// SAVE_INSTANTIATE(sound_info, ser20::oarchive_binary_t);
60
61LOAD(audio::sound_info)
62{
63 try_load(ar, ser20::make_nvp("bits_per_sample", obj.bits_per_sample));
64 try_load(ar, ser20::make_nvp("sample_rate", obj.sample_rate));
65 try_load(ar, ser20::make_nvp("channels", obj.channels));
66 try_load(ar, ser20::make_nvp("duration", obj.duration));
67 try_load(ar, ser20::make_nvp("frames", obj.frames));
68}
69// LOAD_INSTANTIATE(sound_info, ser20::iarchive_binary_t);
70
71SAVE(audio::sound_data)
72{
73 try_save(ar, ser20::make_nvp("info", obj.info));
74 try_save(ar, ser20::make_nvp("data", obj.data));
75}
76// SAVE_INSTANTIATE(sound_data, ser20::oarchive_binary_t);
77
78LOAD(audio::sound_data)
79{
80 try_load(ar, ser20::make_nvp("info", obj.info));
81 try_load(ar, ser20::make_nvp("data", obj.data));
82}
83// LOAD_INSTANTIATE(sound_data, ser20::iarchive_binary_t);
84
85} // namespace audio
86
87namespace unravel
88{
89
91{
92 entt::meta_factory<audio_clip>{}
93 .type("audio_clip"_hs)
95 entt::attribute{"name", "audio_clip"},
96 entt::attribute{"pretty_name", "Audio Clip"},
97 })
98 .data<nullptr, &audio_clip::get_info>("info"_hs)
100 entt::attribute{"name", "info"},
101 entt::attribute{"pretty_name", "Info"},
102 });
103}
104
106{
107 // try_save(ar, ser20::make_nvp("info", obj.info));
108 // try_save(ar, ser20::make_nvp("data", obj.data));
109}
111
113{
114 // try_load(ar, ser20::make_nvp("info", obj.info));
115 // try_load(ar, ser20::make_nvp("data", obj.data));
116}
118
119void save_to_file(const std::string& absolute_path, const audio::sound_data& obj)
120{
121 // std::ofstream stream(absolute_path);
122 // if(stream.good())
123 // {
124 // auto ar = ser20::create_oarchive_associative(stream);
125 // try_save(ar, ser20::make_nvp("audio_clip", obj));
126 // }
127}
128
129void save_to_file_bin(const std::string& absolute_path, const audio::sound_data& obj)
130{
131 std::ofstream stream(absolute_path, std::ios::binary);
132 if(stream.good())
133 {
134 ser20::oarchive_binary_t ar(stream);
135 try_save(ar, ser20::make_nvp("sound_data", obj));
136 }
137}
138
139auto load_from_file(const std::string& absolute_path, audio::sound_data& obj, std::string& err) -> bool
140{
141 return audio::load_from_file(absolute_path, obj, err);
142
143 // std::ifstream stream(absolute_path);
144 // if(stream.good())
145 // {
146 // auto ar = ser20::create_iarchive_associative(stream);
147 // try_load(ar, ser20::make_nvp("audio_clip", obj));
148 // }
149}
150
151void load_from_file_bin(const std::string& absolute_path, audio::sound_data& obj)
152{
153 std::ifstream stream(absolute_path, std::ios::binary);
154 if(stream.good())
155 {
156 ser20::iarchive_binary_t ar(stream);
157 try_load(ar, ser20::make_nvp("sound_data", obj));
158 }
159}
160} // namespace unravel
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
BinaryOutputArchive oarchive_binary_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#define REFLECT_EXTERN(cls)
Definition reflection.h:120
#define REFLECT(cls)
Definition reflection.h:133
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Struct representing an audio clip.
Definition audio_clip.h:16