envelope, filter cutoff/resonance mapped to default modulators (with semi-random magic numbers)
This commit is contained in:
		@ -4,6 +4,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include "FluidSynthModel.h"
 | 
					#include "FluidSynthModel.h"
 | 
				
			||||||
 | 
					#include "MidiConstants.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -15,8 +16,8 @@ FluidSynthModel::FluidSynthModel(SharesParams& p)
 | 
				
			|||||||
          currentSampleRate(44100),
 | 
					          currentSampleRate(44100),
 | 
				
			||||||
          initialised(false),
 | 
					          initialised(false),
 | 
				
			||||||
          sfont_id(0),
 | 
					          sfont_id(0),
 | 
				
			||||||
          channel(0),
 | 
					          channel(0)/*,
 | 
				
			||||||
          mod(nullptr)
 | 
					          mod(nullptr)*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{}
 | 
					{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -27,7 +28,7 @@ FluidSynthModel::~FluidSynthModel() {
 | 
				
			|||||||
        delete_fluid_settings(settings);
 | 
					        delete_fluid_settings(settings);
 | 
				
			||||||
//        delete driver;
 | 
					//        delete driver;
 | 
				
			||||||
//        delete settings;
 | 
					//        delete settings;
 | 
				
			||||||
        delete_fluid_mod(mod);
 | 
					//        delete_fluid_mod(mod);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -63,37 +64,73 @@ void FluidSynthModel::initialise() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
//    changePreset(128, 13);
 | 
					//    changePreset(128, 13);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    float env_amount(12700.0f);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    fluid_mod_t *mod(new_fluid_mod());
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
//    mod = new_fluid_mod();
 | 
					    fluid_mod_set_source1(mod,
 | 
				
			||||||
//
 | 
					                          static_cast<int>(SOUND_CTRL2), // MIDI CC 71 Timbre/Harmonic Intensity (filter resonance)
 | 
				
			||||||
//    // modulator's primary source controller and flags
 | 
					                          FLUID_MOD_CC
 | 
				
			||||||
//    // fluid_mod_src:
 | 
					                          | FLUID_MOD_UNIPOLAR
 | 
				
			||||||
//    // https://github.com/FluidSynth/fluidsynth/blob/master/include/fluidsynth/mod.h#L61
 | 
					                          | FLUID_MOD_CONCAVE
 | 
				
			||||||
//    // fluid_mod_flags:
 | 
					                          | FLUID_MOD_NEGATIVE);
 | 
				
			||||||
//    // https://github.com/FluidSynth/fluidsynth/blob/master/include/fluidsynth/mod.h#L41
 | 
					    fluid_mod_set_source2(mod, 0, 0);
 | 
				
			||||||
//    // diagrams showing what negative and concave mean:
 | 
					    fluid_mod_set_dest(mod, GEN_FILTERQ);
 | 
				
			||||||
//    // https://musescore.org/en/user/527826/blog/2016/05/23/volume-fluidsynth
 | 
					    fluid_mod_set_amount(mod, FLUID_PEAK_ATTENUATION);
 | 
				
			||||||
//    // fluid_gen_type:
 | 
					    fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD);
 | 
				
			||||||
//    // https://github.com/FluidSynth/fluidsynth/blob/master/include/fluidsynth/gen.h#L36
 | 
					    delete_fluid_mod(mod);
 | 
				
			||||||
//    // https://github.com/FluidSynth/fluidsynth/blob/master/src/synth/fluid_gen.c#L27
 | 
					 | 
				
			||||||
//    fluid_mod_set_source1(mod,
 | 
					 | 
				
			||||||
//            FLUID_MOD_KEYPRESSURE,
 | 
					 | 
				
			||||||
//            FLUID_MOD_CC |
 | 
					 | 
				
			||||||
//                    FLUID_MOD_POSITIVE |
 | 
					 | 
				
			||||||
//                    FLUID_MOD_UNIPOLAR |
 | 
					 | 
				
			||||||
//                    FLUID_MOD_CONCAVE);
 | 
					 | 
				
			||||||
//    // modulator's secondary source controller and flags
 | 
					 | 
				
			||||||
//    // MIDI CC 74
 | 
					 | 
				
			||||||
////    fluid_mod_set_source2(mod, 74, FLUID_MOD_CC);
 | 
					 | 
				
			||||||
//    fluid_mod_set_source2(mod, 0, 0);
 | 
					 | 
				
			||||||
//    // generator for filter cutoff
 | 
					 | 
				
			||||||
//    fluid_mod_set_dest(mod, GEN_MODENVATTACK);
 | 
					 | 
				
			||||||
//    fluid_mod_set_amount(mod, 13500.0f);
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
//    fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD);
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    mod = new_fluid_mod();
 | 
				
			||||||
 | 
					    fluid_mod_set_source1(mod,
 | 
				
			||||||
 | 
					                          static_cast<int>(SOUND_CTRL3), // MIDI CC 72 Release time
 | 
				
			||||||
 | 
					                          FLUID_MOD_CC
 | 
				
			||||||
 | 
					                          | FLUID_MOD_BIPOLAR
 | 
				
			||||||
 | 
					                          | FLUID_MOD_CONCAVE
 | 
				
			||||||
 | 
					                          | FLUID_MOD_POSITIVE);
 | 
				
			||||||
 | 
					    fluid_mod_set_source2(mod, 0, 0);
 | 
				
			||||||
 | 
					    fluid_mod_set_dest(mod, GEN_VOLENVRELEASE);
 | 
				
			||||||
 | 
					    fluid_mod_set_amount(mod, env_amount);
 | 
				
			||||||
 | 
					    fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD);
 | 
				
			||||||
 | 
					    delete_fluid_mod(mod);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    mod = new_fluid_mod();
 | 
				
			||||||
 | 
					    fluid_mod_set_source1(mod,
 | 
				
			||||||
 | 
					                          static_cast<int>(SOUND_CTRL4), // MIDI CC 73 Attack time
 | 
				
			||||||
 | 
					                          FLUID_MOD_CC
 | 
				
			||||||
 | 
					                          | FLUID_MOD_BIPOLAR
 | 
				
			||||||
 | 
					                          | FLUID_MOD_CONCAVE
 | 
				
			||||||
 | 
					                          | FLUID_MOD_POSITIVE);
 | 
				
			||||||
 | 
					    fluid_mod_set_source2(mod, 0, 0);
 | 
				
			||||||
 | 
					    fluid_mod_set_dest(mod, GEN_VOLENVATTACK);
 | 
				
			||||||
 | 
					    fluid_mod_set_amount(mod, env_amount);
 | 
				
			||||||
 | 
					    fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD);
 | 
				
			||||||
 | 
					    delete_fluid_mod(mod);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    mod = new_fluid_mod();
 | 
				
			||||||
 | 
					    fluid_mod_set_source1(mod,
 | 
				
			||||||
 | 
					                          static_cast<int>(SOUND_CTRL5), // MIDI CC 74 Brightness (cutoff frequency, FILTERFC)
 | 
				
			||||||
 | 
					                          FLUID_MOD_CC
 | 
				
			||||||
 | 
					                          | FLUID_MOD_SWITCH
 | 
				
			||||||
 | 
					                          | FLUID_MOD_UNIPOLAR
 | 
				
			||||||
 | 
					                          | FLUID_MOD_POSITIVE);
 | 
				
			||||||
 | 
					    fluid_mod_set_source2(mod, 0, 0);
 | 
				
			||||||
 | 
					    fluid_mod_set_dest(mod, GEN_FILTERFC);
 | 
				
			||||||
 | 
					    fluid_mod_set_amount(mod, -2400.0f);
 | 
				
			||||||
 | 
					    fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD);
 | 
				
			||||||
 | 
					    delete_fluid_mod(mod);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    mod = new_fluid_mod();
 | 
				
			||||||
 | 
					    fluid_mod_set_source1(mod,
 | 
				
			||||||
 | 
					                          static_cast<int>(SOUND_CTRL6), // MIDI CC 75 Decay Time
 | 
				
			||||||
 | 
					                          FLUID_MOD_CC
 | 
				
			||||||
 | 
					                          | FLUID_MOD_BIPOLAR
 | 
				
			||||||
 | 
					                          | FLUID_MOD_CONCAVE
 | 
				
			||||||
 | 
					                          | FLUID_MOD_POSITIVE);
 | 
				
			||||||
 | 
					    fluid_mod_set_source2(mod, 0, 0);
 | 
				
			||||||
 | 
					    fluid_mod_set_dest(mod, GEN_VOLENVDECAY);
 | 
				
			||||||
 | 
					    fluid_mod_set_amount(mod, env_amount);
 | 
				
			||||||
 | 
					    fluid_synth_add_default_mod(synth, mod, FLUID_SYNTH_ADD);
 | 
				
			||||||
 | 
					    delete_fluid_mod(mod);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    initialised = true;
 | 
					    initialised = true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -88,7 +88,7 @@ private:
 | 
				
			|||||||
    unsigned int sfont_id;
 | 
					    unsigned int sfont_id;
 | 
				
			||||||
    unsigned int channel;
 | 
					    unsigned int channel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fluid_mod_t* mod;
 | 
					//    fluid_mod_t* mod;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ListenerList<Listener> eventListeners;
 | 
					    ListenerList<Listener> eventListeners;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,10 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Taken from fluidsynth/src/midi/fluid_midi.h
 | 
					/* Taken from:
 | 
				
			||||||
 | 
					 * fluidsynth/src/midi/fluid_midi.h
 | 
				
			||||||
 | 
					 * fluidsynth/src/utils/fluid_conv_tables.h
 | 
				
			||||||
 * https://github.com/FluidSynth/fluidsynth/blob/master/src/midi/fluid_midi.h
 | 
					 * https://github.com/FluidSynth/fluidsynth/blob/master/src/midi/fluid_midi.h
 | 
				
			||||||
 | 
					 * https://github.com/FluidSynth/fluidsynth/blob/master/src/utils/fluid_conv_tables.h
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * FluidSynth - A Software Synthesizer
 | 
					 * FluidSynth - A Software Synthesizer
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@ -128,3 +131,34 @@ enum fluid_midi_control_change
 | 
				
			|||||||
    POLY_OFF = 0x7E,
 | 
					    POLY_OFF = 0x7E,
 | 
				
			||||||
    POLY_ON = 0x7F
 | 
					    POLY_ON = 0x7F
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 Attenuation range in centibels.
 | 
				
			||||||
 | 
					 Attenuation range is the dynamic range of the volume envelope generator
 | 
				
			||||||
 | 
					 from 0 to the end of attack segment.
 | 
				
			||||||
 | 
					 fluidsynth is a 24 bit synth, it could (should??) be 144 dB of attenuation.
 | 
				
			||||||
 | 
					 However the spec makes no distinction between 16 or 24 bit synths, so use
 | 
				
			||||||
 | 
					 96 dB here.
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					 Note about usefulness of 24 bits:
 | 
				
			||||||
 | 
					 1)Even fluidsynth is a 24 bit synth, this format is only relevant if
 | 
				
			||||||
 | 
					 the sample format coming from the soundfont is 24 bits and the audio sample format
 | 
				
			||||||
 | 
					 choosen by the application (audio.sample.format) is not 16 bits.
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					 2)When the sample soundfont is 16 bits, the internal 24 bits number have
 | 
				
			||||||
 | 
					 16 bits msb and lsb to 0. Consequently, at the DAC output, the dynamic range of
 | 
				
			||||||
 | 
					 this 24 bit sample is reduced to the the dynamic of a 16 bits sample (ie 90 db)
 | 
				
			||||||
 | 
					 even if this sample is produced by the audio driver using an audio sample format
 | 
				
			||||||
 | 
					 compatible for a 24 bit DAC.
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					 3)When the audio sample format settings is 16 bits (audio.sample.format), the
 | 
				
			||||||
 | 
					 audio driver will make use of a 16 bit DAC, and the dynamic will be reduced to 96 dB
 | 
				
			||||||
 | 
					 even if the initial sample comes from a 24 bits soundfont.
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					 In both cases (2) or (3), the real dynamic range is only 96 dB.
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
 | 
					 Other consideration for FLUID_NOISE_FLOOR related to case (1),(2,3):
 | 
				
			||||||
 | 
					 - for case (1), FLUID_NOISE_FLOOR should be the noise floor for 24 bits (i.e -138 dB).
 | 
				
			||||||
 | 
					 - for case (2) or (3), FLUID_NOISE_FLOOR should be the noise floor for 16 bits (i.e -90 dB).
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define FLUID_PEAK_ATTENUATION  960.0f
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user