Beispiel #1
0
int Instruments::load_soundfont(SFInfo *sf, struct timidity_file *fd)
{
	SFChunk chunk;

	sf->preset = NULL;
	sf->sample = NULL;
	sf->inst = NULL;
	sf->sf_name = NULL;

	prbags.bag = inbags.bag = NULL;
	prbags.gen = inbags.gen = NULL;
	prbags.nbags = inbags.nbags =
		prbags.ngens = inbags.ngens = 0;

	/* check RIFF file header */
	READCHUNK(&chunk, fd);
	if (chunkid(chunk.id) != RIFF_ID) {
		ctl_cmsg(CMSG_ERROR, VERB_NORMAL,
			"%s: *** not a RIFF file", fd->filename.c_str());
		return -1;
	}
	/* check file id */
	READID(chunk.id, fd);
	if (chunkid(chunk.id) != SFBK_ID) {
		ctl_cmsg(CMSG_ERROR, VERB_NORMAL,
			"%s: *** not a SoundFont file", fd->filename.c_str());
		return -1;
	}

	for (;;) {
		if (READCHUNK(&chunk, fd) <= 0)
			break;
		else if (chunkid(chunk.id) == LIST_ID) {
			if (process_list(chunk.size, sf, fd))
				break;
		}
		else {
			ctl_cmsg(CMSG_WARNING, VERB_NORMAL,	"%s: *** illegal id in level 0: %4.4s %4d",	fd->filename.c_str(), chunk.id, chunk.size);			
			FSKIP(chunk.size, fd);
			// Not aborting here will inevitably crash.
			return -1;
		}
	}

	/* parse layer structure */
	convert_layers(sf);

	/* free private tables */
	if (prbags.bag) free(prbags.bag);
	if (prbags.gen) free(prbags.gen);
	if (inbags.bag) free(inbags.bag);
	if (inbags.gen) free(inbags.gen);

	return 0;
}
Beispiel #2
0
int awe_load_soundfont(SFInfo *sf, FILE *fd, int is_seekable)
{
	SFChunk chunk;

	seekable = is_seekable;

	sf->preset = NULL;
	sf->sample = NULL;
	sf->inst = NULL;
	sf->sf_name = NULL;

	prbags.bag = inbags.bag = NULL;
	prbags.gen = inbags.gen = NULL;

	/* check RIFF file header */
	READCHUNK(chunk, fd);
	if (chunkid(chunk.id) != RIFF_ID) {
		fprintf(stderr, "*** not a RIFF file\n");
		return -1;
	}
	/* check file id */
	READID(chunk.id, fd);
	if (chunkid(chunk.id) != SFBK_ID) {
		fprintf(stderr, "*** not a SoundFont file\n");
		return -1;
	}

	for (;;) {
		READCHUNK(chunk, fd);
		if (feof(fd))
			break;
		else if (chunkid(chunk.id) == LIST_ID) {
			if (process_list(chunk.size, sf, fd))
				break;
		} else {
			fprintf(stderr, "*** illegal id in level 0: %4.4s %4d\n",
				chunk.id, chunk.size);
			FSKIP(chunk.size, fd);
		}
	}

	/* parse layer structure */
	convert_layers(sf);

	/* free private tables */
	if (prbags.bag) free(prbags.bag);
	if (prbags.gen) free(prbags.gen);
	if (inbags.bag) free(inbags.bag);
	if (inbags.gen) free(inbags.gen);

	return 0;
}