sfpreset

sfpreset — Assigns an existing preset of a SoundFont2 (SF2) sample file to an index number.

Description

Assigns an existing preset of a previously loaded SoundFont2 (SF2) sample file to an index number. These opcodes allow management the sample-structure of SF2 files. In order to understand the usage of these opcodes, the user must have some knowledge of the SF2 format, so a brief description of this format can be found in the SoundFont2 File Format section.

sfpreset should be placed in the header section of a Csound orchestra.

Syntax

ir sfpreset iprog, ibank, ifilhandle, ipreindex

Initialization

ir -- output to be used by other SF2 opcodes. For sfpreset, ir is ipreindex.

iprog -- program number of a bank of presets in a SF2 file

ibank -- number of a specific bank of a SF2 file

ifilhandle -- unique number generated by sfload opcode to be used as an identifier for a SF2 file. Several SF2 files can be loaded and activated at the same time.

ipreindex -- preset index

Performance

sfpreset assigns an existing preset of a previously loaded SF2 file to an index number, to be used later with the opcodes sfplay and sfplaym. The user must previously know the program and the bank numbers of the preset in order to fill the corresponding arguments. Any number of sfpreset instances can be placed in the header section of an orchestra, each one assigning a different preset belonging to the same (or different) SF2 file to different index numbers.

These opcodes only support the sample structure of SF2 files. The modulator structure of the SoundFont2 format is not supported in Csound. Any modulation or processing to the sample data is left to the Csound user, bypassing all restrictions forced by the SF2 standard.

Examples

Here is an example of the sfpreset opcode. It uses the file sfpreset.csd.

Example 984. Example of the sfpreset opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac  ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if RT audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o sfpreset.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

; By  Menno Knevel - 2020

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

gisf1	sfload	 "sf_GMbank.sf2"
	sfplist	 gisf1						;list presets of first soundfont
gisf2	sfload	 "07AcousticGuitar.sf2"
	sfplist	 gisf2						;list presets of second soundfont
gir	sfpreset 51, 0, gisf1, 0 				;assign Synth Strings2 (#51)to index 0
giv	sfpreset 0, 0, gisf2, 1					;assign AcousticGuitar (#0) to index 1
print gir
print giv

instr 1

inum	=	p4
ivel	=	p5
kamp	linsegr	1, 1, 1, .1, 0
kamp	= kamp/600000						;scale amplitude, small value due to 0dbfs = 1
kfreq	=	1						;do not change freq 
a1,a2	sfplay3	ivel, inum, kamp*ivel, kfreq, p6
	outs	a1, a2
endin
	
</CsInstruments>
<CsScore>

i1 0 1 60 127 0	;= Synth Strings I from first soundfont
i1 + 1 62 <   .
i1 + 1 65 <   .
i1 + 1 69 10  .

i1 5 1 60 127 1	;= AcousticGuitar from second soundfont
i1 + 1 62 <   .
i1 + 1 65 <   .
i1 + 1 69 10  .
e
</CsScore>
</CsoundSynthesizer>


See also

Soundfonts

More information on soundfonts is in the Floss Manuals: https://flossmanual.csound.com/midi/reading-midi-files

For other information on soundfonts look in the Wikipedia: http://en.wikipedia.org/wiki/Soundfont

Credits

Author: Gabriel Maldonado
Italy
May 2000

New in Csound Version 4.07