UNPKG

nitro-fs

Version:

NDS Filesystem reading and parsing library

1,543 lines (1,454 loc) 43.3 kB
declare class ADSRConverter { private static readonly ATTACKRATE_TABLE; static convertAttack(attackRate: number): number; private static readonly FALLRATE_TABLE; static convertFall(fallRate: number): number; private static readonly SUSTAIN_TABLE; static convertSustain(sustain: number): number; static convertVolume(volume: number): number; static convertPan(pan: number): number; } declare namespace Audio_2 { export { Block, SoundFileHeader, Table, TableEntry, Uint32TableEntry, EncodingType, SDAT, SDATHeader, SDATFS, SoundFile, SequenceArchiveFile, InfoBlock, SequenceInfo, SequenceArchiveInfo, BankInfo, WaveArchiveInfo, PlayerInfo, GroupInfo, GroupEntry, GroupEntryType, StreamPlayerInfo, StreamInfo, SSAR, SSARDataBlock, SequenceArchiveEntry, SSEQ, SSEQDataBlock, Command, OffsetCommand, NestedCommand, Commands, ModType, CommandType, commandTypeToString, CommandParser, Note, noteToFrequency, STRM, STRMDataBlock, STRMInfoBlock, SWAR, SWAV, SWAVDataBlock, SBNK, SBNKDataBlock, InstrumentTableEntry, NoteInfo, InstrumentType, Instrument, DirectInstrumentType, DirectInstrument, DrumSetInstrument, KeySplitInstrument, ContainedInstrument, SequenceRenderer, RendererInfo, RendererFileInfo, Track, TrackInfo, SequenceVariables, Synthesizer, SynthChannel, PlayingNote, Sample, PCMSample, PSGSample, WhiteNoiseSample, Resampler, Envelope, EnvelopeState, ADSRConverter, Random } } export { Audio_2 as Audio } declare class BankInfo { constructor(raw: BufferReader); fileId: number; waveArchives: number[]; } declare class Block { constructor(raw: BufferReader, assertMagic?: string); magic: string; size: number; } export declare class BTX0 { constructor(raw: BufferReader); header: BTX0Header; tex: TEX0; } export declare class BTX0Header { constructor(raw: BufferReader); readonly magic: string; readonly fileSize: number; readonly texOffset: number; } export declare class BufferReader { constructor(buffer: ArrayBuffer, start: number, length: number, littleEndian?: boolean); private buffer; private start; private bufferLength; private view; littleEndian: boolean; /** * Creates a new BufferReader instance from the specified ArrayBuffer. * @param buffer - The ArrayBuffer to read from. * @param littleEndian - Whether the buffer is little endian. * @returns The BufferReader instance. */ static new(buffer: ArrayBuffer, littleEndian?: boolean): BufferReader; /** * Slices the buffer and returns a new BufferReader instance, without copying the underlying buffer. * @param start - The start offset. * @param end - The end offset. * @returns The new BufferReader instance. */ slice(start: number, end?: number): BufferReader; readUint8(offset: number): number; readUint16(offset: number): number; readUint24(offset: number): number; readUint32(offset: number): number; readInt8(offset: number): number; readInt16(offset: number): number; readInt24(offset: number): number; readInt32(offset: number): number; readFloat32(offset: number): number; readFloat64(offset: number): number; /** * Reads a string of the specified length from the buffer. * @param offset - The offset to start reading from. * @param length - The length of the string to read. */ readChars(offset: number, length: number): string; /** * Reads a null-terminated string from the buffer. * @param offset - The offset to start reading from. */ readString(offset: number): string; /** * Reads a variable-length integer from the buffer. Variable-length integers are encoded in groups of 7 bits, * with the 8th bit indicating whether another group of 7 bits follows. * @param offset - The offset to start reading from. * @returns An object containing the value and the length of the integer. */ readVL(offset: number): { value: number; length: number; }; get length(): number; /** * Returns a copy of the underlying buffer. * @returns - A copy of the underlying buffer. */ getBuffer(): ArrayBuffer; } export declare class CartridgeHeader { constructor(raw: BufferReader); readonly gameTitle: string; readonly gameCode: string; readonly fntOffset: number; readonly fntLength: number; readonly fatOffset: number; readonly fatLength: number; } declare abstract class Command { abstract type: CommandType; abstract length: number; } declare class CommandParser { static parseCommands(raw: BufferReader, length: number): Command[]; static parseCommand(raw: BufferReader, pos: number): Command; } declare namespace Commands { class Note extends Command { length: number; note: Note; velocity: number; duration: number; constructor(length: number, note: Note, velocity: number, duration: number); type: CommandType; } class Wait extends Command { length: number; duration: number; constructor(length: number, duration: number); type: CommandType; } class ProgramChange extends Command { length: number; program: number; constructor(length: number, program: number); type: CommandType; } class OpenTrack extends OffsetCommand { length: number; track: number; offset: number; constructor(length: number, track: number, offset: number); type: CommandType; } class Jump extends OffsetCommand { offset: number; constructor(offset: number); type: CommandType; length: number; } class Call extends OffsetCommand { offset: number; constructor(offset: number); type: CommandType; length: number; } class Random extends NestedCommand { subCommand: Command; min: number; max: number; length: number; constructor(subCommand: Command, min: number, max: number, length: number); type: CommandType; } class Variable extends NestedCommand { subCommand: Command; variable: number; length: number; constructor(subCommand: Command, variable: number, length: number); type: CommandType; } class If extends NestedCommand { subCommand: Command; length: number; constructor(subCommand: Command, length: number); type: CommandType; } class SetVariable extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class AddVariable extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class SubtractVariable extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class MultiplyVariable extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class DivideVariable extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class ShiftVariable extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class RandomVariable extends Command { variable: number; max: number; constructor(variable: number, max: number); type: CommandType; length: number; } class CompareEqual extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class CompareGreaterOrEqual extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class CompareGreater extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class CompareLessOrEqual extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class CompareLess extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class CompareNotEqual extends Command { variable: number; value: number; constructor(variable: number, value: number); type: CommandType; length: number; } class Pan extends Command { pan: number; constructor(pan: number); type: CommandType; length: number; } class Volume extends Command { volume: number; constructor(volume: number); type: CommandType; length: number; } class MainVolume extends Command { volume: number; constructor(volume: number); type: CommandType; length: number; } class Transpose extends Command { transpose: number; constructor(transpose: number); type: CommandType; length: number; } class PitchBend extends Command { bend: number; constructor(bend: number); type: CommandType; length: number; } class PitchBendRange extends Command { range: number; constructor(range: number); type: CommandType; length: number; } class Priority extends Command { priority: number; constructor(priority: number); type: CommandType; length: number; } class NoteWaitMode extends Command { enabled: boolean; constructor(enabled: boolean); type: CommandType; length: number; } class Tie extends Command { enabled: boolean; constructor(enabled: boolean); type: CommandType; length: number; } class Portamento extends Command { key: number; constructor(key: number); type: CommandType; length: number; } class ModulationDepth extends Command { depth: number; constructor(depth: number); type: CommandType; length: number; } class ModulationSpeed extends Command { speed: number; constructor(speed: number); type: CommandType; length: number; } class ModulationType extends Command { modType: ModType; constructor(modType: ModType); type: CommandType; length: number; } class ModulationRange extends Command { range: number; constructor(range: number); type: CommandType; length: number; } class PortamentoSwitch extends Command { enabled: boolean; constructor(enabled: boolean); type: CommandType; length: number; } class PortamentoTime extends Command { time: number; constructor(time: number); type: CommandType; length: number; } class Attack extends Command { attack: number; constructor(attack: number); type: CommandType; length: number; } class Decay extends Command { decay: number; constructor(decay: number); type: CommandType; length: number; } class Sustain extends Command { sustain: number; constructor(sustain: number); type: CommandType; length: number; } class Release extends Command { release: number; constructor(release: number); type: CommandType; length: number; } class LoopStart extends Command { count: number; constructor(count: number); type: CommandType; length: number; } class Volume2 extends Command { volume: number; constructor(volume: number); type: CommandType; length: number; } class PrintVariable extends Command { variable: number; constructor(variable: number); type: CommandType; length: number; } class ModulationDelay extends Command { delay: number; constructor(delay: number); type: CommandType; length: number; } class Tempo extends Command { tempo: number; constructor(tempo: number); type: CommandType; length: number; } class SweepPitch extends Command { pitch: number; constructor(pitch: number); type: CommandType; length: number; } class Return extends Command { constructor(); length: number; type: CommandType; } class LoopEnd extends Command { constructor(); length: number; type: CommandType; } class AllocateTracks extends Command { tracks: number; constructor(tracks: number); length: number; type: CommandType; isAllocated(track: number): boolean; } class Fin extends Command { constructor(); length: number; type: CommandType; } } declare enum CommandType { Note = 0, Wait = 128, ProgramChange = 129, OpenTrack = 147, Jump = 148, Call = 149, Random = 160, Variable = 161, If = 162, SetVariable = 176, AddVariable = 177, SubtractVariable = 178, MultiplyVariable = 179, DivideVariable = 180, ShiftVariable = 181, RandomVariable = 182, CompareEqual = 184, CompareGreaterOrEqual = 185, CompareGreater = 186, CompareLessOrEqual = 187, CompareLess = 188, CompareNotEqual = 189, Pan = 192, Volume = 193, MainVolume = 194, Transpose = 195, PitchBend = 196, PitchBendRange = 197, Priority = 198, NoteWaitMode = 199, Tie = 200, Portamento = 201, ModulationDepth = 202, ModulationSpeed = 203, ModulationType = 204, ModulationRange = 205, PortamentoSwitch = 206, PortamentoTime = 207, Attack = 208, Decay = 209, Sustain = 210, Release = 211, LoopStart = 212, Volume2 = 213, PrintVariable = 214, ModulationDelay = 224, Tempo = 225, SweepPitch = 227, LoopEnd = 252, Return = 253, AllocateTracks = 254, Fin = 255 } declare function commandTypeToString(type: CommandType): "Note" | "Wait" | "ProgramChange" | "OpenTrack" | "Jump" | "Call" | "Random" | "Variable" | "If" | "SetVariable" | "AddVariable" | "SubtractVariable" | "MultiplyVariable" | "DivideVariable" | "ShiftVariable" | "RandomVariable" | "CompareEqual" | "CompareGreaterOrEqual" | "CompareGreater" | "CompareLessOrEqual" | "CompareLess" | "CompareNotEqual" | "Pan" | "Volume" | "MainVolume" | "Transpose" | "PitchBend" | "PitchBendRange" | "Priority" | "NoteWaitMode" | "Tie" | "PortamentoControl" | "ModulationDepth" | "ModulationSpeed" | "ModulationType" | "ModulationRange" | "PortamentoSwitch" | "PortamentoTime" | "Attack" | "Decay" | "Sustain" | "Release" | "LoopStart" | "Volume2" | "PrintVariable" | "ModulationDelay" | "Tempo" | "SweepPitch" | "LoopEnd" | "Return" | "AllocateTracks" | "Fin" | "Unknown"; export declare class Compression { static decompress(raw: BufferReader): Uint8Array; } declare class ContainedInstrument { constructor(raw: BufferReader); type: InstrumentType; noteInfo: NoteInfo; } declare class DirectInstrument extends Instrument { constructor(raw: BufferReader, type: DirectInstrumentType); type: DirectInstrumentType; noteInfo: NoteInfo; } declare type DirectInstrumentType = InstrumentType.PCM | InstrumentType.PSG | InstrumentType.WhiteNoise | InstrumentType.DirectPCM; declare class DrumSetInstrument extends Instrument { constructor(raw: BufferReader); type: InstrumentType; lowerKey: number; upperKey: number; instruments: ContainedInstrument[]; } declare enum EncodingType { PCM8 = 0, PCM16 = 1, IMA_ADPCM = 2 } declare class Envelope { constructor(startTime: number, attackRate: number, decayRate: number, sustainLevel: number, releaseRate: number, stopTime?: number); startTime: number; stopTime: number; attackRate: number; decayRate: number; sustainLevel: number; releaseRate: number; state: EnvelopeState; gain: number; tick(time: number): void; get isDone(): boolean; } declare enum EnvelopeState { Attack = 0, Decay = 1, Sustain = 2, Release = 3 } declare class GroupEntry extends TableEntry { constructor(raw: BufferReader); type: GroupEntryType; load: number; entryId: number; readonly length = 8; } declare enum GroupEntryType { Sequence = 0, Bank = 1, WaveArchive = 2, SequenceArchive = 3 } declare class GroupInfo { constructor(raw: BufferReader); entries: GroupEntry[]; } declare class InfoBlock extends Block { constructor(raw: BufferReader); sequenceInfo: SequenceInfo[]; sequenceArchiveInfo: SequenceArchiveInfo[]; bankInfo: BankInfo[]; waveArchiveInfo: WaveArchiveInfo[]; playerInfo: PlayerInfo[]; groupInfo: GroupInfo[]; streamPlayerInfo: StreamPlayerInfo[]; streamInfo: StreamInfo[]; } export declare abstract class InfoSection { constructor(raw: BufferReader); numberOfEntries: number; sectionSize: number; dataSize: number; names: string[]; abstract parseEntry(raw: BufferReader): void; } declare abstract class Instrument { constructor(raw: BufferReader); abstract type: InstrumentType; } declare class InstrumentTableEntry extends TableEntry { constructor(raw: BufferReader); readonly length = 4; type: InstrumentType; dataOffset: number; } declare enum InstrumentType { Null = 0, PCM = 1, PSG = 2, WhiteNoise = 3, DirectPCM = 4, DrumSet = 16, KeySplit = 17 } declare class KeySplitInstrument extends Instrument { constructor(raw: BufferReader); type: InstrumentType; regions: number[]; instruments: ContainedInstrument[]; } declare enum ModType { Pitch = 0, Volume = 1, Pan = 2 } export declare class NCG { constructor(raw: Uint8Array, offset?: number); raw: Uint8Array; offset: number; parse(ncl: NCL, paletteIndex?: number): Uint8Array; get length(): number; } export declare class NCL { constructor(raw: Uint8Array, offset?: number); raw: Uint8Array; offset: number; colorAt(index: number): Uint8Array; colors(): Uint8Array; get length(): number; private color5to8; } declare abstract class NestedCommand extends Command { abstract subCommand: Command; } /** * Class for reading files from the NitroFS. */ export declare class NitroFS { /** * Creates a NitroFS instance from a ROM buffer. * @param rom - The ROM buffer. * @returns The NitroFS instance. */ static fromRom(rom: ArrayBuffer): NitroFS; cartridgeHeader: CartridgeHeader; private fnt; private fileData; /** * Reads a file from the NitroFS. * @param path - The path to the file. * @returns A buffer containing the file data. */ readFile(path: string): ArrayBuffer; /** * Reads a directory from the NitroFS. * @param path - The path to the directory. * @returns An object containing the paths of every file and directory in the base directory. */ readDir(path: string): { files: string[]; directories: string[]; }; /** * Checks if a file exists in the NitroFS. * @param path - The path to the file. * @returns Whether the file exists. */ exists(path: string): boolean; } declare enum Note { CNegative1 = 0, CNegative1Sharp = 1, DNegative1 = 2, DNegative1Sharp = 3, ENegative1 = 4, FNegative1 = 5, FNegative1Sharp = 6, GNegative1 = 7, GNegative1Sharp = 8, ANegative1 = 9, ANegative1Sharp = 10, BNegative1 = 11, C0 = 12, C0Sharp = 13, D0 = 14, D0Sharp = 15, E0 = 16, F0 = 17, F0Sharp = 18, G0 = 19, G0Sharp = 20, A0 = 21, A0Sharp = 22, B0 = 23, C1 = 24, C1Sharp = 25, D1 = 26, D1Sharp = 27, E1 = 28, F1 = 29, F1Sharp = 30, G1 = 31, G1Sharp = 32, A1 = 33, A1Sharp = 34, B1 = 35, C2 = 36, C2Sharp = 37, D2 = 38, D2Sharp = 39, E2 = 40, F2 = 41, F2Sharp = 42, G2 = 43, G2Sharp = 44, A2 = 45, A2Sharp = 46, B2 = 47, C3 = 48, C3Sharp = 49, D3 = 50, D3Sharp = 51, E3 = 52, F3 = 53, F3Sharp = 54, G3 = 55, G3Sharp = 56, A3 = 57, A3Sharp = 58, B3 = 59, C4 = 60, C4Sharp = 61, D4 = 62, D4Sharp = 63, E4 = 64, F4 = 65, F4Sharp = 66, G4 = 67, G4Sharp = 68, A4 = 69, A4Sharp = 70, B4 = 71, C5 = 72, C5Sharp = 73, D5 = 74, D5Sharp = 75, E5 = 76, F5 = 77, F5Sharp = 78, G5 = 79, G5Sharp = 80, A5 = 81, A5Sharp = 82, B5 = 83, C6 = 84, C6Sharp = 85, D6 = 86, D6Sharp = 87, E6 = 88, F6 = 89, F6Sharp = 90, G6 = 91, G6Sharp = 92, A6 = 93, A6Sharp = 94, B6 = 95, C7 = 96, C7Sharp = 97, D7 = 98, D7Sharp = 99, E7 = 100, F7 = 101, F7Sharp = 102, G7 = 103, G7Sharp = 104, A7 = 105, A7Sharp = 106, B7 = 107, C8 = 108, C8Sharp = 109, D8 = 110, D8Sharp = 111, E8 = 112, F8 = 113, F8Sharp = 114, G8 = 115, G8Sharp = 116, A8 = 117, A8Sharp = 118, B8 = 119, C9 = 120, C9Sharp = 121, D9 = 122, D9Sharp = 123, E9 = 124, F9 = 125, F9Sharp = 126, G9 = 127 } declare class NoteInfo { constructor(raw: BufferReader); waveId: number; waveArchiveId: number; baseNote: number; attack: number; decay: number; sustain: number; release: number; pan: number; } declare function noteToFrequency(note: Note): number; declare abstract class OffsetCommand extends Command { abstract offset: number; } export declare class PaletteInfo { constructor(raw: BufferReader); paletteOffset: number; } export declare class PaletteInfoSection extends InfoSection { entries: PaletteInfo[]; parseEntry(raw: BufferReader): void; } declare class PCMSample implements Sample { constructor(swav: SWAV, baseNote: Note); swav: SWAV; sample: Float32Array; baseFreq: number; getValue(targetSampleRate: number, index: number): number; } declare class PlayerInfo { constructor(raw: BufferReader); maxVoices: number; channels: number; heapSize: number; } declare class PlayingNote { constructor(note: Note, envelope: Envelope, sample: Sample, sampleRate: number, velocity: number, trackInfo: TrackInfo, pan: number, doneCallback: () => void); note: Note; envelope: Envelope; sample: Sample; baseFreq: number; sampleRate: number; velocity: number; trackInfo: TrackInfo; pan: number; doneCallback: () => void; sampleIndex: number; modulationPitch: number; modulationVolume: number; modulationTickCount: number; modulationStartTime?: number; portamentoStart?: Note; portamentoTime: number; notePlusPortamento: Note; portamentoCounter: number; getValue(): number; pitchBend(semitones: number): void; setVolume(volume1: number, volume2: number): void; setModulation(modDepth: number, modRange: number, modSpeed: number, modDelay: number, modType: ModType): void; modulationTick(time: number): void; portamentoTick(): void; } declare class PSGSample implements Sample { constructor(dutyCycle: number); dutyCycle: number; baseFreq: number; getValue(targetSampleRate: number, index: number): number; dutyCycleToThreshold(dutyCycle: number): number; } declare class Random { constructor(seed?: number); seed: number; next(): number; } declare interface RendererFileInfo { commands: Command[]; bank: SBNK; swars: SWAR[]; } /** * Information needed to render an SSEQ. */ declare interface RendererInfo { file: RendererFileInfo; /** * The function to call when the renderer has a buffer to output. * @param buffer - A stereo buffer of 32-bit floating point samples. The length of the * buffers is always equal to the bufferLength parameter. */ sink: (buffer: Float32Array[]) => void; /** * The length of the buffer to output. Defaults to 4096. */ bufferLength?: number; /** * The sample rate to render at. Defaults to 48000. */ sampleRate?: number; /** * The active tracks bitmask. Should be 16 bits long, with each bit corresponding to a track. * Defaults to 0xFFFF (all channels active). */ activeTracks?: number; /** * The sequence variables to use. You can use this object even after the renderer has started, * or you can reuse it for multiple renderers, which will allow you to share variables * between them (although the DS resets the local variables between sequences, do that with variables.resetLocal()). * Defaults to a new SequenceVariables object. */ variables?: SequenceVariables; /** * Seed for the random number generator. Defaults to Date.now(). */ seed?: number; } declare class Resampler { static singleSample(source: Float32Array, sourceRate: number, targetRate: number, index: number, loopStartIndex?: number, loopLength?: number): number; } declare abstract class Sample { abstract getValue(targetSampleRate: number, index: number): number; abstract baseFreq: number; } /** * Sound Bank, contains instrument definitions. */ declare class SBNK { constructor(raw: BufferReader); header: SoundFileHeader; data: SBNKDataBlock; instruments: Instrument[]; } declare class SBNKDataBlock extends Block { constructor(raw: BufferReader); instrumentTable: Table<InstrumentTableEntry>; } /** * Sound Data, contains audio files. */ declare class SDAT { constructor(raw: BufferReader); header: SDATHeader; fs: SDATFS; } declare class SDATFS { constructor(raw: BufferReader, header: SDATHeader); sequences: SoundFile<SequenceInfo>[]; sequenceArchives: SequenceArchiveFile[]; banks: SoundFile<BankInfo>[]; waveArchives: SoundFile<WaveArchiveInfo>[]; streams: SoundFile<StreamInfo>[]; infoBlock: InfoBlock; } declare class SDATHeader extends SoundFileHeader { constructor(raw: BufferReader); symbolBlockOffset: number; symbolBlockSize: number; infoBlockOffset: number; infoBlockSize: number; fileAllocationBlockOffset: number; fileAllocationBlockSize: number; fileBlockOffset: number; fileBlockSize: number; } declare class SequenceArchiveEntry extends TableEntry { constructor(raw: BufferReader); readonly length = 12; sequenceDataOffset: number; bankId: number; volume: number; channelPriority: number; playerPriority: number; playerId: number; } declare class SequenceArchiveFile extends SoundFile<SequenceArchiveInfo> { constructor(name: string, fileInfo: SequenceArchiveInfo, id: number, buffer: BufferReader, sequenceSymbols: string[]); sequenceSymbols: string[]; } declare class SequenceArchiveInfo { constructor(raw: BufferReader); fileId: number; } declare class SequenceInfo { constructor(raw: BufferReader); fileId: number; bankId: number; volume: number; channelPriority: number; playerPriority: number; playerId: number; } /** * Renders an SSEQ to a stereo buffer of 32-bit floating point samples. */ declare class SequenceRenderer { constructor(info: RendererInfo); static readonly TICK_INTERVAL_MS: number; commands: Command[]; sampleRate: number; synth: Synthesizer; samplesPerTick: number; tracks: Track[]; sequenceVariables: SequenceVariables; tracksStarted: boolean; activeTracks: number; random: Random; cycle: number; tempo: number; /** * Runs the renderer for one tick. Call this in a loop to render the entire sequence. * The renderer will call the sink function when it has a buffer to output. */ tick(): void; private openTrack; private stopTrack; private changeTempo; static makeInfoSSEQ(sdat: SDAT, name: string): RendererFileInfo; static makeInfoSSEQ(sdat: SDAT, id: number): RendererFileInfo; static makeInfoSSAR(sdat: SDAT, name: string, subName: string): RendererFileInfo; static makeInfoSSAR(sdat: SDAT, name: string, subId: number): RendererFileInfo; static makeInfoSSAR(sdat: SDAT, id: number, subId: number): RendererFileInfo; static makeInfoSSAR(sdat: SDAT, id: number, subName: string): RendererFileInfo; } declare class SequenceVariables { constructor(override?: number[]); variables: number[]; resetLocal(): void; resetGlobal(): void; set(index: number, value: number): void; get(index: number): number; } declare class SoundFile<T> { constructor(name: string, fileInfo: T, id: number, buffer: BufferReader); name: string; fileInfo: T; id: number; buffer: BufferReader; } declare class SoundFileHeader { constructor(raw: BufferReader, assertMagic?: string); magic: string; endianness: number; fileSize: number; headerSize: number; blockCount: number; } declare class SSAR { constructor(raw: BufferReader); dataBlock: SSARDataBlock; data: BufferReader; getSequenceData(id: number): Command[]; } declare class SSARDataBlock extends Block { constructor(raw: BufferReader); sequenceDataStartOffset: number; sequenceTable: Table<SequenceArchiveEntry>; } /** * Sound Sequence, contains sequence commands (similar to MIDI). */ declare class SSEQ { constructor(raw: BufferReader); header: SoundFileHeader; data: SSEQDataBlock; } declare class SSEQDataBlock extends Block { constructor(raw: BufferReader); commands: Command[]; } declare class StreamInfo { constructor(raw: BufferReader); fileId: number; convertToStereo: boolean; volume: number; priority: number; playerId: number; } declare class StreamPlayerInfo { constructor(raw: BufferReader); channelCount: number; leftOrMonoChannel: number; rightChannel: number; } /** * Stream, contains streamed audio data. */ declare class STRM { constructor(raw: BufferReader); infoBlock: STRMInfoBlock; dataBlock: STRMDataBlock; toPCM(): Float32Array[]; } declare class STRMDataBlock extends Block { constructor(raw: BufferReader, header: STRMInfoBlock); raw: BufferReader; header: STRMInfoBlock; toPCM(): Float32Array[]; decodeBlock(offset: number, numSamples: number, blockSize: number): Float32Array; } declare class STRMInfoBlock extends Block { constructor(raw: BufferReader); encoding: EncodingType; loop: boolean; channelCount: number; sampleRate: number; clockTime: number; loopStart: number; sampleCount: number; dataOffset: number; blockCount: number; blockSize: number; samplesPerBlock: number; lastBlockSize: number; lastBlockSampleCount: number; } /** * Sound Archive, contains multiple SWAV files. */ declare class SWAR { constructor(raw: BufferReader); waves: SWAV[]; } /** * Wave, contains audio data. */ declare class SWAV { constructor(raw: BufferReader, hasHeader: boolean); dataBlock: SWAVDataBlock; toPCM(): Float32Array; } declare class SWAVDataBlock extends Block { constructor(raw: BufferReader, hasHeader: boolean); encoding: EncodingType; loop: boolean; sampleRate: number; clockTime: number; loopStart: number; loopLength: number; audioData: BufferReader; } declare class SynthChannel { constructor(sampleRate: number, bank: SBNK, swars: SWAR[]); sampleRate: number; bank: SBNK; bankInfo: BankInfo; swars: SWAR[]; programNumber: number; pan: number; playing: PlayingNote[]; getValue(): number[]; playNote(time: number, note: Note, velocity: number, stopTime?: number, trackInfo?: TrackInfo): void; getNoteInfo(note: Note): { noteInfo: NoteInfo; isPSG: boolean; isWhiteNoise: boolean; }; envelopeTick(time: number): void; changeProgram(programNumber: number): void; pitchBend(semitones: number): void; setVolume(volume1: number, volume2: number): void; setModulation(modDepth: number, modRange: number, modSpeed: number, modDelay: number, modType: ModType): void; private findFirstEmpty; } declare class Synthesizer { constructor(bank: SBNK, swars: SWAR[], sampleRate: number, bpm: number, sink: (buffer: Float32Array[]) => void, bufferLength?: number); sampleRate: number; bpm: number; bufferLength: number; sink: (buffer: Float32Array[]) => void; timePerSample: number; sampleRemainder: number; buffer: Float32Array[]; pos: number; time: number; channels: SynthChannel[]; tick(numSamples: number): void; playNote(track: number, note: Note, velocity?: number, duration?: number, trackInfo?: TrackInfo): void; } declare class Table<T extends TableEntry> { constructor(raw: BufferReader, type: new (raw: BufferReader) => T); entries: T[]; } declare abstract class TableEntry { constructor(raw: BufferReader); abstract readonly length: number; } export declare class TEX0 { constructor(raw: BufferReader); raw: BufferReader; header: TEX0Header; textureInfo: TextureInfoSection; paletteInfo: PaletteInfoSection; parseTexture(texIndex: number, palIndex?: number): Uint8Array; } export declare class TEX0Header { constructor(raw: BufferReader); readonly magic: string; readonly sectionSize: number; readonly textureDataSize: number; readonly textureInfoOffset: number; readonly textureDataOffset: number; readonly compressedTextureDataSize: number; readonly compressedTextureInfoOffset: number; readonly compressedTextureDataOffset: number; readonly compressedTextureInfoDataOffset: number; readonly paletteDataSize: number; readonly paletteInfoOffset: number; readonly paletteDataOffset: number; } export declare class TextureInfo { constructor(raw: BufferReader); textureOffset: number; firstColorTransparent: boolean; format: number; height: number; width: number; } export declare class TextureInfoSection extends InfoSection { entries: TextureInfo[]; parseEntry(raw: BufferReader): void; } declare class Track { constructor(track: number, offset: number, commands: Command[], synth: Synthesizer, sampleRate: number, variables: SequenceVariables, random: Random, stopTrack: () => void, changeTempo: (tempo: number) => void, openTrack: (track: number, offset: number) => void); readonly handlers: { 0: (cmd: Commands.Note) => void; 128: (cmd: Commands.Wait) => void; 129: (cmd: Commands.ProgramChange) => void; 147: (cmd: Commands.OpenTrack) => void; 148: (cmd: Commands.Jump) => void; 149: (cmd: Commands.Call) => void; 160: (cmd: Commands.Random) => void; 161: (cmd: Commands.Variable) => void; 162: (cmd: Commands.If) => void; 176: (cmd: Commands.SetVariable) => void; 177: (cmd: Commands.AddVariable) => void; 178: (cmd: Commands.SubtractVariable) => void; 179: (cmd: Commands.MultiplyVariable) => void; 180: (cmd: Commands.DivideVariable) => void; 181: (cmd: Commands.ShiftVariable) => void; 182: (cmd: Commands.RandomVariable) => void; 184: (cmd: Commands.CompareEqual) => void; 185: (cmd: Commands.CompareGreaterOrEqual) => void; 186: (cmd: Commands.CompareGreater) => void; 187: (cmd: Commands.CompareLessOrEqual) => void; 188: (cmd: Commands.CompareLess) => void; 189: (cmd: Commands.CompareNotEqual) => void; 192: (cmd: Commands.Pan) => void; 193: (cmd: Commands.Volume) => void; 194: (cmd: Commands.MainVolume) => void; 195: (cmd: Commands.Transpose) => void; 196: (cmd: Commands.PitchBend) => void; 197: (cmd: Commands.PitchBendRange) => void; 198: (cmd: Commands.Priority) => void; 199: (cmd: Commands.NoteWaitMode) => void; 200: (cmd: Commands.Tie) => void; 201: (cmd: Commands.Portamento) => void; 202: (cmd: Commands.ModulationDepth) => void; 203: (cmd: Commands.ModulationSpeed) => void; 204: (cmd: Commands.ModulationType) => void; 205: (cmd: Commands.ModulationRange) => void; 206: (cmd: Commands.PortamentoSwitch) => void; 207: (cmd: Commands.PortamentoTime) => void; 208: (cmd: Commands.Attack) => void; 209: (cmd: Commands.Decay) => void; 210: (cmd: Commands.Sustain) => void; 211: (cmd: Commands.Release) => void; 212: (cmd: Commands.LoopStart) => void; 213: (cmd: Commands.Volume2) => void; 214: (cmd: Commands.PrintVariable) => void; 224: (cmd: Commands.ModulationDelay) => void; 225: (cmd: Commands.Tempo) => void; 227: (cmd: Commands.SweepPitch) => void; 252: (cmd: Commands.LoopEnd) => void; 253: (cmd: Commands.Return) => void; 254: (cmd: Commands.AllocateTracks) => void; 255: (cmd: Commands.Fin) => void; }; active: boolean; track: number; offset: number; commands: Command[]; sampleRate: number; synth: Synthesizer; stopTrackCallback: (track: number) => void; changeTempoCallback: (tempo: number) => void; openTrackCallback: (track: number, offset: number) => void; pointer: number; wait: number; callReturnStack: number[]; pitchBendRange: number; pitchBend: number; volume1: number; volume2: number; modulationDepth: number; modulationRange: number; modulationSpeed: number; modulationDelay: number; modulationType: ModType; portamentoKey: Note; portamentoTime: number; portamentoSwitch: boolean; transpose: number; noteWaitEnabled: boolean; variables: SequenceVariables; conditionalFlag: boolean; random: Random; tick(): void; private Note; private Wait; private ProgramChange; private OpenTrack; private Jump; private Call; private Random; private Variable; private If; private SetVariable; private AddVariable; private SubtractVariable; private MultiplyVariable; private DivideVariable; private ShiftVariable; private RandomVariable; private CompareEqual; private CompareGreaterOrEqual; private CompareGreater; private CompareLessOrEqual; private CompareLess; private CompareNotEqual; private Pan; private Volume; private MainVolume; private Transpose; private PitchBend; private PitchBendRange; private Priority; private NoteWaitMode; private Tie; private PortamentoControl; private ModulationDepth; private ModulationSpeed; private ModulationType; private ModulationRange; private PortamentoSwitch; private PortamentoTime; private Attack; private Decay; private Sustain; private Release; private LoopStart; private Volume2; private PrintVariable; private ModulationDelay; private Tempo; private SweepPitch; private LoopEnd; private Return; private AllocateTracks; private Fin; } declare interface TrackInfo { pitchBendSemitones: number; volume1: number; volume2: number; modDepth: number; modRange: number; modSpeed: number; modDelay: number; modType: ModType; portamentoKey: Note; portamentoTime: number; portamentoSwitch: boolean; } declare class Uint32TableEntry extends TableEntry { constructor(raw: BufferReader); readonly length = 4; value: number; } declare class WaveArchiveInfo { constructor(raw: BufferReader); fileId: number; loadIndividually: boolean; } declare class WhiteNoiseSample implements Sample { constructor(); baseFreq: number; getValue(targetSampleRate: number, index: number): number; } export { }