mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-02-22 11:51:56 +00:00
Split preset parsing from Soundfont file open
This commit is contained in:
parent
8051b43c02
commit
3d05360f33
3 changed files with 54 additions and 10 deletions
|
@ -272,12 +272,17 @@ int fluid_defsfont_load(fluid_defsfont_t* defsfont, const fluid_file_callbacks_t
|
|||
}
|
||||
|
||||
/* The actual loading is done in the sfont and sffile files */
|
||||
sfdata = fluid_sffile_load(file, fcbs);
|
||||
sfdata = fluid_sffile_open(file, fcbs);
|
||||
if (sfdata == NULL) {
|
||||
FLUID_LOG(FLUID_ERR, "Couldn't load soundfont file");
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
if (fluid_sffile_parse_presets(sfdata) == FLUID_FAILED) {
|
||||
FLUID_LOG(FLUID_ERR, "Couldn't parse presets from soundfont file");
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
/* Keep track of the position and size of the sample data because
|
||||
it's loaded separately (and might be unoaded/reloaded in future) */
|
||||
defsfont->samplepos = sfdata->samplepos;
|
||||
|
@ -386,7 +391,7 @@ fluid_defsfont_load_sampledata(fluid_defsfont_t* defsfont, const fluid_file_call
|
|||
SFData *sfdata;
|
||||
int ret;
|
||||
|
||||
sfdata = fluid_sffile_load(defsfont->filename, fcbs);
|
||||
sfdata = fluid_sffile_open(defsfont->filename, fcbs);
|
||||
if (sfdata == NULL) {
|
||||
FLUID_LOG(FLUID_ERR, "Couldn't load soundfont file");
|
||||
return FLUID_FAILED;
|
||||
|
|
|
@ -259,7 +259,8 @@ static const unsigned short invalid_preset_gen[] = {
|
|||
} while (0)
|
||||
|
||||
|
||||
static int load_body(SFData *sf, unsigned int size);
|
||||
static int load_header(SFData *sf);
|
||||
static int load_body(SFData *sf);
|
||||
static int process_info(SFData *sf, int size);
|
||||
static int process_sdta(SFData *sf, unsigned int size);
|
||||
static int process_pdta(SFData *sf, int size);
|
||||
|
@ -294,9 +295,9 @@ static void delete_zone(SFZone *zone);
|
|||
*
|
||||
* @param fname filename
|
||||
* @param fcbs file callback structure
|
||||
* @return the parsed SoundFont as SFData structure or NULL on error
|
||||
* @return the partially parsed SoundFont as SFData structure or NULL on error
|
||||
*/
|
||||
SFData *fluid_sffile_load(const char *fname, const fluid_file_callbacks_t *fcbs)
|
||||
SFData *fluid_sffile_open(const char *fname, const fluid_file_callbacks_t *fcbs)
|
||||
{
|
||||
SFData *sf;
|
||||
int fsize = 0;
|
||||
|
@ -334,6 +335,7 @@ SFData *fluid_sffile_load(const char *fname, const fluid_file_callbacks_t *fcbs)
|
|||
FLUID_LOG(FLUID_ERR, "Get end of file position failed");
|
||||
goto error_exit;
|
||||
}
|
||||
sf->filesize = fsize;
|
||||
|
||||
if (fcbs->fseek(sf->sffd, 0, SEEK_SET) == FLUID_FAILED)
|
||||
{
|
||||
|
@ -341,7 +343,7 @@ SFData *fluid_sffile_load(const char *fname, const fluid_file_callbacks_t *fcbs)
|
|||
goto error_exit;
|
||||
}
|
||||
|
||||
if (!load_body(sf, fsize))
|
||||
if (!load_header(sf))
|
||||
{
|
||||
goto error_exit;
|
||||
}
|
||||
|
@ -353,6 +355,21 @@ error_exit:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse all preset information from the soundfont
|
||||
*
|
||||
* @return FLUID_OK on success, otherwise FLUID_FAILED
|
||||
*/
|
||||
int fluid_sffile_parse_presets(SFData *sf)
|
||||
{
|
||||
if (!load_body(sf))
|
||||
{
|
||||
return FLUID_FAILED;
|
||||
}
|
||||
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
/* Load sample data from the soundfont file
|
||||
*
|
||||
* @param sf SFFile instance
|
||||
|
@ -534,7 +551,7 @@ static int chunkid(unsigned int id)
|
|||
return UNKN_ID;
|
||||
}
|
||||
|
||||
static int load_body(SFData *sf, unsigned int size)
|
||||
static int load_header(SFData *sf)
|
||||
{
|
||||
SFChunk chunk;
|
||||
|
||||
|
@ -552,7 +569,7 @@ static int load_body(SFData *sf, unsigned int size)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (chunk.size != size - 8)
|
||||
if (chunk.size != sf->filesize - 8)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "SoundFont file size mismatch");
|
||||
return FALSE;
|
||||
|
@ -588,11 +605,27 @@ static int load_body(SFData *sf, unsigned int size)
|
|||
FLUID_LOG(FLUID_ERR, "Invalid ID found when expecting HYDRA chunk");
|
||||
return FALSE;
|
||||
}
|
||||
if (!process_pdta(sf, chunk.size))
|
||||
|
||||
sf->hydrapos = sf->fcbs->ftell(sf->sffd);
|
||||
sf->hydrasize = chunk.size;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int load_body(SFData *sf)
|
||||
{
|
||||
if (sf->fcbs->fseek(sf->sffd, sf->hydrapos, SEEK_SET) == FLUID_FAILED)
|
||||
{
|
||||
FLUID_LOG(FLUID_ERR, "Failed to seek to HYDRA position");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!process_pdta(sf, sf->hydrasize))
|
||||
return FALSE;
|
||||
|
||||
if (!fixup_pgen(sf))
|
||||
return FALSE;
|
||||
|
||||
if (!fixup_igen(sf))
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -134,6 +134,8 @@ struct _SFData
|
|||
SFVersion version; /* sound font version */
|
||||
SFVersion romver; /* ROM version */
|
||||
|
||||
unsigned int filesize;
|
||||
|
||||
unsigned int samplepos; /* position within sffd of the sample chunk */
|
||||
unsigned int samplesize; /* length within sffd of the sample chunk */
|
||||
|
||||
|
@ -141,6 +143,9 @@ struct _SFData
|
|||
sample support */
|
||||
unsigned int sample24size; /* length within sffd of the sm24 chunk */
|
||||
|
||||
unsigned int hydrapos;
|
||||
unsigned int hydrasize;
|
||||
|
||||
char *fname; /* file name */
|
||||
FILE *sffd; /* loaded sfont file descriptor */
|
||||
const fluid_file_callbacks_t *fcbs; /* file callbacks used to read this file */
|
||||
|
@ -204,8 +209,9 @@ struct _SFShdr
|
|||
};
|
||||
|
||||
/* Public functions */
|
||||
SFData *fluid_sffile_load(const char *fname, const fluid_file_callbacks_t *fcbs);
|
||||
SFData *fluid_sffile_open(const char *fname, const fluid_file_callbacks_t *fcbs);
|
||||
void fluid_sffile_close(SFData *sf);
|
||||
int fluid_sffile_parse_presets(SFData *sf);
|
||||
int fluid_sffile_read_sample_data(SFData *sf, unsigned int start, unsigned int count,
|
||||
short **data, char **data24);
|
||||
|
||||
|
|
Loading…
Reference in a new issue