#pragma pattern_limit 4000000
import std.mem;

struct ID {
	char name[4];
};


// FORM Header
struct FORM_Header {
	ID id  [[inline]];       // 'FORM'
    be u32 size;         // Big endian 32-bit unsigned integer (size of the FORM chunk)
    char type[4];        // 'AIFC'
};

// Common Chunk (COMM)
struct CommonChunk {
    be u32 size;           // Chunk size (big endian)
    be u16 num_channels;       // Number of audio channels (big endian)
    be u32 num_frames;         // Number of audio frames (big endian)
    be u16 sample_size;        // Size of each sample in bits (big endian)
    u8 sample_rate[10];      // 80-bit IEEE Extended (approximation, replace if precise handling needed)
    char compression_type[4];  // Compression type
    u8 compression_name_len;   // Length of the compression name
    char compression_name[compression_name_len]; // Compression name
};

// Sound Data Chunk (SSND)
struct SoundDataChunk {
    be u32 size;           // Chunk size (big endian)
    be u32 offset;         // Offset to the sound data
    be u32 block_size;     // Block size
    u8 sound_data[size - 8]; // Sound data (remaining size minus offset and block size fields)
};

// Marker Chunk (MARK)
struct Marker {
    be u32 size;           // Chunk size (big endian)
    be u16 id;             // Marker ID
    be u32 position;       // Sample position of the marker
    u8 name_len;           // Marker name length
    char name[name_len];   // Marker name
};

struct MarkerChunk {
    be u16 num_markers;    // Number of markers
    Marker markers[num_markers]; // List of markers
};

struct FormatVersionChunk {
    be u32 size;           // Chunk size (big endian)
	u32 timestamp;
};

struct Region {
   u8 _unused1[21] [[hidden]];
   u24 start;
   u8 _unused[5] [[hidden]];
   u24 end;
   u8 _unused2[56] [[hidden]];
};

struct RegionData {
    be u32 size;
    be u32 regionCount;
    be Region regions[regionCount];
};

struct BinaryData {
    be u32 size;           // Chunk size (big endian)
    u8 data[size]; // Default: unknown chunk data
};

// Generic Chunk
struct Chunk {
	ID id;         // Chunk identifier

	if (id.name == "SSND") {
       SoundDataChunk ssnd;
    } else if(id.name == "FVER") {
    	FormatVersionChunk format;
	} else if(id.name == "COMM") {
		CommonChunk comm;
	} else if (id.name == "regn") {
	    RegionData regn;
	 }else {
		BinaryData raw;
    }
};

// Main File Structure
struct AIFC_File {
    FORM_Header header;    // File header
    Chunk chunks[4];
};

AIFC_File file  @ 0x00;

Изменить пасту