synth.h
上传用户:tjmskj2
上传日期:2020-08-17
资源大小:577k
文件大小:14k
源码类别:

midi

开发平台:

C/C++

  1. /* FluidSynth - A Software Synthesizer
  2.  *
  3.  * Copyright (C) 2003  Peter Hanappe and others.
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public License
  7.  * as published by the Free Software Foundation; either version 2 of
  8.  * the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *  
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18.  * 02111-1307, USA
  19.  */
  20. #ifndef _FLUIDSYNTH_SYNTH_H
  21. #define _FLUIDSYNTH_SYNTH_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /**
  26.  * @file synth.h
  27.  * @brief Embeddable SoundFont synthesizer
  28.  *  
  29.  * You create a new synthesizer with new_fluid_synth() and you destroy
  30.  * if with delete_fluid_synth(). Use the settings structure to specify
  31.  * the synthesizer characteristics. 
  32.  *
  33.  * You have to load a SoundFont in order to hear any sound. For that
  34.  * you use the fluid_synth_sfload() function.
  35.  *
  36.  * You can use the audio driver functions described below to open
  37.  * the audio device and create a background audio thread.
  38.  *  
  39.  * The API for sending MIDI events is probably what you expect:
  40.  * fluid_synth_noteon(), fluid_synth_noteoff(), ...
  41.  */
  42. #define FLUID_SYNTH_CHANNEL_INFO_NAME_SIZE   32    /**< Length of channel info name field (including zero terminator) */
  43. /**
  44.  * Channel information structure for fluid_synth_get_channel_info().
  45.  * @since 1.1.1
  46.  */
  47. struct _fluid_synth_channel_info_t
  48. {
  49.   int assigned : 1;     /**< TRUE if a preset is assigned, FALSE otherwise */
  50.   /* Reserved flag bits (at the least 31) */
  51.   int sfont_id;         /**< ID of parent SoundFont */
  52.   int bank;             /**< MIDI bank number (0-16383) */
  53.   int program;          /**< MIDI program number (0-127) */
  54.   char name[FLUID_SYNTH_CHANNEL_INFO_NAME_SIZE];     /**< Channel preset name */
  55.   char reserved[32];    /**< Reserved data for future expansion */
  56. };
  57. FLUIDSYNTH_API fluid_synth_t* new_fluid_synth(fluid_settings_t* settings);
  58. FLUIDSYNTH_API int delete_fluid_synth(fluid_synth_t* synth);
  59. FLUIDSYNTH_API fluid_settings_t* fluid_synth_get_settings(fluid_synth_t* synth);
  60. /* MIDI channel messages */
  61. FLUIDSYNTH_API int fluid_synth_noteon(fluid_synth_t* synth, int chan, int key, int vel);
  62. FLUIDSYNTH_API int fluid_synth_noteoff(fluid_synth_t* synth, int chan, int key);
  63. FLUIDSYNTH_API int fluid_synth_cc(fluid_synth_t* synth, int chan, int ctrl, int val);
  64. FLUIDSYNTH_API int fluid_synth_get_cc(fluid_synth_t* synth, int chan, int ctrl, int* pval);
  65. FLUIDSYNTH_API int fluid_synth_sysex(fluid_synth_t *synth, const char *data, int len,
  66.                                      char *response, int *response_len, int *handled, int dryrun);
  67. FLUIDSYNTH_API int fluid_synth_pitch_bend(fluid_synth_t* synth, int chan, int val);
  68. FLUIDSYNTH_API int fluid_synth_get_pitch_bend(fluid_synth_t* synth, int chan, int* ppitch_bend);
  69. FLUIDSYNTH_API int fluid_synth_pitch_wheel_sens(fluid_synth_t* synth, int chan, int val);
  70. FLUIDSYNTH_API int fluid_synth_get_pitch_wheel_sens(fluid_synth_t* synth, int chan, int* pval);
  71. FLUIDSYNTH_API int fluid_synth_program_change(fluid_synth_t* synth, int chan, int program);
  72. FLUIDSYNTH_API int fluid_synth_channel_pressure(fluid_synth_t* synth, int chan, int val);
  73. FLUIDSYNTH_API int fluid_synth_bank_select(fluid_synth_t* synth, int chan, unsigned int bank);
  74. FLUIDSYNTH_API int fluid_synth_sfont_select(fluid_synth_t* synth, int chan, unsigned int sfont_id);
  75. FLUIDSYNTH_API
  76. int fluid_synth_program_select(fluid_synth_t* synth, int chan, unsigned int sfont_id,
  77.                                unsigned int bank_num, unsigned int preset_num);
  78. FLUIDSYNTH_API int
  79. fluid_synth_program_select_by_sfont_name (fluid_synth_t* synth, int chan,
  80.                                           const char *sfont_name, unsigned int bank_num,
  81.                                           unsigned int preset_num);
  82. FLUIDSYNTH_API 
  83. int fluid_synth_get_program(fluid_synth_t* synth, int chan, unsigned int* sfont_id, 
  84.                             unsigned int* bank_num, unsigned int* preset_num);
  85. FLUIDSYNTH_API int fluid_synth_unset_program (fluid_synth_t *synth, int chan);
  86. FLUIDSYNTH_API int fluid_synth_get_channel_info (fluid_synth_t *synth, int chan,
  87.                                                  fluid_synth_channel_info_t *info);
  88. FLUIDSYNTH_API int fluid_synth_program_reset(fluid_synth_t* synth);
  89. FLUIDSYNTH_API int fluid_synth_system_reset(fluid_synth_t* synth);
  90. /* Low level access */
  91. FLUIDSYNTH_API fluid_preset_t* fluid_synth_get_channel_preset(fluid_synth_t* synth, int chan);
  92. FLUIDSYNTH_API int fluid_synth_start(fluid_synth_t* synth, unsigned int id, 
  93.      fluid_preset_t* preset, int audio_chan, 
  94.      int midi_chan, int key, int vel);
  95. FLUIDSYNTH_API int fluid_synth_stop(fluid_synth_t* synth, unsigned int id);
  96. /* SoundFont management */
  97. FLUIDSYNTH_API 
  98. int fluid_synth_sfload(fluid_synth_t* synth, const char* filename, int reset_presets);
  99. FLUIDSYNTH_API int fluid_synth_sfreload(fluid_synth_t* synth, unsigned int id);
  100. FLUIDSYNTH_API int fluid_synth_sfunload(fluid_synth_t* synth, unsigned int id, int reset_presets);
  101. FLUIDSYNTH_API int fluid_synth_add_sfont(fluid_synth_t* synth, fluid_sfont_t* sfont);
  102. FLUIDSYNTH_API void fluid_synth_remove_sfont(fluid_synth_t* synth, fluid_sfont_t* sfont);
  103. FLUIDSYNTH_API int fluid_synth_sfcount(fluid_synth_t* synth);
  104. FLUIDSYNTH_API fluid_sfont_t* fluid_synth_get_sfont(fluid_synth_t* synth, unsigned int num);
  105. FLUIDSYNTH_API fluid_sfont_t* fluid_synth_get_sfont_by_id(fluid_synth_t* synth, unsigned int id);
  106. FLUIDSYNTH_API fluid_sfont_t *fluid_synth_get_sfont_by_name (fluid_synth_t* synth,
  107.                                                              const char *name);
  108. FLUIDSYNTH_API int fluid_synth_set_bank_offset(fluid_synth_t* synth, int sfont_id, int offset);
  109. FLUIDSYNTH_API int fluid_synth_get_bank_offset(fluid_synth_t* synth, int sfont_id);
  110. /* Reverb  */
  111. FLUIDSYNTH_API void fluid_synth_set_reverb(fluid_synth_t* synth, double roomsize, 
  112.    double damping, double width, double level);
  113. FLUIDSYNTH_API void fluid_synth_set_reverb_on(fluid_synth_t* synth, int on);
  114. FLUIDSYNTH_API double fluid_synth_get_reverb_roomsize(fluid_synth_t* synth);
  115. FLUIDSYNTH_API double fluid_synth_get_reverb_damp(fluid_synth_t* synth);
  116. FLUIDSYNTH_API double fluid_synth_get_reverb_level(fluid_synth_t* synth);
  117. FLUIDSYNTH_API double fluid_synth_get_reverb_width(fluid_synth_t* synth);
  118. #define FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f      /**< Default reverb room size */
  119. #define FLUID_REVERB_DEFAULT_DAMP 0.0f          /**< Default reverb damping */
  120. #define FLUID_REVERB_DEFAULT_WIDTH 0.5f         /**< Default reverb width */
  121. #define FLUID_REVERB_DEFAULT_LEVEL 0.9f         /**< Default reverb level */
  122. /* Chorus */
  123. /**
  124.  * Chorus modulation waveform type.
  125.  */
  126. enum fluid_chorus_mod {
  127.   FLUID_CHORUS_MOD_SINE = 0,            /**< Sine wave chorus modulation */
  128.   FLUID_CHORUS_MOD_TRIANGLE = 1         /**< Triangle wave chorus modulation */
  129. };
  130. FLUIDSYNTH_API void fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level, 
  131.  double speed, double depth_ms, int type);
  132. FLUIDSYNTH_API void fluid_synth_set_chorus_on(fluid_synth_t* synth, int on);
  133. FLUIDSYNTH_API int fluid_synth_get_chorus_nr(fluid_synth_t* synth);
  134. FLUIDSYNTH_API double fluid_synth_get_chorus_level(fluid_synth_t* synth);
  135. FLUIDSYNTH_API double fluid_synth_get_chorus_speed_Hz(fluid_synth_t* synth);
  136. FLUIDSYNTH_API double fluid_synth_get_chorus_depth_ms(fluid_synth_t* synth);
  137. FLUIDSYNTH_API int fluid_synth_get_chorus_type(fluid_synth_t* synth); /* see fluid_chorus_mod */
  138. #define FLUID_CHORUS_DEFAULT_N 3                                /**< Default chorus voice count */
  139. #define FLUID_CHORUS_DEFAULT_LEVEL 2.0f                         /**< Default chorus level */
  140. #define FLUID_CHORUS_DEFAULT_SPEED 0.3f                         /**< Default chorus speed */
  141. #define FLUID_CHORUS_DEFAULT_DEPTH 8.0f                         /**< Default chorus depth */
  142. #define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE         /**< Default chorus waveform type */
  143. /* Audio and MIDI channels */
  144. FLUIDSYNTH_API int fluid_synth_count_midi_channels(fluid_synth_t* synth);
  145. FLUIDSYNTH_API int fluid_synth_count_audio_channels(fluid_synth_t* synth);
  146. FLUIDSYNTH_API int fluid_synth_count_audio_groups(fluid_synth_t* synth);
  147. FLUIDSYNTH_API int fluid_synth_count_effects_channels(fluid_synth_t* synth);
  148. /* Synthesis parameters */
  149. FLUIDSYNTH_API void fluid_synth_set_gain(fluid_synth_t* synth, float gain);
  150. FLUIDSYNTH_API float fluid_synth_get_gain(fluid_synth_t* synth);
  151. FLUIDSYNTH_API int fluid_synth_set_polyphony(fluid_synth_t* synth, int polyphony);
  152. FLUIDSYNTH_API int fluid_synth_get_polyphony(fluid_synth_t* synth);
  153. FLUIDSYNTH_API int fluid_synth_get_active_voice_count(fluid_synth_t* synth);
  154. FLUIDSYNTH_API int fluid_synth_get_internal_bufsize(fluid_synth_t* synth);
  155. FLUIDSYNTH_API 
  156. int fluid_synth_set_interp_method(fluid_synth_t* synth, int chan, int interp_method);
  157. /**
  158.  * Synthesis interpolation method.
  159.  */
  160. enum fluid_interp {
  161.   FLUID_INTERP_NONE = 0,        /**< No interpolation: Fastest, but questionable audio quality */
  162.   FLUID_INTERP_LINEAR = 1,      /**< Straight-line interpolation: A bit slower, reasonable audio quality */
  163.   FLUID_INTERP_4THORDER = 4,    /**< Fourth-order interpolation, good quality, the default */
  164.   FLUID_INTERP_7THORDER = 7,    /**< Seventh-order interpolation */
  165. };
  166. #define FLUID_INTERP_DEFAULT    FLUID_INTERP_4THORDER   /**< Default interpolation method from #fluid_interp. */
  167. #define FLUID_INTERP_HIGHEST    FLUID_INTERP_7THORDER   /**< Highest interpolation method from #fluid_interp. */
  168. /* Generator interface */
  169. FLUIDSYNTH_API 
  170. int fluid_synth_set_gen(fluid_synth_t* synth, int chan, int param, float value);
  171. FLUIDSYNTH_API int fluid_synth_set_gen2 (fluid_synth_t* synth, int chan,
  172.                                          int param, float value,
  173.                                          int absolute, int normalized);
  174. FLUIDSYNTH_API float fluid_synth_get_gen(fluid_synth_t* synth, int chan, int param);
  175. /* Tuning */
  176. FLUIDSYNTH_API 
  177. int fluid_synth_create_key_tuning(fluid_synth_t* synth, int bank, int prog,
  178.   const char* name, const double* pitch);
  179. FLUIDSYNTH_API
  180. int fluid_synth_activate_key_tuning(fluid_synth_t* synth, int bank, int prog,
  181.                                     const char* name, const double* pitch, int apply);
  182. FLUIDSYNTH_API 
  183. int fluid_synth_create_octave_tuning(fluid_synth_t* synth, int bank, int prog,
  184.                                      const char* name, const double* pitch);
  185. FLUIDSYNTH_API
  186. int fluid_synth_activate_octave_tuning(fluid_synth_t* synth, int bank, int prog,
  187.                                        const char* name, const double* pitch, int apply);
  188. FLUIDSYNTH_API 
  189. int fluid_synth_tune_notes(fluid_synth_t* synth, int bank, int prog,
  190.    int len, const int *keys, const double* pitch, int apply);
  191. FLUIDSYNTH_API 
  192. int fluid_synth_select_tuning(fluid_synth_t* synth, int chan, int bank, int prog);
  193. FLUIDSYNTH_API
  194. int fluid_synth_activate_tuning(fluid_synth_t* synth, int chan, int bank, int prog,
  195.                                 int apply);
  196. FLUIDSYNTH_API int fluid_synth_reset_tuning(fluid_synth_t* synth, int chan);
  197. FLUIDSYNTH_API
  198. int fluid_synth_deactivate_tuning(fluid_synth_t* synth, int chan, int apply);
  199. FLUIDSYNTH_API void fluid_synth_tuning_iteration_start(fluid_synth_t* synth);
  200. FLUIDSYNTH_API 
  201. int fluid_synth_tuning_iteration_next(fluid_synth_t* synth, int* bank, int* prog);
  202. FLUIDSYNTH_API int fluid_synth_tuning_dump(fluid_synth_t* synth, int bank, int prog, 
  203.    char* name, int len, double* pitch);
  204. /* Misc */
  205. FLUIDSYNTH_API double fluid_synth_get_cpu_load(fluid_synth_t* synth);
  206. FLUIDSYNTH_API char* fluid_synth_error(fluid_synth_t* synth);
  207. /*
  208.  * Synthesizer plugin
  209.  *
  210.  * To create a synthesizer plugin, create the synthesizer as
  211.  * explained above. Once the synthesizer is created you can call
  212.  * any of the functions below to get the audio. 
  213.  */
  214. FLUIDSYNTH_API int fluid_synth_write_s16(fluid_synth_t* synth, int len, 
  215.        void* lout, int loff, int lincr, 
  216.        void* rout, int roff, int rincr);
  217. FLUIDSYNTH_API int fluid_synth_write_float(fluid_synth_t* synth, int len, 
  218.  void* lout, int loff, int lincr, 
  219.  void* rout, int roff, int rincr);
  220. FLUIDSYNTH_API int fluid_synth_nwrite_float(fluid_synth_t* synth, int len, 
  221.   float** left, float** right, 
  222.   float** fx_left, float** fx_right);
  223. FLUIDSYNTH_API int fluid_synth_process(fluid_synth_t* synth, int len,
  224.      int nin, float** in, 
  225.      int nout, float** out);
  226. /**
  227.  * Type definition of the synthesizer's audio callback function.
  228.  * @param synth FluidSynth instance
  229.  * @param len Count of audio frames to synthesize
  230.  * @param out1 Array to store left channel of audio to
  231.  * @param loff Offset index in 'out1' for first sample
  232.  * @param lincr Increment between samples stored to 'out1'
  233.  * @param out2 Array to store right channel of audio to
  234.  * @param roff Offset index in 'out2' for first sample
  235.  * @param rincr Increment between samples stored to 'out2'
  236.  */
  237. typedef int (*fluid_audio_callback_t)(fluid_synth_t* synth, int len, 
  238.      void* out1, int loff, int lincr, 
  239.      void* out2, int roff, int rincr);
  240. /* Synthesizer's interface to handle SoundFont loaders */
  241. FLUIDSYNTH_API void fluid_synth_add_sfloader(fluid_synth_t* synth, fluid_sfloader_t* loader);
  242. FLUIDSYNTH_API fluid_voice_t* fluid_synth_alloc_voice(fluid_synth_t* synth, fluid_sample_t* sample,
  243.                                                       int channum, int key, int vel);
  244. FLUIDSYNTH_API void fluid_synth_start_voice(fluid_synth_t* synth, fluid_voice_t* voice);
  245. FLUIDSYNTH_API void fluid_synth_get_voicelist(fluid_synth_t* synth,
  246.                                               fluid_voice_t* buf[], int bufsize, int ID);
  247. FLUIDSYNTH_API int fluid_synth_handle_midi_event(void* data, fluid_midi_event_t* event);
  248. FLUIDSYNTH_API void fluid_synth_set_midi_router(fluid_synth_t* synth,
  249.                                                 fluid_midi_router_t* router);
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253. #endif /* _FLUIDSYNTH_SYNTH_H */