npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nitro-fs

v1.1.1

Published

NDS Filesystem reading and parsing library

Downloads

39

Readme

nitro-fs

About

nitro-fs is a work-in-progress TypeScript library for reading files on the Nintendo DS ROM Filesystem. It is also able to parse and convert some popular file formats used on the Nintendo DS (mainly SDAT as of right now).

Note that this library is still in development and things may change. If you find any bugs or have any suggestions, feel free to open an issue or pull request.

If you need help with something, feel free to ask me on Discord (danielpxl).

Supported Formats

  • SDAT (Sound Data)
    • SSEQ (Sound Sequence)
    • STRM (Sound Stream)
    • SWAR (Sound Wave Archive)
    • SBNK (Sound Bank)
    • SSAR (Sound Sequence Archive)
  • BTX (3D Model Texture)

Installation

npm install nitro-fs

Usage

Initializing NitroFS

import { NitroFS } from "nitro-fs";

// File input element for selecting a ROM
const fileInput = document.getElementById("fileInput") as HTMLInputElement;

fileInput.addEventListener("change", async () => {
	// Initialize NitroFS with the ROM buffer
	const rom = await fileInput.files.item(0).arrayBuffer();
	const nitroFS = NitroFS.fromRom(rom);
});

Reading the ROM header

// Read the ROM header
const header = nitroFS.cartridgeHeader;
console.log(header.gameTitle);

Reading a file as an ArrayBuffer

// Read a file
const buffer = nitroFS.readFile("data/sound/sound_data.sdat");
// Do something with the buffer

Parsing an SDAT file

// Add imports at the top
import { Audio, BufferReader } from "nitro-fs";
// Read the file
const file = nitroFS.readFile("data/sound/sound_data.sdat");

// Convert ArrayBuffer to BufferReader (makes it easier to read the file)
const reader = BufferReader.new(file);

// Parse the SDAT file
const sdat = new Audio.SDAT(reader);

console.log(sdat);

Converting an SSEQ file to PCM

// Assuming you have already parsed the SDAT file

// Desired sample rate and number of seconds to render
const sampleRate = 48000;
const numSeconds = 10;

// Create a (stereo) buffer to store the audio data
const audioBuffer: Float32Array[] = new Array(2);
for (let i = 0; i < 2; i++) {
	// Create a buffer for each channel
	audioBuffer[i] = new Float32Array(sampleRate * numSeconds);
}

// Create a sink function to handle the audio data
let offset = 0;
let done = false;
const sink = (chunk: Float32Array[]) => {
	// If the offset is greater than the length of the buffer, we're done
	if (offset + chunk[0].length > chunk[0].length) {
		done = true;
		return;
	}

	// Copy the audio data into the buffer
	for (let i = 0; i < 2; i++) {
		audioBuffer[i].set(chunk[i], offset);
	}

	offset += chunk[0].length;
}

// Initialize the sequence renderer
const renderer = new Audio.SequenceRenderer({
	file: Audio.SequenceRenderer.makeInfoSSEQ(sdat, "SEQ_BA_AKAGI")
	sampleRate: sampleRate, 
	sink: sink
});

// Render the sequence until it's done
while (!done) {
	renderer.tick();
}

// Do something with the audio buffer

Known Issues

  • The SequenceRenderer only supports a subset of the available commands (see here for more info). The most important ones are supported though, and most games already work fine.
  • SSARs are parsed correctly (I think?), but the SequenceRenderer doesn't really support them yet.

Thanks to: