Path: blob/master/libs/fluidsynth/src/sfloader/fluid_sfont.h
4396 views
/* FluidSynth - A Software Synthesizer1*2* Copyright (C) 2003 Peter Hanappe and others.3*4* This library is free software; you can redistribute it and/or5* modify it under the terms of the GNU Lesser General Public License6* as published by the Free Software Foundation; either version 2.1 of7* the License, or (at your option) any later version.8*9* This library is distributed in the hope that it will be useful, but10* WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12* Lesser General Public License for more details.13*14* You should have received a copy of the GNU Lesser General Public15* License along with this library; if not, write to the Free16* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA17* 02110-1301, USA18*/192021#ifndef _PRIV_FLUID_SFONT_H22#define _PRIV_FLUID_SFONT_H2324#include "fluidsynth.h"2526int fluid_sample_validate(fluid_sample_t *sample, unsigned int max_end);27int fluid_sample_sanitize_loop(fluid_sample_t *sample, unsigned int max_end);2829/*30* Utility macros to access soundfonts, presets, and samples31*/3233#define fluid_sfloader_delete(_loader) { if ((_loader) && (_loader)->free) (*(_loader)->free)(_loader); }34#define fluid_sfloader_load(_loader, _filename) (*(_loader)->load)(_loader, _filename)353637#define fluid_sfont_delete_internal(_sf) ( ((_sf) && (_sf)->free)? (*(_sf)->free)(_sf) : 0)383940#define fluid_preset_delete_internal(_preset) \41{ if ((_preset) && (_preset)->free) { (*(_preset)->free)(_preset); }}4243#define fluid_preset_noteon(_preset,_synth,_ch,_key,_vel) \44(*(_preset)->noteon)(_preset,_synth,_ch,_key,_vel)4546#define fluid_preset_notify(_preset,_reason,_chan) \47( ((_preset) && (_preset)->notify) ? (*(_preset)->notify)(_preset,_reason,_chan) : FLUID_OK )484950#define fluid_sample_incr_ref(_sample) { (_sample)->refcount++; }5152#define fluid_sample_decr_ref(_sample) \53(_sample)->refcount--; \54if (((_sample)->refcount == 0) && ((_sample)->notify)) \55(*(_sample)->notify)(_sample, FLUID_SAMPLE_DONE);56575859/**60* File callback structure to enable custom soundfont loading (e.g. from memory).61*/62struct _fluid_file_callbacks_t63{64fluid_sfloader_callback_open_t fopen;65fluid_sfloader_callback_read_t fread;66fluid_sfloader_callback_seek_t fseek;67fluid_sfloader_callback_close_t fclose;68fluid_sfloader_callback_tell_t ftell;69};7071/**72* SoundFont loader structure.73*/74struct _fluid_sfloader_t75{76void *data; /**< User defined data pointer used by _fluid_sfloader_t::load() */7778/** Callback structure specifying file operations used during soundfont loading to allow custom loading, such as from memory */79fluid_file_callbacks_t file_callbacks;8081fluid_sfloader_free_t free;8283fluid_sfloader_load_t load;84};8586/**87* Virtual SoundFont instance structure.88*/89struct _fluid_sfont_t90{91void *data; /**< User defined data */92int id; /**< SoundFont ID */93int refcount; /**< SoundFont reference count (1 if no presets referencing it) */94int bankofs; /**< Bank offset */9596fluid_sfont_free_t free;9798fluid_sfont_get_name_t get_name;99100fluid_sfont_get_preset_t get_preset;101102fluid_sfont_iteration_start_t iteration_start;103104fluid_sfont_iteration_next_t iteration_next;105};106107/**108* Virtual SoundFont preset.109*/110struct _fluid_preset_t111{112void *data; /**< User supplied data */113fluid_sfont_t *sfont; /**< Parent virtual SoundFont */114115fluid_preset_free_t free;116117fluid_preset_get_name_t get_name;118119fluid_preset_get_banknum_t get_banknum;120121fluid_preset_get_num_t get_num;122123fluid_preset_noteon_t noteon;124125/**126* Virtual SoundFont preset notify method.127* @param preset Virtual SoundFont preset128* @param reason #FLUID_PRESET_SELECTED or #FLUID_PRESET_UNSELECTED129* @param chan MIDI channel number130* @return Should return #FLUID_OK131*132* Implement this optional method if the preset needs to be notified about133* preset select and unselect events.134*135* This method may be called from within synthesis context and therefore136* should be as efficient as possible and not perform any operations considered137* bad for realtime audio output (memory allocations and other OS calls).138*/139int (*notify)(fluid_preset_t *preset, int reason, int chan);140};141142/**143* Virtual SoundFont sample.144*/145struct _fluid_sample_t146{147char name[21]; /**< Sample name */148149/* The following four sample pointers store the original pointers from the Soundfont150* file. They are never changed after loading and are used to re-create the151* actual sample pointers after a sample has been unloaded and loaded again. The152* actual sample pointers get modified during loading for SF3 (compressed) samples153* and individually loaded SF2 samples. */154unsigned int source_start;155unsigned int source_end;156unsigned int source_loopstart;157unsigned int source_loopend;158159unsigned int start; /**< Start index */160unsigned int end; /**< End index, index of last valid sample point (contrary to SF spec) */161unsigned int loopstart; /**< Loop start index */162unsigned int loopend; /**< Loop end index, first point following the loop (superimposed on loopstart) */163164unsigned int samplerate; /**< Sample rate */165int origpitch; /**< Original pitch (MIDI note number, 0-127) */166int pitchadj; /**< Fine pitch adjustment (+/- 99 cents) */167int sampletype; /**< Specifies the type of this sample as indicated by the #fluid_sample_type enum */168int auto_free; /**< TRUE if _fluid_sample_t::data and _fluid_sample_t::data24 should be freed upon sample destruction */169short *data; /**< Pointer to the sample's 16 bit PCM data */170char *data24; /**< If not NULL, pointer to the least significant byte counterparts of each sample data point in order to create 24 bit audio samples */171172int amplitude_that_reaches_noise_floor_is_valid; /**< Indicates if \a amplitude_that_reaches_noise_floor is valid (TRUE), set to FALSE initially to calculate. */173double 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. */174175unsigned int refcount; /**< Count of voices using this sample */176int preset_count; /**< Count of selected presets using this sample (used for dynamic sample loading) */177178/**179* Implement this function to receive notification when sample is no longer used.180* @param sample Virtual SoundFont sample181* @param reason #FLUID_SAMPLE_DONE only currently182* @return Should return #FLUID_OK183*/184int (*notify)(fluid_sample_t *sample, int reason);185};186187188#endif /* _PRIV_FLUID_SFONT_H */189190191