@@ -1318,7 +1318,7 @@ fluid_synth_damp_voices_by_sostenuto_LOCAL(fluid_synth_t *synth, int chan)
1318
1318
* @param mod Modulator info (values copied, passed in object can be freed immediately afterwards)
1319
1319
* @param mode Determines how to handle an existing identical modulator (#fluid_synth_add_mod)
1320
1320
* @return #FLUID_OK on success, #FLUID_FAILED otherwise
1321
- *
1321
+ *
1322
1322
* @note Not realtime safe (due to internal memory allocation) and therefore should not be called
1323
1323
* from synthesis context at the risk of stalling audio output.
1324
1324
*/
@@ -1388,7 +1388,7 @@ fluid_synth_add_default_mod(fluid_synth_t *synth, const fluid_mod_t *mod, int mo
1388
1388
* @param synth synth instance
1389
1389
* @param mod The modulator to remove
1390
1390
* @return #FLUID_OK if a matching modulator was found and successfully removed, #FLUID_FAILED otherwise
1391
- *
1391
+ *
1392
1392
* @note Not realtime safe (due to internal memory allocation) and therefore should not be called
1393
1393
* from synthesis context at the risk of stalling audio output.
1394
1394
*/
@@ -1513,7 +1513,37 @@ fluid_synth_cc(fluid_synth_t *synth, int chan, int num, int val)
1513
1513
FLUID_API_RETURN (result );
1514
1514
}
1515
1515
1516
- /* Local synthesis thread variant of MIDI CC set function. */
1516
+ /* Local synthesis thread variant of MIDI CC set function.
1517
+ Most of CC are allowed to modulate but not all. A comment describes if CC num
1518
+ isn't allowed to modulate.
1519
+ Following explanations should help to understand both MIDI specifications and
1520
+ Soundfont specifications in regard to MIDI specs.
1521
+
1522
+ MIDI specs:
1523
+ CC LSB (32 to 63) are LSB contributions to CC MSB (0 to 31).
1524
+ It's up to the synthesizer to decide to take LSB values into account or not.
1525
+ Actually Fluidsynth doesn't use CC LSB value inside fluid_voice_update_param()
1526
+ (once fluid_voice_modulate() has been triggered). This is because actually
1527
+ fluidsynth needs only 7 bits resolution (and not 14 bits) from these CCs.
1528
+ So fluidsynth is using only 7 bit MSB (except for portamento time).
1529
+ In regard to MIDI specs Fluidsynth behaves correctly.
1530
+
1531
+ Soundfont specs 2.01 - 8.2.1:
1532
+ To deal correctly with MIDI CC (regardless if any synth will use CC MSB alone (7 bit)
1533
+ or both CCs MSB,LSB (14 bits) during synthesis), SF specs recommend not making use of
1534
+ CC LSB (i.e only CC MSB) in modulator sources to trigger modulation (i.e modulators
1535
+ with CC LSB connected to sources inputs should be ignored).
1536
+ These specifics are particularly suited for synths that use 14 bits CCs. In this case,
1537
+ the MIDI transmitter sends CC LSB first followed by CC MSB. The MIDI synth receives
1538
+ both CC LSB and CC MSB but only CC MSB will trigger the modulation.
1539
+ This will produce correct synthesis parameters update from a correct 14 bits CC.
1540
+ If in SF specs, modulator sources with CC LSB had been accepted, both CC LSB and
1541
+ CC MSB will triggers 2 modulations. This leads to incorrect synthesis parameters
1542
+ update followed by correct synthesis parameters update.
1543
+
1544
+ However, as long as fluidsynth will use only CC 7 bits resolution, it is safe to ignore
1545
+ these SF recommendations on CC receive.
1546
+ */
1517
1547
static int
1518
1548
fluid_synth_cc_LOCAL (fluid_synth_t * synth , int channum , int num )
1519
1549
{
@@ -1525,8 +1555,11 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1525
1555
1526
1556
switch (num )
1527
1557
{
1558
+ case LOCAL_CONTROL : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1559
+ break ;
1528
1560
1529
1561
/* CC omnioff, omnion, mono, poly */
1562
+ /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1530
1563
case POLY_OFF :
1531
1564
case POLY_ON :
1532
1565
case OMNI_OFF :
@@ -1581,18 +1614,18 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1581
1614
1582
1615
return FLUID_FAILED ;
1583
1616
1584
- case LEGATO_SWITCH :
1617
+ case LEGATO_SWITCH : /* not allowed to modulate */
1585
1618
/* handles Poly/mono commutation on Legato pedal On/Off.*/
1586
1619
fluid_channel_cc_legato (chan , value );
1587
1620
break ;
1588
1621
1589
- case PORTAMENTO_SWITCH :
1622
+ case PORTAMENTO_SWITCH : /* not allowed to modulate */
1590
1623
/* Special handling of the monophonic list */
1591
1624
/* Invalids the most recent note played in a staccato manner */
1592
1625
fluid_channel_invalid_prev_note_staccato (chan );
1593
1626
break ;
1594
1627
1595
- case SUSTAIN_SWITCH :
1628
+ case SUSTAIN_SWITCH : /* not allowed to modulate */
1596
1629
1597
1630
/* Release voices if Sustain switch is released */
1598
1631
if (value < 64 ) /* Sustain is released */
@@ -1602,7 +1635,7 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1602
1635
1603
1636
break ;
1604
1637
1605
- case SOSTENUTO_SWITCH :
1638
+ case SOSTENUTO_SWITCH : /* not allowed to modulate */
1606
1639
1607
1640
/* Release voices if Sostetuno switch is released */
1608
1641
if (value < 64 ) /* Sostenuto is released */
@@ -1617,28 +1650,31 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1617
1650
1618
1651
break ;
1619
1652
1620
- case BANK_SELECT_MSB :
1653
+ case BANK_SELECT_MSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1621
1654
fluid_channel_set_bank_msb (chan , value & 0x7F );
1622
1655
break ;
1623
1656
1624
- case BANK_SELECT_LSB :
1657
+ case BANK_SELECT_LSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1625
1658
fluid_channel_set_bank_lsb (chan , value & 0x7F );
1626
1659
break ;
1627
1660
1628
- case ALL_NOTES_OFF :
1661
+ case ALL_NOTES_OFF : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1629
1662
fluid_synth_all_notes_off_LOCAL (synth , channum );
1630
1663
break ;
1631
1664
1632
- case ALL_SOUND_OFF :
1665
+ case ALL_SOUND_OFF : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1633
1666
fluid_synth_all_sounds_off_LOCAL (synth , channum );
1634
1667
break ;
1635
1668
1636
- case ALL_CTRL_OFF :
1669
+ case ALL_CTRL_OFF : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1637
1670
fluid_channel_init_ctrl (chan , 1 );
1638
1671
fluid_synth_modulate_voices_all_LOCAL (synth , channum );
1639
1672
break ;
1640
1673
1641
- case DATA_ENTRY_MSB :
1674
+ case DATA_ENTRY_LSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1675
+ break ;
1676
+
1677
+ case DATA_ENTRY_MSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1642
1678
{
1643
1679
int data = (value << 7 ) + fluid_channel_get_cc (chan , DATA_ENTRY_LSB );
1644
1680
@@ -1698,13 +1734,13 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1698
1734
break ;
1699
1735
}
1700
1736
1701
- case NRPN_MSB :
1737
+ case NRPN_MSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1702
1738
fluid_channel_set_cc (chan , NRPN_LSB , 0 );
1703
1739
chan -> nrpn_select = 0 ;
1704
1740
chan -> nrpn_active = 1 ;
1705
1741
break ;
1706
1742
1707
- case NRPN_LSB :
1743
+ case NRPN_LSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1708
1744
1709
1745
/* SontFont 2.01 NRPN Message (Sect. 9.6, p. 74) */
1710
1746
if (fluid_channel_get_cc (chan , NRPN_MSB ) == 120 )
@@ -1730,8 +1766,8 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1730
1766
chan -> nrpn_active = 1 ;
1731
1767
break ;
1732
1768
1733
- case RPN_MSB :
1734
- case RPN_LSB :
1769
+ case RPN_MSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1770
+ case RPN_LSB : /* not allowed to modulate (spec SF 2.01 - 8.2.1) */
1735
1771
chan -> nrpn_active = 0 ;
1736
1772
break ;
1737
1773
@@ -1741,7 +1777,14 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num)
1741
1777
1742
1778
/* fall-through */
1743
1779
default :
1744
- return fluid_synth_modulate_voices_LOCAL (synth , channum , 1 , num );
1780
+ /* CC lsb shouldn't allowed to modulate (spec SF 2.01 - 8.2.1) */
1781
+ /* However, as long fluidsynth will use only CC 7 bits resolution, it
1782
+ is safe to ignore these SF recommendations on CC receive. See
1783
+ explanations above */
1784
+ /* if (! (32 <= num && num <= 63)) */
1785
+ {
1786
+ return fluid_synth_modulate_voices_LOCAL (synth , channum , 1 , num );
1787
+ }
1745
1788
}
1746
1789
1747
1790
return FLUID_OK ;
0 commit comments