minor refactor + fix
This commit is contained in:
parent
90a4922201
commit
5657457edb
@ -10,12 +10,19 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace audio {
|
||||
/// @brief playing speaker uid
|
||||
using speakerid_t = int64_t;
|
||||
/// @brief duration unit is second
|
||||
|
||||
/// @brief duration unit is a second
|
||||
using duration_t = double;
|
||||
|
||||
/// @brief not important sounds (steps, random noises)
|
||||
constexpr inline int PRIORITY_LOW = 0;
|
||||
|
||||
/// @brief default sounds priority
|
||||
constexpr inline int PRIORITY_NORMAL = 5;
|
||||
|
||||
/// @brief streams and important sounds
|
||||
constexpr inline int PRIORITY_HIGH = 10;
|
||||
|
||||
class Speaker;
|
||||
@ -31,10 +38,16 @@ namespace audio {
|
||||
struct PCM {
|
||||
/// @brief May contain 8 bit and 16 bit PCM data
|
||||
std::vector<char> data;
|
||||
/// @brief Total number of mono samples (sampleRate per second)
|
||||
size_t totalSamples;
|
||||
/// @brief Track channels number (1 - mono, 2 - stereo)
|
||||
uint8_t channels;
|
||||
/// @brief Sample bit depth (8 and 16 supported)
|
||||
/// does not depend on the channels number
|
||||
uint8_t bitsPerSample;
|
||||
/// @brief Number of mono samples per second (example: 44100)
|
||||
uint sampleRate;
|
||||
/// @brief Audio source is seekable
|
||||
bool seekable;
|
||||
|
||||
PCM(
|
||||
@ -51,12 +64,8 @@ namespace audio {
|
||||
sampleRate(sampleRate),
|
||||
seekable(seekable) {}
|
||||
|
||||
inline size_t countSamplesMono() const {
|
||||
return totalSamples / channels;
|
||||
}
|
||||
|
||||
inline duration_t getDuration() const {
|
||||
return static_cast<duration_t>(countSamplesMono()) /
|
||||
return static_cast<duration_t>(totalSamples) /
|
||||
static_cast<duration_t>(sampleRate);
|
||||
}
|
||||
};
|
||||
@ -142,7 +151,7 @@ namespace audio {
|
||||
};
|
||||
|
||||
/// @brief Sound is an audio asset that supposed to support many
|
||||
/// simultaneously playing instances with different sources.
|
||||
/// simultaneously playing instances (speakers).
|
||||
/// So it's audio data is stored in memory.
|
||||
class Sound {
|
||||
public:
|
||||
|
||||
@ -53,7 +53,7 @@ audio::PCM* ogg::load_pcm(const std::filesystem::path& file, bool headerOnly) {
|
||||
data.insert(data.end(), std::begin(buffer), std::begin(buffer)+ret);
|
||||
}
|
||||
}
|
||||
totalSamples = data.size();
|
||||
totalSamples = data.size() / channels / 2;
|
||||
}
|
||||
ov_clear(&vf);
|
||||
return new PCM(std::move(data), totalSamples, channels, 16, sampleRate, seekable);
|
||||
|
||||
@ -5,33 +5,33 @@
|
||||
#include <string>
|
||||
#include "typedefs.h"
|
||||
|
||||
const int ENGINE_VERSION_MAJOR = 0;
|
||||
const int ENGINE_VERSION_MINOR = 20;
|
||||
const bool ENGINE_VERSION_INDEV = true;
|
||||
inline constexpr int ENGINE_VERSION_MAJOR = 0;
|
||||
inline constexpr int ENGINE_VERSION_MINOR = 20;
|
||||
inline constexpr bool ENGINE_VERSION_INDEV = true;
|
||||
#define ENGINE_VERSION_STRING "0.20"
|
||||
|
||||
const int BLOCK_AIR = 0;
|
||||
const int ITEM_EMPTY = 0;
|
||||
inline constexpr int BLOCK_AIR = 0;
|
||||
inline constexpr int ITEM_EMPTY = 0;
|
||||
|
||||
const int CHUNK_W = 16;
|
||||
const int CHUNK_H = 256;
|
||||
const int CHUNK_D = 16;
|
||||
inline constexpr int CHUNK_W = 16;
|
||||
inline constexpr int CHUNK_H = 256;
|
||||
inline constexpr int CHUNK_D = 16;
|
||||
|
||||
const uint VOXEL_USER_BITS = 8;
|
||||
constexpr uint VOXEL_USER_BITS_OFFSET = sizeof(blockstate_t)*8-VOXEL_USER_BITS;
|
||||
inline constexpr uint VOXEL_USER_BITS = 8;
|
||||
inline constexpr uint VOXEL_USER_BITS_OFFSET = sizeof(blockstate_t)*8-VOXEL_USER_BITS;
|
||||
|
||||
const int ITEM_ICON_SIZE = 48;
|
||||
inline constexpr int ITEM_ICON_SIZE = 48;
|
||||
|
||||
/* Chunk volume (count of voxels per Chunk) */
|
||||
constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D);
|
||||
inline constexpr int CHUNK_VOL = (CHUNK_W * CHUNK_H * CHUNK_D);
|
||||
|
||||
/* BLOCK_VOID is block id used to mark non-existing voxel (voxel of missing chunk) */
|
||||
const blockid_t BLOCK_VOID = std::numeric_limits<blockid_t>::max();
|
||||
const itemid_t ITEM_VOID = std::numeric_limits<itemid_t>::max();
|
||||
inline constexpr blockid_t BLOCK_VOID = std::numeric_limits<blockid_t>::max();
|
||||
inline constexpr itemid_t ITEM_VOID = std::numeric_limits<itemid_t>::max();
|
||||
|
||||
const blockid_t MAX_BLOCKS = BLOCK_VOID;
|
||||
inline constexpr blockid_t MAX_BLOCKS = BLOCK_VOID;
|
||||
|
||||
constexpr uint vox_index(uint x, uint y, uint z, uint w=CHUNK_W, uint d=CHUNK_D) {
|
||||
inline constexpr uint vox_index(uint x, uint y, uint z, uint w=CHUNK_W, uint d=CHUNK_D) {
|
||||
return (y * d + z) * w + x;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user