Help using fluid_synth_activate_key_tuning

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help using fluid_synth_activate_key_tuning

Tarjei Bærland
Hi!

I want to use fluidsynth to explore different tunings with my mathematics classes. As a start, I've modified ~example.c~ to include a 'tuning' of all notes being tuned at 200 cents, and not knowing how banks and progs work, I try to set the tuning for the full range for both bank and prog.

However, the random notes are still tuned distinctly, and I'm at a loss as to what my errors are. I have tried googling, but I can't find a clear example of fluid_synth_activate_key_tuning in use.

All help would be much appreciated!

Kind regards,
Tarjei Bærland

#include <fluidsynth.h>
#if defined(WIN32)
#include <windows.h>
#define sleep(_t) Sleep(_t * 1000)
#else
#include <stdlib.h>
#endif

const double tuning[128] = {200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0,
   200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0, 200.0};


int main(int argc, char **argv)
{
    fluid_settings_t *settings;
    fluid_synth_t *synth;
    fluid_audio_driver_t *adriver;
    int sfont_id;
    int i, key;
    /* Create the settings. */
    settings = new_fluid_settings();
    fluid_settings_setstr(settings, "audio.driver", "alsa");
    /* Change the settings if necessary*/
    /* Create the synthesizer. */
    synth = new_fluid_synth(settings);
    /* Create the audio driver. The synthesizer starts playing as soon
       as the driver is created. */
    adriver = new_fluid_audio_driver(settings, synth);
    /* Load a SoundFont and reset presets (so that new instruments
     * get used from the SoundFont) */
    sfont_id = fluid_synth_sfload(synth, "Sinus.sf2", 1);
    /* Initialize the random number generator */
    for (int j = 0; j < 128; j++) {
      for (int k = 0; k < 128; k++) {
fluid_synth_activate_key_tuning(synth, j, k, "Test", tuning, 1);
      }
    }
   
    srand(getpid());
    /* fluid_synth_bank_select(synth, 0, 0); */

    for(i = 0; i < 12; i++)
    {
        /* Generate a random key */
        key = 60 + (int)(12.0f * rand() / (float) RAND_MAX);
        /* Play a note */
        fluid_synth_noteon(synth, 0, key, 80);
        /* Sleep for 1 second */
        sleep(1);
        /* Stop the note */
        fluid_synth_noteoff(synth, 0, key);
    }
    /* Clean up */
    delete_fluid_audio_driver(adriver);
    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
    return 0;
}


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help using fluid_synth_activate_key_tuning

Marcus Weseloh
Hi Tarjei,

Am So., 13. Okt. 2019 um 22:36 Uhr schrieb Tarjei Bærland <[hidden email]>:
Hi!

I want to use fluidsynth to explore different tunings with my mathematics classes. As a start, I've modified ~example.c~ to include a 'tuning' of all notes being tuned at 200 cents, and not knowing how banks and progs work, I try to set the tuning for the full range for both bank and prog.
However, the random notes are still tuned distinctly, and I'm at a loss as to what my errors are. I have tried googling, but I can't find a clear example of fluid_synth_activate_key_tuning in use.
All help would be much appreciated!

Fluidsynth channels don't have a default tuning set, so you need to select a tuning bank and program for a particular channel to hear the effects.

Simply create your key tuning for a single for bank/prog, no need to do it for all tuning banks and progs. Then call fluid_synth_activate_tuning() to select tuning bank 0, prog 0 for the channel you are playing your notes on. So roughly like this:
...
int tuning_bank = 0;
int tuning_prog = 0;
int channel = 0;

fluid_synth_activate_key_tuning(synth, tuning_bank, tuning_prog, "Test", tuning, 1);
fluid_synth_activate_tuning(synth, channel, tuning_bank, tuning_prog, 1);
...
(play notes)
 
Hope this helps, all the best
Marcus

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Help using fluid_synth_activate_key_tuning

Tarjei Bærland
Hi, Marcus!

Thank you, that worked perfectly. I was, as you've seen, missing the step of activating the tuning.

Thanks, again,
Tarjei



man. 14. okt. 2019 kl. 10:25 skrev Marcus Weseloh <[hidden email]>:
Hi Tarjei,

Am So., 13. Okt. 2019 um 22:36 Uhr schrieb Tarjei Bærland <[hidden email]>:
Hi!

I want to use fluidsynth to explore different tunings with my mathematics classes. As a start, I've modified ~example.c~ to include a 'tuning' of all notes being tuned at 200 cents, and not knowing how banks and progs work, I try to set the tuning for the full range for both bank and prog.
However, the random notes are still tuned distinctly, and I'm at a loss as to what my errors are. I have tried googling, but I can't find a clear example of fluid_synth_activate_key_tuning in use.
All help would be much appreciated!

Fluidsynth channels don't have a default tuning set, so you need to select a tuning bank and program for a particular channel to hear the effects.

Simply create your key tuning for a single for bank/prog, no need to do it for all tuning banks and progs. Then call fluid_synth_activate_tuning() to select tuning bank 0, prog 0 for the channel you are playing your notes on. So roughly like this:
...
int tuning_bank = 0;
int tuning_prog = 0;
int channel = 0;

fluid_synth_activate_key_tuning(synth, tuning_bank, tuning_prog, "Test", tuning, 1);
fluid_synth_activate_tuning(synth, channel, tuning_bank, tuning_prog, 1);
...
(play notes)
 
Hope this helps, all the best
Marcus
_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev