yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::zelda3::music::SpcSerializer Class Reference

Serializer for N-SPC music data to ROM format. More...

#include <spc_parser.h>

Classes

struct  SerializeOptions
 Serialization options. More...
 
struct  SerializeResult
 Result of serialization with relocation info. More...
 

Public Member Functions

 SpcSerializer ()=default
 
 ~SpcSerializer ()=default
 

Static Public Member Functions

static absl::StatusOr< SerializeResultSerializeSong (const MusicSong &song, uint16_t base_address)
 Serialize a complete song to binary format.
 
static std::vector< uint8_t > SerializeTrack (const MusicTrack &track)
 Serialize a single track to binary format.
 
static int CalculateRequiredSpace (const MusicSong &song)
 Calculate the space required for a song.
 
static std::vector< uint8_t > SerializeNote (const Note &note, uint8_t *current_duration)
 Serialize a note event.
 
static std::vector< uint8_t > SerializeCommand (const MusicCommand &command)
 Serialize a command event.
 
static void ApplyBaseAddress (SerializeResult *result, uint16_t new_base_address)
 Adjust all serialized pointers to a new base address.
 
static absl::StatusOr< SerializeResultSerializeSong (const MusicSong &song, uint16_t base_address)
 
static absl::StatusOr< SerializeResultSerializeSongFromSegment (const MusicSong &song, int start_segment, uint16_t base_address)
 Serialize a song starting from a specific segment (for seeking).
 
static void ApplyBaseAddress (SerializeResult *result, uint16_t new_base_address)
 
static int CalculateRequiredSpace (const MusicSong &song)
 

Static Private Member Functions

static std::vector< uint8_t > SerializeTrack (const MusicTrack &track)
 
static std::vector< uint8_t > SerializeNote (const Note &note, uint8_t *current_duration)
 
static std::vector< uint8_t > SerializeCommand (const MusicCommand &command)
 

Detailed Description

Serializer for N-SPC music data to ROM format.

Serializes MusicSong to N-SPC byte format for direct ARAM upload.

This class handles converting the internal song representation back to the binary format expected by the SNES APU.

Produces a complete sound bank block that can be uploaded to ARAM:

  • Song header (section pointers)
  • Channel pointer table
  • Channel data (notes, commands, durations)

This enables preview of custom songs without saving to ROM first.

Definition at line 175 of file spc_parser.h.

Constructor & Destructor Documentation

◆ SpcSerializer()

yaze::zelda3::music::SpcSerializer::SpcSerializer ( )
default

◆ ~SpcSerializer()

yaze::zelda3::music::SpcSerializer::~SpcSerializer ( )
default

Member Function Documentation

◆ SerializeSong() [1/2]

absl::StatusOr< SpcSerializer::SerializeResult > yaze::zelda3::music::SpcSerializer::SerializeSong ( const MusicSong & song,
uint16_t base_address )
static

◆ SerializeTrack() [1/2]

std::vector< uint8_t > yaze::zelda3::music::SpcSerializer::SerializeTrack ( const MusicTrack & track)
static

Serialize a single track to binary format.

Parameters
trackThe track to serialize.
Returns
Binary data for the track.

Definition at line 159 of file spc_serializer.cc.

References yaze::zelda3::music::TrackEvent::Command, yaze::zelda3::music::TrackEvent::End, yaze::zelda3::music::MusicTrack::events, yaze::zelda3::music::kTrackEnd, yaze::zelda3::music::TrackEvent::Note, SerializeCommand(), and SerializeNote().

Referenced by CalculateRequiredSpace(), and SerializeSong().

Here is the call graph for this function:

◆ CalculateRequiredSpace() [1/2]

int yaze::zelda3::music::SpcSerializer::CalculateRequiredSpace ( const MusicSong & song)
static

Calculate the space required for a song.

Parameters
songThe song to measure.
Returns
Size in bytes.

Definition at line 194 of file spc_serializer.cc.

References yaze::zelda3::music::MusicSong::HasLoop(), yaze::zelda3::music::MusicSong::segments, and SerializeTrack().

Here is the call graph for this function:

◆ SerializeNote() [1/2]

std::vector< uint8_t > yaze::zelda3::music::SpcSerializer::SerializeNote ( const Note & note,
uint8_t * current_duration )
static

Serialize a note event.

Parameters
noteThe note to serialize.
current_durationThe current duration state.
Returns
Binary bytes for the note.

Definition at line 215 of file spc_serializer.cc.

References yaze::zelda3::music::Note::duration, yaze::zelda3::music::Note::has_duration_prefix, yaze::zelda3::music::Note::pitch, and yaze::zelda3::music::Note::velocity.

Referenced by SerializeTrack().

◆ SerializeCommand() [1/2]

std::vector< uint8_t > yaze::zelda3::music::SpcSerializer::SerializeCommand ( const MusicCommand & command)
static

Serialize a command event.

Parameters
commandThe command to serialize.
Returns
Binary bytes for the command.

Definition at line 236 of file spc_serializer.cc.

References yaze::zelda3::music::MusicCommand::GetParamCount(), yaze::zelda3::music::MusicCommand::opcode, and yaze::zelda3::music::MusicCommand::params.

Referenced by SerializeTrack().

Here is the call graph for this function:

◆ ApplyBaseAddress() [1/2]

void yaze::zelda3::music::SpcSerializer::ApplyBaseAddress ( SerializeResult * result,
uint16_t new_base_address )
static

Adjust all serialized pointers to a new base address.

Parameters
resultSerialized blob to patch (in-place).
new_base_addressTarget SPC base address.

Definition at line 249 of file spc_serializer.cc.

References yaze::zelda3::music::SpcSerializer::SerializeResult::base_address, yaze::zelda3::music::SpcSerializer::SerializeResult::data, and yaze::zelda3::music::SpcSerializer::SerializeResult::relocations.

Referenced by yaze::zelda3::music::MusicBank::SaveSongTable().

◆ SerializeSong() [2/2]

static absl::StatusOr< SerializeResult > yaze::zelda3::music::SpcSerializer::SerializeSong ( const MusicSong & song,
uint16_t base_address )
static

◆ SerializeSongFromSegment()

absl::StatusOr< SpcSerializer::SerializeResult > yaze::zelda3::music::SpcSerializer::SerializeSongFromSegment ( const MusicSong & song,
int start_segment,
uint16_t base_address )
static

Serialize a song starting from a specific segment (for seeking).

Creates song data starting from segment_index, allowing playback to resume from a specific point in the song.

Definition at line 123 of file spc_serializer.cc.

References yaze::zelda3::music::MusicSong::bank, yaze::zelda3::music::MusicSong::HasLoop(), yaze::zelda3::music::MusicSong::loop_point, yaze::zelda3::music::MusicSong::name, yaze::zelda3::music::MusicSong::segments, and SerializeSong().

Here is the call graph for this function:

◆ ApplyBaseAddress() [2/2]

static void yaze::zelda3::music::SpcSerializer::ApplyBaseAddress ( SerializeResult * result,
uint16_t new_base_address )
static

◆ CalculateRequiredSpace() [2/2]

static int yaze::zelda3::music::SpcSerializer::CalculateRequiredSpace ( const MusicSong & song)
static

◆ SerializeTrack() [2/2]

static std::vector< uint8_t > yaze::zelda3::music::SpcSerializer::SerializeTrack ( const MusicTrack & track)
staticprivate

◆ SerializeNote() [2/2]

static std::vector< uint8_t > yaze::zelda3::music::SpcSerializer::SerializeNote ( const Note & note,
uint8_t * current_duration )
staticprivate

◆ SerializeCommand() [2/2]

static std::vector< uint8_t > yaze::zelda3::music::SpcSerializer::SerializeCommand ( const MusicCommand & command)
staticprivate

The documentation for this class was generated from the following files: