sfload
Prev | Orchestra Opcodes and Operators | Next

## sfload

sfload — Loads an entire SoundFont2 (SF2) sample file into memory.

## Description

Loads an entire SoundFont2 (SF2) sample file into memory. 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.

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

## Syntax

    ir sfload "filename"

## Initialization

ir -- output to be used by other SF2 opcodes. For sfload, ir is ifilhandle.

“filename” -- name of the SF2 file, with its complete path. It must be a string typed within double-quotes with “/” to separate directories (this applies to DOS and Windows as well, where using a backslash will generate an error), or an integer that has been the subject of a strset operation

## Performance

sfload loads an entire SF2 file into memory. It returns a file handle to be used by other opcodes. Several instances of sfload can placed in the header section of an orchestra, allowing use of more than one SF2 file in a single orchestra.

If there is an attempt to load the same file twice the existing load is used with a warning message (from version 6.14).

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.

It should be noted that before version 5.12 a maximum of 10 sound fonts could be loaded, a restriction since relaxed.

## Examples

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

Example 954. Example of the sfload 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, virtual midi in
    ;-iadc    ;;;uncomment -iadc if RT audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o sfload.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; By  Menno Knevel - 2020

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

    ; load in two soundfonts
    isf	sfload	"sf_GMbank.sf2"
    ir	sfload	"07AcousticGuitar.sf2"
    	sfplist isf
    	sfplist ir
    ; first sf_GMbank.sf2 is loaded and assigned to start at 0 and counting up to 328
    ; as there are 329 presets in sf_GMbank.sf2 (0-328).
    ; then 07AcousticGuitar.sf2 is loaded and assigned to replace the 10th preset of already loaded sf_GMbank.sf2
    	sfpassign	0, isf
    	sfpassign	10, ir

    instr 1 ; play French Horn, bank 0 program 60

    inum	=	p4
    ivel	=	p5
    kamp	linsegr	1, 1, 1, .1, 0
    kamp	= kamp/500000						;scale amplitude
    kfreq	=	1						;do not change freq from sf
    a1,a2	sfplay3	ivel, inum, kamp*ivel, kfreq, 60			;preset index = 60
    	outs	a1, a2
    endin

    instr 2	; play Guitar replaces sf_GMbank.sf2 at preset index 10

    inum	=	p4
    ivel	=	p5
    kamp	linsegr	1, 1, 1, .1, 0
    kamp	= kamp/700000						;scale amplitude
    kfreq	=	1						;do not change freq from sf
    a1,a2	sfplay3	ivel, inum, kamp*ivel, kfreq, 10			;preset index = 10
    	outs	a1, a2
    endin

    </CsInstruments>
    <CsScore>

    i1 0 1 60 100
    i1 + 1 62 <
    i1 + 1 65 <
    i1 + 1 69 10

    i2 5 1 60 100
    i2 + 1 62 <
    i2 7 1 65 <
    i2 7 1 69 10

    e
    </CsScore>
    </CsoundSynthesizer>

## See Also

sfilist, sfinstr, sfinstrm, sfpassign, sfplay, sfplaym, sfplist, sfpreset

## Credits

Author: Gabriel Maldonado
Italy
May 2000

New in Csound Version 4.07

Prev | Up | Next
sfinstrm | Home | sflooper