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>
8
9namespace audio
10{
11REFLECT_EXTERN(sound_info);
12REFLECT(sound_info)
13{
14 entt::meta_factory<sound_info>{}
15 .type("sound_info"_hs)
17 entt::attribute{"name", "sound_info"},
18 entt::attribute{"pretty_name", "Sound Info"},
19 })
20 .data<nullptr, &sound_info::bits_per_sample>("bytes_per_sample"_hs)
22 entt::attribute{"name", "bytes_per_sample"},
23 entt::attribute{"pretty_name", "Bits per sample"},
24 entt::attribute{"tooltip", "Bit depth."},
25 })
26 .data<nullptr, &sound_info::sample_rate>("sample_rate"_hs)
28 entt::attribute{"name", "sample_rate"},
29 entt::attribute{"pretty_name", "Sample rate"},
30 entt::attribute{"tooltip", "Sample rate."},
31 })
32 .data<nullptr, &sound_info::channels>("channels"_hs)
34 entt::attribute{"name", "channels"},
35 entt::attribute{"pretty_name", "Channels"},
36 entt::attribute{"tooltip", "Mono or Stereo."},
37 })
38 .data<nullptr, &sound_info::duration>("duration"_hs)
40 entt::attribute{"name", "duration"},
41 entt::attribute{"pretty_name", "Duration"},
42 entt::attribute{"tooltip", "Duration in seconds."},
43 })
44 .data<nullptr, &sound_info::frames>("frames"_hs)
46 entt::attribute{"name", "frames"},
47 entt::attribute{"pretty_name", "Frames"},
48 entt::attribute{"tooltip", "Fames count (samples per channel)."},
49 });
50}
51
52SAVE(audio::sound_info)
53{
54 try_save(ar, ser20::make_nvp("bits_per_sample", obj.bits_per_sample));
55 try_save(ar, ser20::make_nvp("sample_rate", obj.sample_rate));
56 try_save(ar, ser20::make_nvp("channels", obj.channels));
57 try_save(ar, ser20::make_nvp("duration", obj.duration));
58 try_save(ar, ser20::make_nvp("frames", obj.frames));
59}
60// SAVE_INSTANTIATE(sound_info, ser20::oarchive_binary_t);
61
62LOAD(audio::sound_info)
63{
64 try_load(ar, ser20::make_nvp("bits_per_sample", obj.bits_per_sample));
65 try_load(ar, ser20::make_nvp("sample_rate", obj.sample_rate));
66 try_load(ar, ser20::make_nvp("channels", obj.channels));
67 try_load(ar, ser20::make_nvp("duration", obj.duration));
68 try_load(ar, ser20::make_nvp("frames", obj.frames));
69}
70// LOAD_INSTANTIATE(sound_info, ser20::iarchive_binary_t);
71
72SAVE(audio::sound_data)
73{
74 try_save(ar, ser20::make_nvp("info", obj.info));
75 try_save(ar, ser20::make_nvp("data", obj.data));
76
77 // Changes here should be reflected in ex::get_format_version<audio_clip>() in asset_extensions.h
78}
79// SAVE_INSTANTIATE(sound_data, ser20::oarchive_binary_t);
80
81LOAD(audio::sound_data)
82{
83 try_load(ar, ser20::make_nvp("info", obj.info));
84 try_load(ar, ser20::make_nvp("data", obj.data));
85
86 // Changes here should be reflected in ex::get_format_version<audio_clip>() in asset_extensions.h
87}
88// LOAD_INSTANTIATE(sound_data, ser20::iarchive_binary_t);
89
90} // namespace audio
91
92namespace unravel
93{
94
96{
97 entt::meta_factory<audio_clip>{}
98 .type("audio_clip"_hs)
100 entt::attribute{"name", "audio_clip"},
101 entt::attribute{"pretty_name", "Audio Clip"},
102 })
103 .data<nullptr, &audio_clip::get_info>("info"_hs)
105 entt::attribute{"name", "info"},
106 entt::attribute{"pretty_name", "Info"},
107 });
108}
109
111{
112 // try_save(ar, ser20::make_nvp("info", obj.info));
113 // try_save(ar, ser20::make_nvp("data", obj.data));
114}
116
118{
119 // try_load(ar, ser20::make_nvp("info", obj.info));
120 // try_load(ar, ser20::make_nvp("data", obj.data));
121}
123
124void save_to_file(const std::string& absolute_path, const audio::sound_data& obj)
125{
126 // std::ofstream stream(absolute_path);
127 // if(stream.good())
128 // {
129 // auto ar = ser20::create_oarchive_associative(stream);
130 // try_save(ar, ser20::make_nvp("audio_clip", obj));
131 // }
132}
133
134void save_to_file_bin(const std::string& absolute_path, const audio::sound_data& obj)
135{
136 std::ofstream stream(absolute_path, std::ios::binary);
137 if(stream.good())
138 {
139 ser20::oarchive_binary_t ar(stream);
140 try_save(ar, ser20::make_nvp("sound_data", obj));
141 }
142}
143
144auto load_from_file(const std::string& absolute_path, audio::sound_data& obj, std::string& err) -> bool
145{
146 return audio::load_from_file(absolute_path, obj, err);
147
148 // std::ifstream stream(absolute_path);
149 // if(stream.good())
150 // {
151 // auto ar = ser20::create_iarchive_associative(stream);
152 // try_load(ar, ser20::make_nvp("audio_clip", obj));
153 // }
154}
155
156void load_from_file_bin(const std::string& absolute_path, audio::sound_data& obj)
157{
158 fs::file_istream input(absolute_path);
159 if(!input.is_open())
160 {
161 return;
162 }
164 try_load(ar, ser20::make_nvp("sound_data", obj));
165}
166} // namespace unravel
stdio-backed input stream. Accepts std::ios open flags (e.g. std::ios::binary) when opening a
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:136
#define REFLECT(cls)
Definition reflection.h:149
#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