Exemplo n.º 1
0
int main(int argc, char **argv)
{
	procyon_ripper ripper;

	int argnum;
	int argi;

	argi = 1;
	while (argi < argc && argv[argi][0] == '-')
	{
		if (strcmp(argv[argi], "--help") == 0)
		{
			printUsage(argv[0]);
			return EXIT_SUCCESS;
		}
		else if (strcmp(argv[argi], "-v") == 0 || strcmp(argv[argi], "--verbose") == 0)
		{
			ripper.verbose = true;
		}
		else
		{
			fprintf(stderr, "Error: Unknown option \"%s\"\n", argv[argi]);
			return EXIT_FAILURE;
		}
		argi++;
	}

	argnum = argc - argi;
	if (argnum != 1)
	{
		fprintf(stderr, "Error: Too few/more arguments.\n");
		fprintf(stderr, "\n");
		fprintf(stderr, "Run \"%s --help\" for help.\n", argv[0]);
		return EXIT_FAILURE;
	}

	char nds_path[PATH_MAX];
	strcpy(nds_path, argv[argi]);

	char nds_basename[PATH_MAX];
	strcpy(nds_basename, nds_path);
	path_stripext(nds_basename);

	if (!ripper.load_rom(nds_path)) {
		fprintf(stderr, "Error: Unsupported ROM format.\n");
		return EXIT_FAILURE;
	}

	if (!ripper.scan()) {
		fprintf(stderr, "Error: Code detection failed. (unsupported engine?)\n");
		return EXIT_FAILURE;
	}

	if (!ripper.save_2sfs(nds_basename)) {
		fprintf(stderr, "Error: Unable to save 2sf files.\n");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
bool brr2wav(const std::string & brr_filename, uint16_t pitch)
{
	char path_c[PATH_MAX];

	off_t brr_filesize = path_getfilesize(brr_filename.c_str());
	if (brr_filesize == -1) {
		fprintf(stderr, "Error: %s: Unable to open\n", brr_filename.c_str());
		return false;
	}
	if (brr_filesize == 0) {
		fprintf(stderr, "Error: %s: File is empty\n", brr_filename.c_str());
		return false;
	}
	if (brr_filesize > 0x800000) {
		fprintf(stderr, "Error: %s: File too large\n", brr_filename.c_str());
		return false;
	}

	uint8_t * data = readfile(brr_filename);
	if (data == NULL) {
		return false;
	}

	uint8_t * brr = data;
	size_t brr_size = brr_filesize;

	int32_t loop_sample = 0;
	bool has_header = false;
	switch (brr_size % 9) {
	case 0:
		break;

	case 2: {
		uint16_t loop_offset = data[0] | (data[1] << 8);
		loop_sample = loop_offset / 9 * 16;

		if (loop_offset % 9 == 0) {
			printf("%s: addmusicM header detected, loop offset = $%04x (sample #%d).\n", brr_filename.c_str(), loop_offset, loop_sample);
			has_header = true;
		}
		else {
			fprintf(stderr, "%s: warning: illegal length, skip first %d bytes.\n", brr_filename.c_str(), (int)(brr_filesize % 9));
		}

		brr += brr_filesize % 9;
		brr_size -= brr_filesize % 9;
		break;
	}

	default:
		fprintf(stderr, "%s: warning: illegal length, skip first %d bytes.\n", brr_filename.c_str(), (int)(brr_filesize % 9));
		brr += brr_filesize % 9;
		brr_size -= brr_filesize % 9;
		break;
	}

	strcpy(path_c, brr_filename.c_str());
	path_basename(path_c);
	path_stripext(path_c);
	strcat(path_c, ".wav");
	std::string wav_filename(path_c);

	bool looped = false;
	WavWriter wave(SPCSampDir::decode_brr(brr, brr_size, &looped));
	wave.samplerate = pitch * 32000 / 0x1000;
	wave.bitwidth = 16;
	wave.channels = 1;
	if (has_header && looped) {
		wave.SetLoopSample(loop_sample);
	}

	if (!wave.WriteFile(wav_filename)) {
		fprintf(stderr, "Error: %s: %s\n", wav_filename.c_str(), wave.message().c_str());
		delete[] data;
		return false;
	}

	delete[] data;
	return true;
}