# include/fluidsynth/synth.h

    00001 /* FluidSynth - A Software Synthesizer
    00002  *
    00003  * Copyright (C) 2003  Peter Hanappe and others.
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public License
    00007  * as published by the Free Software Foundation; either version 2 of
    00008  * the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful, but
    00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public
    00016  * License along with this library; if not, write to the Free
    00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    00018  * 02111-1307, USA
    00019  */
    00020
    00021 #ifndef _FLUIDSYNTH_SYNTH_H
    00022 #define _FLUIDSYNTH_SYNTH_H
    00023
    00024
    00025 #ifdef __cplusplus
    00026 extern "C" {
    00027 #endif
    00028
    00029
    00056 FLUIDSYNTH_API fluid_synth_t* new_fluid_synth(fluid_settings_t* settings);
    00057
    00058
    00065 FLUIDSYNTH_API int delete_fluid_synth(fluid_synth_t* synth);
    00066
    00067
    00073 FLUIDSYNTH_API fluid_settings_t* fluid_synth_get_settings(fluid_synth_t* synth);
    00074
    00075
    00076   /*
    00077    *
    00078    * MIDI channel messages
    00079    *
    00080    */
    00081
    00083 FLUIDSYNTH_API int fluid_synth_noteon(fluid_synth_t* synth, int chan, int key, int vel);
    00084
    00086 FLUIDSYNTH_API int fluid_synth_noteoff(fluid_synth_t* synth, int chan, int key);
    00087
    00089 FLUIDSYNTH_API int fluid_synth_cc(fluid_synth_t* synth, int chan, int ctrl, int val);
    00090
    00092 FLUIDSYNTH_API int fluid_synth_get_cc(fluid_synth_t* synth, int chan, int ctrl, int* pval);
    00093
    00095 FLUIDSYNTH_API int fluid_synth_pitch_bend(fluid_synth_t* synth, int chan, int val);
    00096
    00098 FLUIDSYNTH_API
    00099 int fluid_synth_get_pitch_bend(fluid_synth_t* synth, int chan, int* ppitch_bend);
    00100
    00102 FLUIDSYNTH_API int fluid_synth_pitch_wheel_sens(fluid_synth_t* synth, int chan, int val);
    00103
    00105 FLUIDSYNTH_API int fluid_synth_get_pitch_wheel_sens(fluid_synth_t* synth, int chan, int* pval);
    00106
    00108 FLUIDSYNTH_API int fluid_synth_program_change(fluid_synth_t* synth, int chan, int program);
    00109
    00111 FLUIDSYNTH_API
    00112 int fluid_synth_bank_select(fluid_synth_t* synth, int chan, unsigned int bank);
    00113
    00115 FLUIDSYNTH_API
    00116 int fluid_synth_sfont_select(fluid_synth_t* synth, int chan, unsigned int sfont_id);
    00117
    00130 FLUIDSYNTH_API
    00131 int fluid_synth_program_select(fluid_synth_t* synth, int chan,
    00132                               unsigned int sfont_id,
    00133                               unsigned int bank_num,
    00134                               unsigned int preset_num);
    00135
    00138 FLUIDSYNTH_API
    00139 int fluid_synth_get_program(fluid_synth_t* synth, int chan,
    00140                            unsigned int* sfont_id,
    00141                            unsigned int* bank_num,
    00142                            unsigned int* preset_num);
    00143
    00148 FLUIDSYNTH_API int fluid_synth_program_reset(fluid_synth_t* synth);
    00149
    00152 FLUIDSYNTH_API int fluid_synth_system_reset(fluid_synth_t* synth);
    00153
    00154
    00155   /*
    00156    *
    00157    * Low level access
    00158    *
    00159    */
    00160
    00163 FLUIDSYNTH_API int fluid_synth_start(fluid_synth_t* synth, unsigned int id,
    00164                                      fluid_preset_t* preset, int audio_chan,
    00165                                      int midi_chan, int key, int vel);
    00166
    00168 FLUIDSYNTH_API int fluid_synth_stop(fluid_synth_t* synth, unsigned int id);
    00169
    00172 /* FLUIDSYNTH_API int fluid_synth_ctrl(fluid_synth_t* synth, int id,  */
    00173 /*                                  int gen, float value,  */
    00174 /*                                  int absolute, int normalized); */
    00175
    00176
    00177   /*
    00178    *
    00179    * SoundFont management
    00180    *
    00181    */
    00182
    00194 FLUIDSYNTH_API
    00195 int fluid_synth_sfload(fluid_synth_t* synth, const char* filename, int reset_presets);
    00196
    00204 FLUIDSYNTH_API int fluid_synth_sfreload(fluid_synth_t* synth, unsigned int id);
    00205
    00213 FLUIDSYNTH_API int fluid_synth_sfunload(fluid_synth_t* synth, unsigned int id, int reset_presets);
    00214
    00222 FLUIDSYNTH_API int fluid_synth_add_sfont(fluid_synth_t* synth, fluid_sfont_t* sfont);
    00223
    00231 FLUIDSYNTH_API void fluid_synth_remove_sfont(fluid_synth_t* synth, fluid_sfont_t* sfont);
    00232
    00238 FLUIDSYNTH_API int fluid_synth_sfcount(fluid_synth_t* synth);
    00239
    00247 FLUIDSYNTH_API fluid_sfont_t* fluid_synth_get_sfont(fluid_synth_t* synth, unsigned int num);
    00248
    00255 FLUIDSYNTH_API fluid_sfont_t* fluid_synth_get_sfont_by_id(fluid_synth_t* synth, unsigned int id);
    00256
    00257
    00259 FLUIDSYNTH_API fluid_preset_t* fluid_synth_get_channel_preset(fluid_synth_t* synth, int chan);
    00260
    00263 FLUIDSYNTH_API int fluid_synth_set_bank_offset(fluid_synth_t* synth, int sfont_id, int offset);
    00264
    00266 FLUIDSYNTH_API int fluid_synth_get_bank_offset(fluid_synth_t* synth, int sfont_id);
    00267
    00268
    00269
    00270   /*
    00271    *
    00272    * Reverb
    00273    *
    00274    */
    00275
    00277 FLUIDSYNTH_API void fluid_synth_set_reverb(fluid_synth_t* synth, double roomsize,
    00278                                          double damping, double width, double level);
    00279
    00281 FLUIDSYNTH_API void fluid_synth_set_reverb_on(fluid_synth_t* synth, int on);
    00282
    00283
    00285 FLUIDSYNTH_API double fluid_synth_get_reverb_roomsize(fluid_synth_t* synth);
    00286 FLUIDSYNTH_API double fluid_synth_get_reverb_damp(fluid_synth_t* synth);
    00287 FLUIDSYNTH_API double fluid_synth_get_reverb_level(fluid_synth_t* synth);
    00288 FLUIDSYNTH_API double fluid_synth_get_reverb_width(fluid_synth_t* synth);
    00289
    00290   /* Those are the default settings for the reverb */
    00291 #define FLUID_REVERB_DEFAULT_ROOMSIZE 0.2f
    00292 #define FLUID_REVERB_DEFAULT_DAMP 0.0f
    00293 #define FLUID_REVERB_DEFAULT_WIDTH 0.5f
    00294 #define FLUID_REVERB_DEFAULT_LEVEL 0.9f
    00295
    00296
    00297
    00298   /*
    00299    *
    00300    * Chorus
    00301    *
    00302    */
    00303
    00304 enum fluid_chorus_mod {
    00305   FLUID_CHORUS_MOD_SINE = 0,
    00306   FLUID_CHORUS_MOD_TRIANGLE = 1
    00307 };
    00308
    00313 FLUIDSYNTH_API void fluid_synth_set_chorus(fluid_synth_t* synth, int nr, double level,
    00314                                          double speed, double depth_ms, int type);
    00315
    00317 FLUIDSYNTH_API void fluid_synth_set_chorus_on(fluid_synth_t* synth, int on);
    00318
    00320 FLUIDSYNTH_API int fluid_synth_get_chorus_nr(fluid_synth_t* synth);
    00321 FLUIDSYNTH_API double fluid_synth_get_chorus_level(fluid_synth_t* synth);
    00322 FLUIDSYNTH_API double fluid_synth_get_chorus_speed_Hz(fluid_synth_t* synth);
    00323 FLUIDSYNTH_API double fluid_synth_get_chorus_depth_ms(fluid_synth_t* synth);
    00324 FLUIDSYNTH_API int fluid_synth_get_chorus_type(fluid_synth_t* synth); /* see fluid_chorus_mod */
    00325
    00326   /* Those are the default settings for the chorus. */
    00327 #define FLUID_CHORUS_DEFAULT_N 3
    00328 #define FLUID_CHORUS_DEFAULT_LEVEL 2.0f
    00329 #define FLUID_CHORUS_DEFAULT_SPEED 0.3f
    00330 #define FLUID_CHORUS_DEFAULT_DEPTH 8.0f
    00331 #define FLUID_CHORUS_DEFAULT_TYPE FLUID_CHORUS_MOD_SINE
    00332
    00333
    00334
    00335   /*
    00336    *
    00337    * Audio and MIDI channels
    00338    *
    00339    */
    00340
    00343 FLUIDSYNTH_API int fluid_synth_count_midi_channels(fluid_synth_t* synth);
    00344
    00347 FLUIDSYNTH_API int fluid_synth_count_audio_channels(fluid_synth_t* synth);
    00348
    00351 FLUIDSYNTH_API int fluid_synth_count_audio_groups(fluid_synth_t* synth);
    00352
    00355 FLUIDSYNTH_API int fluid_synth_count_effects_channels(fluid_synth_t* synth);
    00356
    00357
    00358
    00359   /*
    00360    *
    00361    * Synthesis parameters
    00362    *
    00363    */
    00364
    00366 FLUIDSYNTH_API void fluid_synth_set_gain(fluid_synth_t* synth, float gain);
    00367
    00369 FLUIDSYNTH_API float fluid_synth_get_gain(fluid_synth_t* synth);
    00370
    00372 FLUIDSYNTH_API int fluid_synth_set_polyphony(fluid_synth_t* synth, int polyphony);
    00373
    00375 FLUIDSYNTH_API int fluid_synth_get_polyphony(fluid_synth_t* synth);
    00376
    00386 FLUIDSYNTH_API int fluid_synth_get_internal_bufsize(fluid_synth_t* synth);
    00387
    00389 FLUIDSYNTH_API
    00390 int fluid_synth_set_interp_method(fluid_synth_t* synth, int chan, int interp_method);
    00391
    00392   /* Flags to choose the interpolation method */
    00393 enum fluid_interp {
    00394   /* no interpolation: Fastest, but questionable audio quality */
    00395   FLUID_INTERP_NONE = 0,
    00396   /* Straight-line interpolation: A bit slower, reasonable audio quality */
    00397   FLUID_INTERP_LINEAR = 1,
    00398   /* Fourth-order interpolation: Requires 50 % of the whole DSP processing time, good quality
    00399    * Default. */
    00400   FLUID_INTERP_DEFAULT = 4,
    00401   FLUID_INTERP_4THORDER = 4,
    00402   FLUID_INTERP_7THORDER = 7,
    00403   FLUID_INTERP_HIGHEST=7
    00404 };
    00405
    00406
    00407
    00408
    00409   /*
    00410    *
    00411    * Generator interface
    00412    *
    00413    */
    00414
    00429 FLUIDSYNTH_API
    00430 int fluid_synth_set_gen(fluid_synth_t* synth, int chan, int param, float value);
    00431
    00432
    00441 FLUIDSYNTH_API float fluid_synth_get_gen(fluid_synth_t* synth, int chan, int param);
    00442
    00443
    00444
    00445
    00446   /*
    00447    *
    00448    * Tuning
    00449    *
    00450    */
    00451
    00463 FLUIDSYNTH_API
    00464 int fluid_synth_create_key_tuning(fluid_synth_t* synth, int tuning_bank, int tuning_prog,
    00465                                  char* name, double* pitch);
    00466
    00479 FLUIDSYNTH_API
    00480 int fluid_synth_create_octave_tuning(fluid_synth_t* synth, int tuning_bank, int tuning_prog,
    00481                                     char* name, double* pitch);
    00482
    00497 FLUIDSYNTH_API
    00498 int fluid_synth_tune_notes(fluid_synth_t* synth, int tuning_bank, int tuning_prog,
    00499                           int len, int *keys, double* pitch, int apply);
    00500
    00508 FLUIDSYNTH_API
    00509 int fluid_synth_select_tuning(fluid_synth_t* synth, int chan, int tuning_bank, int tuning_prog);
    00510
    00516 FLUIDSYNTH_API int fluid_synth_reset_tuning(fluid_synth_t* synth, int chan);
    00517
    00522 FLUIDSYNTH_API void fluid_synth_tuning_iteration_start(fluid_synth_t* synth);
    00523
    00524
    00534 FLUIDSYNTH_API
    00535 int fluid_synth_tuning_iteration_next(fluid_synth_t* synth, int* bank, int* prog);
    00536
    00537
    00549 FLUIDSYNTH_API int fluid_synth_tuning_dump(fluid_synth_t* synth, int bank, int prog,
    00550                                          char* name, int len, double* pitch);
    00551
    00552
    00553
    00554
    00555   /*
    00556    *
    00557    * Misc
    00558    *
    00559    */
    00560
    00566 FLUIDSYNTH_API double fluid_synth_get_cpu_load(fluid_synth_t* synth);
    00567
    00569 FLUIDSYNTH_API char* fluid_synth_error(fluid_synth_t* synth);
    00570
    00571
    00572   /*
    00573    *
    00574    *    Synthesizer plugin
    00575    *
    00576    *
    00577    *    To create a synthesizer plugin, create the synthesizer as
    00578    *    explained above. Once the synthesizer is created you can call
    00579    *    any of the functions below to get the audio.
    00580    *
    00581    */
    00582
    00598 FLUIDSYNTH_API int fluid_synth_write_s16(fluid_synth_t* synth, int len,
    00599                                        void* lout, int loff, int lincr,
    00600                                        void* rout, int roff, int rincr);
    00601
    00602
    00618 FLUIDSYNTH_API int fluid_synth_write_float(fluid_synth_t* synth, int len,
    00619                                          void* lout, int loff, int lincr,
    00620                                          void* rout, int roff, int rincr);
    00621
    00622 FLUIDSYNTH_API int fluid_synth_nwrite_float(fluid_synth_t* synth, int len,
    00623                                           float** left, float** right,
    00624                                           float** fx_left, float** fx_right);
    00625
    00640 FLUIDSYNTH_API int fluid_synth_process(fluid_synth_t* synth, int len,
    00641                                      int nin, float** in,
    00642                                      int nout, float** out);
    00643
    00644
    00645
    00646   /* Type definition of the synthesizer's audio callback function. */
    00647 typedef int (*fluid_audio_callback_t)(fluid_synth_t* synth, int len,
    00648                                      void* out1, int loff, int lincr,
    00649                                      void* out2, int roff, int rincr);
    00650
    00651
    00652
    00653
    00654
    00655   /*
    00656    *  Synthesizer's interface to handle SoundFont loaders
    00657    */
    00658
    00659
    00663 FLUIDSYNTH_API void fluid_synth_add_sfloader(fluid_synth_t* synth, fluid_sfloader_t* loader);
    00664
    00671 FLUIDSYNTH_API fluid_voice_t* fluid_synth_alloc_voice(fluid_synth_t* synth, fluid_sample_t* sample,
    00672                                                    int channum, int key, int vel);
    00673
    00679 FLUIDSYNTH_API void fluid_synth_start_voice(fluid_synth_t* synth, fluid_voice_t* voice);
    00680
    00681
    00684 FLUIDSYNTH_API void fluid_synth_get_voicelist(fluid_synth_t* synth,
    00685                                             fluid_voice_t* buf[], int bufsize, int ID);
    00686
    00687
    00689 FLUIDSYNTH_API int fluid_synth_handle_midi_event(void* data, fluid_midi_event_t* event);
    00690
    00691
    00693 FLUIDSYNTH_API void fluid_synth_set_midi_router(fluid_synth_t* synth,
    00694                                               fluid_midi_router_t* router);
    00695
    00696 #ifdef __cplusplus
    00697 }
    00698 #endif
    00699
    00700 #endif /* _FLUIDSYNTH_SYNTH_H */