Exemple #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;
}
Exemple #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;
}
Exemple #3
0
static int process_sdta(int size, SFInfo *sf, FILE *fd)
{
	while (size > 0) {
		SFChunk chunk;

		/* read a sub chunk */
		READCHUNK(chunk, fd); size -= 8;
		if (feof(fd))
			return -1;

		switch (chunkid(chunk.id)) {
		case SNAM_ID:
			/* sample name list */
			load_sample_names(chunk.size, sf, fd);
			break;
		case SMPL_ID:
			/* sample data starts from here */
			sf->samplepos = ftell(fd);
			sf->samplesize = chunk.size;
			FSKIP(chunk.size, fd);
			break;
		default:
			FSKIP(chunk.size, fd);
			break;
		}
		size -= chunk.size;
	}
	return 0;
}
Exemple #4
0
static int process_info(int size, SFInfo *sf, FILE *fd)
{
	sf->infopos = ftell(fd);
	sf->infosize = size;
	
	/* parse the buffer */
	while (size > 0) {
		SFChunk chunk;

		/* read a sub chunk */
		READCHUNK(chunk, fd); size -= 8;
		if (feof(fd))
			return -1;

		switch (chunkid(chunk.id)) {
		case IFIL_ID:
			/* soundfont file version */
			READW(sf->version, fd);
			READW(sf->minorversion, fd);
			break;
		case INAM_ID:
			/* name of the font */
			sf->sf_name = (char*)safe_malloc(chunk.size + 1);
			fread(sf->sf_name, 1, chunk.size, fd);
			sf->sf_name[chunk.size] = 0;
			break;
		default:
			FSKIP(chunk.size, fd);
			break;
		}
		size -= chunk.size;
	}
	return 0;
}
Exemple #5
0
int Instruments::process_sdta(int size, SFInfo *sf, struct timidity_file *fd)
{
	while (size > 0) {
		SFChunk chunk;

		/* read a sub chunk */
		if (READCHUNK(&chunk, fd) <= 0)
			return -1;
		size -= 8;

		ctl_cmsg(CMSG_INFO, VERB_DEBUG, " %c%c%c%c:",
			chunk.id[0], chunk.id[1], chunk.id[2], chunk.id[3]);
		switch (chunkid(chunk.id)) {
		case SNAM_ID:
			/* sample name list */
			load_sample_names(chunk.size, sf, fd);
			break;
		case SMPL_ID:
			/* sample data starts from here */
			sf->samplepos = tf_tell(fd);
			sf->samplesize = chunk.size;
			FSKIP(chunk.size, fd);
			break;
		default:
			FSKIP(chunk.size, fd);
			break;
		}
		size -= chunk.size;
	}
	return 0;
}
Exemple #6
0
int Instruments::process_pdta(int size, SFInfo *sf, struct timidity_file *fd)
{
	while (size > 0) {
		SFChunk chunk;

		/* read a subchunk */
		if (READCHUNK(&chunk, fd) <= 0)
			return -1;
		size -= 8;

		ctl_cmsg(CMSG_INFO, VERB_DEBUG, " %c%c%c%c:",
			chunk.id[0], chunk.id[1], chunk.id[2], chunk.id[3]);
		switch (chunkid(chunk.id)) {
		case PHDR_ID:
			load_preset_header(chunk.size, sf, fd);
			break;
		case PBAG_ID:
			load_bag(chunk.size, &prbags, fd);
			break;
		case PGEN_ID:
			load_gen(chunk.size, &prbags, fd);
			break;
		case INST_ID:
			load_inst_header(chunk.size, sf, fd);
			break;
		case IBAG_ID:
			load_bag(chunk.size, &inbags, fd);
			break;
		case IGEN_ID:
			load_gen(chunk.size, &inbags, fd);
			break;
		case SHDR_ID:
			load_sample_info(chunk.size, sf, fd);
			break;
		case PMOD_ID: /* ignored */
		case IMOD_ID: /* ingored */
		default:
			FSKIP(chunk.size, fd);
			break;
		}
		size -= chunk.size;
	}
	return 0;
}
Exemple #7
0
static int process_pdta(int size, SFInfo *sf, FILE *fd)
{
	while (size > 0) {
		SFChunk chunk;

		/* read a subchunk */
		READCHUNK(chunk, fd); size -= 8;
		if (feof(fd))
			return -1;

		switch (chunkid(chunk.id)) {
		case PHDR_ID:
			load_preset_header(chunk.size, sf, fd);
			break;
		case PBAG_ID:
			load_bag(chunk.size, &prbags, fd);
			break;
		case PGEN_ID:
			load_gen(chunk.size, &prbags, fd);
			break;
		case INST_ID:
			load_inst_header(chunk.size, sf, fd);
			break;
		case IBAG_ID:
			load_bag(chunk.size, &inbags, fd);
			break;
		case IGEN_ID:
			load_gen(chunk.size, &inbags, fd);
			break;
		case SHDR_ID:
			load_sample_info(chunk.size, sf, fd);
			break;
		case PMOD_ID: /* ignored */
		case IMOD_ID: /* ingored */
		default:
			FSKIP(chunk.size, fd);
			break;
		}
		size -= chunk.size;
	}
	return 0;
}
Exemple #8
0
int Instruments::process_info(int size, SFInfo *sf, struct timidity_file *fd)
{
	sf->infopos = tf_tell(fd);
	sf->infosize = size;

	/* parse the buffer */
	while (size > 0) {
		SFChunk chunk;

		/* read a sub chunk */
		if (READCHUNK(&chunk, fd) <= 0)
			return -1;
		size -= 8;

		ctl_cmsg(CMSG_INFO, VERB_DEBUG, " %c%c%c%c:",
			chunk.id[0], chunk.id[1], chunk.id[2], chunk.id[3]);
		switch (chunkid(chunk.id)) {
		case IFIL_ID:
			/* soundfont file version */
			READW(&sf->version, fd);
			READW(&sf->minorversion, fd);
			ctl_cmsg(CMSG_INFO, VERB_DEBUG,
				"  version %d, minor %d",
				sf->version, sf->minorversion);
			break;
		case INAM_ID:
			/* name of the font */
			sf->sf_name = (char*)safe_malloc(chunk.size + 1);
			tf_read(sf->sf_name, 1, chunk.size, fd);
			sf->sf_name[chunk.size] = 0;
			ctl_cmsg(CMSG_INFO, VERB_DEBUG,
				"  name %s", sf->sf_name);
			break;

		default:
			FSKIP(chunk.size, fd);
			break;
		}
		size -= chunk.size;
	}
	return 0;
}