parse sm24 chunk

This commit is contained in:
derselbst 2017-10-07 11:34:53 +02:00
parent 680d4d51a4
commit 8fd8a75b9f
3 changed files with 57 additions and 5 deletions

View file

@ -244,7 +244,8 @@ struct _fluid_sample_t
int pitchadj; /**< Fine pitch adjustment (+/- 99 cents) */
int sampletype; /**< Values: #FLUID_SAMPLETYPE_MONO, FLUID_SAMPLETYPE_RIGHT, FLUID_SAMPLETYPE_LEFT, FLUID_SAMPLETYPE_ROM */
int valid; /**< Should be TRUE if sample data is valid, FALSE otherwise (in which case it will not be synthesized) */
short* data; /**< Pointer to the sample's data */
short* data; /**< Pointer to the sample's 16 bit PCM data */
char* data24; /**< If not NULL, pointer to the sample's contains the least significant byte counterparts to each sample data point */
int amplitude_that_reaches_noise_floor_is_valid; /**< Indicates if \a amplitude_that_reaches_noise_floor is valid (TRUE), set to FALSE initially to calculate. */
double amplitude_that_reaches_noise_floor; /**< The amplitude at which the sample's loop will be below the noise floor. For voice off optimization, calculated automatically. */

View file

@ -2134,7 +2134,7 @@ static int fixup_sample (SFData * sf);
char idlist[] = {
"RIFFLISTsfbkINFOsdtapdtaifilisngINAMiromiverICRDIENGIPRD"
"ICOPICMTISFTsnamsmplphdrpbagpmodpgeninstibagimodigenshdr"
"ICOPICMTISFTsnamsmplphdrpbagpmodpgeninstibagimodigenshdrsm24"
};
static unsigned int sdtachunk_size;
@ -2411,8 +2411,51 @@ process_sdta (unsigned int size, SFData * sf, FILE * fd)
sdtachunk_size = chunk.size;
sf->samplesize = chunk.size;
FSKIP (chunk.size, fd);
size -= chunk.size;
if(sf->version.major >= 2 && sf->version.minor >= 4)
{
/* any chance to find another chunk here? */
if(size > 8)
{
/* read sub chunk */
READCHUNK (&chunk, fd);
size -= 8;
if (chunkid (chunk.id) == SM24_ID)
{
int sm24size, sdtahalfsize;
FLUID_LOG(FLUID_DBG, "Found SM24 chunk");
if (chunk.size > size)
{
FLUID_LOG(FLUID_WARN, "SM24 exeeds SDTA chunk, ignoring SM24");
goto ret; // no error
}
sdtahalfsize = sf->samplesize/2;
/* + 1 byte in the case that half the size of smpl chunk is an odd value */
sdtahalfsize += sdtahalfsize%2;
sm24size = chunk.size;
if (sdtahalfsize != sm24size)
{
FLUID_LOG(FLUID_WARN, "SM24 not equal to half the size of SMPL chunk (0x%X != 0x%X), ignoring SM24", sm24size, sdtahalfsize);
goto ret; // no error
}
/* sample data24 follows */
sf->hassample24 = TRUE;
sf->sample24pos = ftell (fd);
sf->sample24size = chunk.size;
}
}
}
ret:
FSKIP (size, fd);
return (OK);
}
@ -3337,6 +3380,9 @@ fixup_sample (SFData * sf)
{
sam = (SFSample *) (p->data);
if(sf->samplesize != sdtachunk_size)
FLUID_LOG(FLUID_ERR, "OMGOMGOMGOM");
/* The SoundFont 2.4 spec defines the loopstart index as the first sample point of the loop */
invalid_loopstart = (sam->loopstart < sam->start) || (sam->loopstart >= sam->loopend);
/* while loopend is the first point AFTER the last sample of the loop.

View file

@ -145,6 +145,10 @@ typedef struct _SFData
SFVersion romver; /* ROM version */
unsigned int samplepos; /* position within sffd of the sample chunk */
unsigned int samplesize; /* length within sffd of the sample chunk */
int hassample24; /* TRUE if valid 24 bit samples are available (i.e. the two members below are set */
unsigned int sample24pos; /* position within sffd of the sm24 chunk */
unsigned int sample24size; /* length within sffd of the sm24 chunk */
char *fname; /* file name */
FILE *sffd; /* loaded sfont file descriptor */
fluid_list_t *info; /* linked list of info strings (1st byte is ID) */
@ -166,7 +170,8 @@ enum
SNAM_ID, SMPL_ID, /* sample ids */
PHDR_ID, PBAG_ID, PMOD_ID, PGEN_ID, /* preset ids */
IHDR_ID, IBAG_ID, IMOD_ID, IGEN_ID, /* instrument ids */
SHDR_ID /* sample info */
SHDR_ID, /* sample info */
SM24_ID
};
/* generator types */
@ -403,7 +408,7 @@ struct _fluid_defsfont_t
{
char* filename; /* the filename of this soundfont */
unsigned int samplepos; /* the position in the file at which the sample data starts */
unsigned int samplesize; /* the size of the sample data */
unsigned int samplesize; /* the size of the sample data in bytes */
short* sampledata; /* the sample data, loaded in ram */
fluid_list_t* sample; /* the samples in this soundfont */
fluid_defpreset_t* preset; /* the presets of this soundfont */