43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#pragma once
|
|
#include "core/inflate.h"
|
|
#include <cstdint>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <optional>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace playground {
|
|
|
|
enum class CadiKind { OggVorbis, Xml };
|
|
enum class CadiChannel { Sfx, Music, Environment };
|
|
struct CadiEventInfo {
|
|
std::vector<size_t> clips;
|
|
CadiChannel channel = CadiChannel::Sfx;
|
|
bool loop = false;
|
|
};
|
|
struct CadiRecord {
|
|
uint32_t token = 0; // opaque bank index value
|
|
uint32_t offset = 0;
|
|
uint32_t size = 0;
|
|
CadiKind kind = CadiKind::OggVorbis;
|
|
};
|
|
|
|
// Read-only parser for a caller-supplied CADI audio bank.
|
|
class CadiBank {
|
|
public:
|
|
bool load(Bytes bytes, std::string* error = nullptr);
|
|
const std::vector<CadiRecord>& records() const { return records_; }
|
|
std::span<const uint8_t> data(size_t index) const;
|
|
std::optional<size_t> clipForEvent(std::string_view event) const;
|
|
std::vector<size_t> clipsForEvent(std::string_view event) const;
|
|
std::optional<CadiEventInfo> eventInfo(std::string_view event) const;
|
|
size_t mappedEventCount() const { return eventClips_.size(); }
|
|
private:
|
|
Bytes bytes_;
|
|
std::vector<CadiRecord> records_;
|
|
std::unordered_map<std::string,CadiEventInfo> eventClips_;
|
|
};
|
|
|
|
} // namespace playground
|