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 Appendix.

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.

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 754. 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 -+rtmidi=virtual -M0   ;;;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>

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

    ;load two soundfonts
    isf	sfload	"07AcousticGuitar.sf2"
    ir	sfload	"01hpschd.sf2"
    	sfplist isf
    	sfplist ir
    	sfpassign	0, isf
    	sfpassign	1, ir

    instr 1	; play guitar from score and midi keyboard - preset index = 0

    	mididefault	60, p3
    	midinoteonkey	p4, p5
    inum	init	p4
    ivel	init	p5
    ivel	init	ivel/127					;make velocity dependent
    kamp	linsegr	1, 1, 1, .1, 0
    kamp	= kamp/3000						;scale amplitude
    kfreq	init	1						;do not change freq from sf
    a1,a2	sfplay3	ivel, inum, kamp*ivel, kfreq, 0			;preset index = 0
    	outs	a1, a2

    	endin

    instr 2	; play harpsichord from score and midi keyboard - preset index = 1

    	mididefault	60, p3
    	midinoteonkey	p4, p5
    inum	init	p4
    ivel	init	p5
    ivel	init	ivel/127					;make velocity dependent
    kamp	linsegr	1, 1, 1, .1, 0
    kamp	= kamp/1000						;scale amplitude
    kfreq	init	1						;do not change freq from sf
    a1,a2	sfplay3	ivel, inum, kamp*ivel, kfreq, 1			;preset index = 1
    	outs	a1, a2

    endin

    </CsInstruments>
    <CsScore>
    f0  60				; stay active for 1 minute

    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