Path: blob/master/libs/fluidsynth/src/sfloader/fluid_sffile.h
4396 views
/* FluidSynth - A Software Synthesizer1*2* Copyright (C) 2003 Peter Hanappe and others.3*4* SoundFont loading code borrowed from Smurf SoundFont Editor by Josh Green5*6* This library is free software; you can redistribute it and/or7* modify it under the terms of the GNU Lesser General Public License8* as published by the Free Software Foundation; either version 2.1 of9* the License, or (at your option) any later version.10*11* This library is distributed in the hope that it will be useful, but12* WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14* Lesser General Public License for more details.15*16* You should have received a copy of the GNU Lesser General Public17* License along with this library; if not, write to the Free18* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA19* 02110-1301, USA20*/212223#ifndef _FLUID_SFFILE_H24#define _FLUID_SFFILE_H252627#include "fluid_gen.h"28#include "fluid_list.h"29#include "fluid_mod.h"30#include "fluidsynth.h"31#include "fluid_sys.h"323334/* Sound Font structure defines */3536/* Forward declarations */37typedef union _SFGenAmount SFGenAmount;38typedef struct _SFVersion SFVersion;39typedef struct _SFMod SFMod;40typedef struct _SFGen SFGen;41typedef struct _SFZone SFZone;42typedef struct _SFSample SFSample;43typedef struct _SFInst SFInst;44typedef struct _SFPreset SFPreset;45typedef struct _SFData SFData;46typedef struct _SFChunk SFChunk;474849struct _SFVersion50{51/* version structure */52unsigned short major;53unsigned short minor;54};5556struct _SFMod57{58/* Modulator structure */59unsigned short src; /* source modulator */60unsigned short dest; /* destination generator */61signed short amount; /* signed, degree of modulation */62unsigned short amtsrc; /* second source controls amnt of first */63unsigned short trans; /* transform applied to source */64};6566union _SFGenAmount /* Generator amount structure */67{68signed short sword; /* signed 16 bit value */69unsigned short uword; /* unsigned 16 bit value */70struct71{72unsigned char lo; /* low value for ranges */73unsigned char hi; /* high value for ranges */74} range;75};7677struct _SFGen78{79/* Generator structure */80unsigned short id; /* generator ID */81SFGenAmount amount; /* generator value */82};8384struct _SFZone85{86/* Sample/instrument zone structure */87fluid_list_t *gen; /* list of generators */88fluid_list_t *mod; /* list of modulators */89};9091struct _SFSample92{93/* Sample structure */94char name[21]; /* Name of sample */95int idx; /* Index of this instrument in the Soundfont */96unsigned int start; /* Offset in sample area to start of sample */97unsigned int end; /* Offset from start to end of sample,98this is the last point of the99sample, the SF spec has this as the1001st point after, corrected on101load/save */102unsigned int loopstart; /* Offset from start to start of loop */103unsigned int loopend; /* Offset from start to end of loop,104marks the first point after loop,105whose sample value is ideally106equivalent to loopstart */107unsigned int samplerate; /* Sample rate recorded at */108unsigned char origpitch; /* root midi key number */109signed char pitchadj; /* pitch correction in cents */110unsigned short sampletype; /* 1 mono,2 right,4 left,linked 8,0x8000=ROM */111fluid_sample_t *fluid_sample; /* Imported sample (fixed up in fluid_defsfont_load) */112};113114struct _SFInst115{116/* Instrument structure */117char name[21]; /* Name of instrument */118int idx; /* Index of this instrument in the Soundfont */119fluid_list_t *zone; /* list of instrument zones */120};121122struct _SFPreset123{124/* Preset structure */125char name[21]; /* preset name */126unsigned short prenum; /* preset number */127unsigned short bank; /* bank number */128fluid_list_t *zone; /* list of preset zones */129};130131/* NOTE: sffd is also used to determine if sound font is new (NULL) */132struct _SFData133{134/* Sound font data structure */135SFVersion version; /* sound font version */136SFVersion romver; /* ROM version */137138unsigned int filesize;139140unsigned int samplepos; /* position within sffd of the sample chunk */141unsigned int samplesize; /* length within sffd of the sample chunk */142143unsigned int sample24pos; /* position within sffd of the sm24 chunk, set to zero if no 24 bit144sample support */145unsigned int sample24size; /* length within sffd of the sm24 chunk */146147unsigned int hydrapos;148unsigned int hydrasize;149150char *fname; /* file name */151FILE *sffd; /* loaded sfont file descriptor */152const fluid_file_callbacks_t *fcbs; /* file callbacks used to read this file */153154fluid_rec_mutex_t mtx; /* this mutex can be used to synchronize calls to fcbs when using multiple threads (e.g. SF3 loading) */155156fluid_list_t *info; /* linked list of info strings (1st byte is ID) */157fluid_list_t *preset; /* linked list of preset info */158fluid_list_t *inst; /* linked list of instrument info */159fluid_list_t *sample; /* linked list of sample info */160};161162/* functions */163164165/*-----------------------------------sffile.h----------------------------*/166/*167File structures and routines (used to be in sffile.h)168*/169170/* sfont file data structures */171struct _SFChunk172{173/* RIFF file chunk structure */174unsigned int id; /* chunk id */175unsigned int size; /* size of the following chunk */176};177178/* Public functions */179SFData *fluid_sffile_open(const char *fname, const fluid_file_callbacks_t *fcbs);180void fluid_sffile_close(SFData *sf);181int fluid_sffile_parse_presets(SFData *sf);182int fluid_sffile_read_sample_data(SFData *sf, unsigned int sample_start, unsigned int sample_end,183int sample_type, short **data, char **data24);184185186/* extern only for unit test purposes */187int load_igen(SFData *sf, int size);188int load_pgen(SFData *sf, int size);189void delete_preset(SFPreset *preset);190void delete_inst(SFInst *inst);191void delete_zone(SFZone *zone);192193#endif /* _FLUID_SFFILE_H */194195196