-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource mgr, loaders + std wave loader (improved)
- Loading branch information
Showing
26 changed files
with
581 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __DK_PAIR_H__ | ||
#define __DK_PAIR_H__ | ||
|
||
#include <utility> | ||
|
||
namespace dk | ||
{ | ||
|
||
template<typename FirstT, typename SecondT> | ||
using pair = std::pair<FirstT, SecondT>; | ||
|
||
} | ||
|
||
#endif // !__DK_PAIR_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef __DK_RESOURCE_GROUP_H__ | ||
#define __DK_RESOURCE_GROUP_H__ | ||
|
||
#include "resource.h" | ||
#include "containers/vector.h" | ||
#include "containers/hash_table.h" | ||
#include "containers/string_view.h" | ||
|
||
namespace dk | ||
{ | ||
|
||
class resource_group final: public resource | ||
{ | ||
private: | ||
hash_table<string_view, resource*> m_res_table; | ||
vector<resource*> m_resources; | ||
|
||
public: | ||
~resource_group() noexcept override; | ||
|
||
resource* operator[](string_view tag) const noexcept; | ||
|
||
bool is_exists(const resource* res) const noexcept; | ||
|
||
void add(resource* res) noexcept; | ||
void add(resource* res, string_view tag) noexcept; | ||
|
||
bool try_add(resource* res) noexcept; | ||
bool try_add(resource* res, string_view tag) noexcept; | ||
|
||
void remove(resource* res) noexcept; | ||
void remove(string_view tag) noexcept; | ||
void remove_all() noexcept; | ||
|
||
void destroy(resource* res) noexcept; | ||
void destroy(string_view tag) noexcept; | ||
void destroy_all() noexcept; | ||
}; | ||
|
||
} | ||
|
||
#endif // !__DK_RESOURCE_GROUP_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#ifndef __DK_SYS_WAVE_DATA_LOADER_H__ | ||
#define __DK_SYS_WAVE_DATA_LOADER_H__ | ||
|
||
#include "audio/sound_data.h" | ||
#include "sys/resource_loader.h" | ||
|
||
#define WAVE_CHUNK_ID(id) (id[0] + (id[1] << 8) + (id[2] << 16) + (id[3] << 24)) | ||
|
||
namespace dk::sys | ||
{ | ||
|
||
struct wave_header | ||
{ | ||
struct chunk_header | ||
{ | ||
uint32_t id; | ||
uint32_t size; | ||
}; | ||
|
||
struct RIFF_chunk | ||
{ | ||
static constexpr uint32_t id = WAVE_CHUNK_ID("RIFF"); /* 0x46464952 */ | ||
static constexpr uint32_t WAVE_format = WAVE_CHUNK_ID("WAVE"); /* 0x45564157 */ | ||
uint32_t format; | ||
}; | ||
|
||
struct LIST_chunk | ||
{ | ||
static constexpr uint32_t id = WAVE_CHUNK_ID("LIST"); /* 0x5453494C */ | ||
static constexpr uint32_t INFO_type = WAVE_CHUNK_ID("INFO"); /* 0x4F464E49 */ | ||
|
||
/* sub chunk ids */ | ||
static constexpr uint32_t artist_info = WAVE_CHUNK_ID("IART"); | ||
static constexpr uint32_t comments_info = WAVE_CHUNK_ID("ICMT"); | ||
static constexpr uint32_t copyright_info = WAVE_CHUNK_ID("ICOP"); | ||
static constexpr uint32_t creation_date_info = WAVE_CHUNK_ID("ICRD"); | ||
static constexpr uint32_t name_info = WAVE_CHUNK_ID("INAM"); | ||
static constexpr uint32_t product_info = WAVE_CHUNK_ID("IPRD"); | ||
static constexpr uint32_t software_info = WAVE_CHUNK_ID("ISFT"); | ||
|
||
uint32_t type; | ||
}; | ||
|
||
struct fmt_chunk | ||
{ | ||
static constexpr uint32_t id = WAVE_CHUNK_ID("fmt "); /* 0x20746D66 */ | ||
|
||
uint16_t audio_fmt; /* PCM = 1 */ | ||
uint16_t num_channels; /* mono = 1, stereo = 2, ... */ | ||
uint32_t sample_rate; /* 8000, 44100, ... */ | ||
uint32_t byte_rate; /* sample_rate * num_channels * bits_per_sample / 8 */ | ||
uint16_t block_align; /* num_channels * bits_per_sample / 8 */ | ||
uint16_t bits_per_sample; /* 8, 16, ... */ | ||
}; | ||
|
||
struct data_chunk | ||
{ | ||
/* size = num_samples (yeah, samples) * num_channels * bits_per_sample / 8 */ | ||
static constexpr uint32_t id = WAVE_CHUNK_ID("data"); /* 0x61746164 */ | ||
}; | ||
|
||
static size_t align_chunk(size_t size) noexcept | ||
{ | ||
return size + (size & 1); /* every chunk must me aligned by 16-bit boundaries */ | ||
} | ||
}; | ||
|
||
class wave_loader final: public resource_loader | ||
{ | ||
public: | ||
status load(string_view file_path, audio::sound_data& res) noexcept; | ||
|
||
resource* load(string_view file_path, resource_type type) noexcept override; | ||
}; | ||
|
||
} | ||
|
||
#endif // !__DK_SYS_WAVE_DATA_LOADER_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.