csound / csound

Main repository for Csound
https://csound.com
GNU Lesser General Public License v2.1
1.24k stars 191 forks source link

Some soundfont presets don't work #1721

Closed bramtayl closed 1 year ago

bramtayl commented 1 year ago

If you use the musescore soundfont file https://ftp.osuosl.org/pub/musescore/soundfont/MuseScore_General/MuseScore_General.sf2, about half of the instruments don't work, for example, the first one, grand piano:

gisound_font sfload "share/MuseScore_General.sf2"

; arguments preset number, bank_number, sound_font object, assignment_number
 gigrand_piano sfpreset 0, 0, gisound_font, 0

; arguments p1 = instrument, p2 = start_time, p3 = duration, p4 = frequency, p5 = amplitude (max 1)
instr grand_piano
  ; assume velociy is proportional to amplitude
  ; arguments velocity, midi number, amplitude, frequency, preset number, ignore midi flag
  aleft_sound, aright_sound sfplay3 gimax_velocity * p5, 0, gibase_amplitude * p5, p4, gigrand_piano, 1
  ; arguments start_level, sustain_duration, mid_level, release_duration, end_level
  acutoff_envelope linsegr 1, p3, 1, girelease_duration, 0
  ; cutoff instruments at end of the duration
  aleft_sound_cut = aleft_sound * acutoff_envelope
  aright_sound_cut = aright_sound * acutoff_envelope
  outs aleft_sound_cut, aright_sound_cut
endin
vlazzarini commented 1 year ago

Your code is probably wrong, it's hard to say where because I don't have the value of gimax_velocity. I tested the soundfont here and it worked. Preset 1 has multi layers depending on velocity, for which you need ivel to be in the 0-127 (see manual).

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
0dbfs = 1
nchnls=2

gisound_font sfload "MuseScore_General.sf2"
instr grand_piano
  ipr sfpreset 0,0,gisound_font,0
  aleft_sound, aright_sound sfplay3 p4, p5, .0001*p4/128, 1, ipr
  acutoff_envelope linsegr 1, p3, 1, 0.1, 0
  aleft_sound_cut = aleft_sound * acutoff_envelope
  aright_sound_cut = aright_sound * acutoff_envelope
  outs aleft_sound_cut, aright_sound_cut
endin

</CsInstruments>
<CsScore>
i1 0 2 100 60
</CsScore>
</CsoundSynthesizer>
bramtayl commented 1 year ago

Hm, sorry, my gimaxvelocity is 127, so that seems fine, right?

bramtayl commented 1 year ago

Running your code I don't hear anything, but if I change the preset number to 12 (Marimba) I do hear something.

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
0dbfs = 1
nchnls=2

gisound_font sfload "/home/brandon/Justly/share/MuseScore_General.sf2"
instr grand_piano
  ipr sfpreset 12,0,gisound_font,0
  aleft_sound, aright_sound sfplay3 p4, p5, .0001*p4/128, 1, ipr
  acutoff_envelope linsegr 1, p3, 1, 0.1, 0
  aleft_sound_cut = aleft_sound * acutoff_envelope
  aright_sound_cut = aright_sound * acutoff_envelope
  outs aleft_sound_cut, aright_sound_cut
endin

</CsInstruments>
<CsScore>
i1 0 2 100 60
</CsScore>
</CsoundSynthesizer>
bramtayl commented 1 year ago
brandon@brandon-Inspiron-16-5620:~$ csound --version
--Csound version 6.18 (double samples) 2022-11-24

brandon@brandon-Inspiron-16-5620:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.04
Release:    23.04
Codename:   lunar
vlazzarini commented 1 year ago

preset 0 works fine here, see below.

--Csound version 6.18 (double samples) Nov 24 2022
[commit: a1580f9cdf331c35dceb486f4231871ce0b00266]
libsndfile-1.1.0
sr = 44100.0, kr = 4410.000, ksmps = 10
0dBFS level = 1.0, A4 tuning = 440.0
orch now loaded
audio buffered in 128 sample-frame blocks
AuHAL Module: found 7 output device(s):
1: BlackHole 2ch (2 channels)
2: MacBook Pro Speakers (2 channels)
3: Microsoft Teams Audio (2 channels)
4: Fireface UC Mac (23452683) (18 channels)
5: ZoomAudioDevice (2 channels)
6: Multi-Output Device (2 channels)
7: Aggregate Device (4 channels)
selected output device: Fireface UC Mac (23452683)
***** AuHAL module: output device open with 128 buffer frames
writing 256 sample blks of 64-bit floats to dac
SECTION 1:
new alloc for instr grand_piano:
B  0.000 ..  2.000 T  2.000 TT  2.000 M:  0.04837  0.10599
B  2.000 ..  2.100 T  2.100 TT  2.100 M:  0.00255  0.00504
Score finished in csoundPerformKsmps() with 2.
inactive allocs returned to freespace
end of score.          overall amps:  0.04837  0.10599
       overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 2.292s, CPU: 2.171s
--Csound version 6.18 (double samples) Nov 24 2022
[commit: a1580f9cdf331c35dceb486f4231871ce0b00266]
AuHAL module: device closed
724 256 sample blks of 64-bit floats written to dac
bramtayl commented 1 year ago

Ok, never mind, figured it out. I had to set the midi to a reasonable value even in frequency mode. Grand piano is also just much quieter than the other instruments and I needed to turn up my volume. Annoying but likely not a csound issue.

vlazzarini commented 1 year ago

You can edit soundfonts with Polyphone. I actually downloaded it to see if the sound font was good, and then noticed that Preset 0 had multisamples while others did not so that's when I inferred the issue. Polyphone looks really handy

bramtayl commented 1 year ago

Yeah, I've been using polyphone to pull the present and bank numbers and it's pretty useful. Actually, a few instruments still aren't working: "Marching Bass", "Marching Cymbals", "Marching Tenor", "Old Marching Tenor", and "Old Marching Bass". "Marching Snare" does work though. The readme says "These presets are used for marching percussion support in MuseScore and do not conform to GM layout" which might have something to do with it?

vlazzarini commented 1 year ago

that could be it. You may be able to fix these in Polyphone.