VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
vae_source_loader.hpp
Go to the documentation of this file.
1#ifndef _VAE_SOURCE_LOADER
2#define _VAE_SOURCE_LOADER
3
4#include "../vae_types.hpp"
5#include "../vae_config.hpp"
6#include "../vae_util.hpp"
7#include "../pod/vae_source.hpp"
8
9#ifndef VAE_NO_WAV
10 #include "../../../external/tklb/src/types/audio/TWaveFile.hpp"
11#endif
12#include "../../../external/tklb/src/types/audio/TOggFile.hpp"
13
14#include "../../wrapped/vae_fs.hpp"
15
16namespace vae { namespace core {
17 struct SourceLoader {
18 /**
19 * @brief Loads a wav file for the resource
20 * @param s
21 * @param path
22 * @return Result
23 */
24 Result load(Source& s, const char* path) {
25 String joinedPath;
26 const char* data = s.path.c_str();
27 Size length = 0;
28 if (!s.raw) {
29 joinedPath = path;
30 joinedPath.append(s.path);
31 data = joinedPath.c_str();
32 #ifdef VAE_NO_STDIO
33 fs::File file(data);
34 length = file.size();
35 joinedPath.reserve(length);
36 if (!file.readAll(joinedPath.data())) { return Result::FileOpenError; }
37 data = joinedPath.data();
38 #endif
39 } else {
40 length = s.path.size();
41 }
42
43 if (!s.stream) {
44 if (s.format == Source::Format::wav) {
45 #ifdef VAE_NO_WAV
47 #else
48 VAE_PROFILER_SCOPE_NAMED("Load wav")
49 bool success = tklb::wave::load<Sample, AudioBuffer>(data, s.signal, length);
50 return success ? Result::Success : Result::GenericFailure;
51 #endif
52 } else if (s.format == Source::Format::ogg) {
53 VAE_PROFILER_SCOPE_NAMED("Load ogg")
54 auto result = tklb::ogg::load<Sample, AudioBuffer>(data, s.signal, length);
56 }
57 return Result::GenericFailure; // what format is this?
58 }
59 // TODO STREAM
61 }
62 };
63} } // vae::core
64
65
66#endif // _VAE_SOURCE_LOADER
void reserve(Size size)
Definition: TString.hpp:133
const char * c_str() const
Definition: TString.hpp:83
Size size() const
Definition: TString.hpp:86
void append(const String &str)
Definition: TString.hpp:102
char * data()
Definition: TString.hpp:89
bool readAll(char *dest)
Definition: vae_fs.hpp:72
Contains Typedefinitions and basic structures use by the public API and internally.
Definition: vae.hpp:31
unsigned int Size
How the elements are addressed in the heapbuffer.
Definition: vae.hpp:33
Result
Return Types for most engine functions.
Definition: vae.hpp:73
@ FileOpenError
File system could not load file.
@ GenericFailure
:(
AudioBuffer signal
Audio signal itself loaded by SourceLoader.
Definition: vae_source.hpp:21
bool stream
If false entire sample will be loaded in ram, there's no streaming for now.
Definition: vae_source.hpp:11
@ ogg
Uses stb_vorbis to decode oggs.
@ wav
Uses dr_wav to decode wavs.
PathString path
Filesystem path.
Definition: vae_source.hpp:22
enum vae::core::Source::Format format
bool raw
The data in path is a data buffer.
Definition: vae_source.hpp:13
Result load(Source &s, const char *path)
Loads a wav file for the resource.
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.