1#ifndef YAZE_ZELDA3_MUSIC_SPC_PARSER_H
2#define YAZE_ZELDA3_MUSIC_SPC_PARSER_H
7#include "absl/status/statusor.h"
70 static absl::StatusOr<MusicSong>
ParseSong(
Rom& rom, uint16_t address,
82 Rom& rom, uint16_t table_address, uint8_t bank,
int max_entries = 40);
92 static absl::StatusOr<MusicTrack>
ParseTrack(
Rom& rom, uint16_t address,
94 int max_ticks = 50000);
118 static const uint8_t*
GetSpcData(
Rom& rom, uint16_t spc_address,
119 uint8_t bank,
int* out_length =
nullptr);
131 if (opcode < 0xE0)
return 0;
166 int remaining_ticks);
197 uint16_t base_address);
224 uint8_t* current_duration);
239 uint16_t new_base_address);
255 static std::vector<int16_t>
Decode(
const std::vector<uint8_t>& brr_data,
256 int* loop_start =
nullptr);
264 static std::vector<uint8_t>
Encode(
const std::vector<int16_t>& pcm_data,
265 int loop_start = -1);
269 static constexpr int kFilter1[4] = {0, 15, 61, 115};
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
BRR sample encoder/decoder.
static constexpr int kFilter2[4]
static std::vector< int16_t > Decode(const std::vector< uint8_t > &brr_data, int *loop_start=nullptr)
Decode BRR data to PCM samples.
static std::vector< uint8_t > Encode(const std::vector< int16_t > &pcm_data, int loop_start=-1)
Encode PCM samples to BRR format.
static constexpr int kFilter3[4]
static constexpr int kFilter1[4]
Parser for N-SPC music data from ROM.
static bool IsDuration(uint8_t byte)
Check if a byte is a duration value (< 128).
static bool IsCommand(uint8_t byte)
Check if a byte is a command opcode.
static absl::StatusOr< MusicSong > ParseSong(Rom &rom, uint16_t address, uint8_t bank)
Parse a complete song from ROM.
static bool IsNotePitch(uint8_t byte)
Check if a byte is a note pitch.
static absl::StatusOr< std::vector< uint16_t > > ReadSongPointerTable(Rom &rom, uint16_t table_address, uint8_t bank, int max_entries=40)
Read the song pointer table for a given SPC bank.
static const uint8_t * GetSpcData(Rom &rom, uint16_t spc_address, uint8_t bank, int *out_length=nullptr)
Get a pointer to ROM data at an SPC address.
static absl::StatusOr< MusicTrack > ParseTrackInternal(ParseContext &ctx, uint16_t address, int max_ticks)
static absl::StatusOr< int > ParseSubroutine(ParseContext &ctx, uint16_t address, int repeat_count, int remaining_ticks)
static absl::StatusOr< MusicTrack > ParseTrack(Rom &rom, uint16_t address, uint8_t bank, int max_ticks=50000)
Parse a single track from ROM.
static int GetCommandParamCount(uint8_t opcode)
Get the parameter count for an N-SPC command.
static uint32_t SpcAddressToRomOffset(Rom &rom, uint16_t spc_address, uint8_t bank)
Convert an SPC address to a ROM offset.
Serializer for N-SPC music data to ROM format.
static int CalculateRequiredSpace(const MusicSong &song)
Calculate the space required for a song.
static std::vector< uint8_t > SerializeNote(const Note ¬e, uint8_t *current_duration)
Serialize a note event.
static std::vector< uint8_t > SerializeCommand(const MusicCommand &command)
Serialize a command event.
static absl::StatusOr< SerializeResult > SerializeSong(const MusicSong &song, uint16_t base_address)
Serialize a complete song to binary format.
static void ApplyBaseAddress(SerializeResult *result, uint16_t new_base_address)
Adjust all serialized pointers to a new base address.
static std::vector< uint8_t > SerializeTrack(const MusicTrack &track)
Serialize a single track to binary format.
constexpr uint8_t kNoteRest
constexpr uint8_t kNoteMinPitch
constexpr int kCommandParamCount[32]
constexpr uint32_t kSoundBankOffsets[]
Represents an N-SPC command (opcodes 0xE0-0xFF).
A complete song composed of segments.
One of 8 channels in a music segment.
Represents a single musical note.
Context for parsing operations.
std::vector< uint16_t > visited_addresses
Result of serialization with relocation info.
std::vector< uint16_t > relocations
std::vector< uint8_t > data