Preset data
Prerequisite
This section requires a basic understanding of SoundFont 2.04 and binary.
SoundFont preset data is accessible through SoundFont3.presetData
. There are 9 mandatory chunks, named the "HYDRA structure"
in the spec.
Preset data contains references that form a graph structure:
- Multiple
preset zones
can reference oneinstrument
. - Likewise, multiple
instrument zones
can reference onesample
.
Preprocessed data
Preset data that are parsed into an array can be accessed accordingly:
- Banks -
SoundFont3.banks
- Presets -
SoundFont3.presets
- Instruments -
SoundFont3.instruments
- Samples -
SoundFont3.samples
phdr
- Preset headers
Accessible through SoundFont3.presetData.presetHeaders
This chunk contains preset info with one record per preset. library
, genre
and morphology
are reserved for future library management - not currently used.
// Multiple records
char[20] presetName = "presetName" // 20 byte
uint16_t presetNumber = 3 // 2 byte
uint16_t bankNumber = 127 // 2 byte - 127 or 128
uint16_t presetZoneId = 3 // 4 byte
uint16_t library = 0 // 4 byte
uint16_t genre = 0 // 4 byte
uint16_t morphology = 0 // 4 byte
// Multiple 38 byte total
A terminal record is required to signify end of phdr
chunk. All values are zero except:
char[20] presetName = "EOP" // Indicate end of chunck
uint16_t presetZoneId = 3 // Number of preset zones
pbag
- Preset zone indices
Accessible through SoundFont3.presetData.presetZones
List preset zones. The generator is the output of the modulator.
// Multiple records
uint16_t generatorId = 3 // 2 byte
uint16_t modulatorId = 1 // 2 byte
// Multiple 4 byte total
pmod
- Preset modulators
Accessible through SoundFont3.presetData.presetModulators
Defines a preset modulator, which is represented by the following calculation and diagram:
float p = cmath::abs(primarySource);
float s = cmath::abs(modulatorDestination);
float modulatorDestination +=
modulatorTransform(modulatorGain * p * s);
MIDI commands can be used as input for modulators. Only official MIDI commands can be used with SoundFont. Popular commands include:
- MIDI CC64 - Sustain pedal
- MIDI CC66 - Soft pedal
- MIDI CC67 - Sostenuto pedal
// Multiple records
uint16_t modulatorSourceId = 3 // 2 byte
uint16_t modulatorDestinationId = 1 // 2 byte
int16_t modulatorGain = 1 // 2 byte
uint16_t modulatorGainSourceId = 1 // 2 byte
uint16_t modulatorTransformId = 1 // 2 byte
// Multiple 10 byte total
pgen
- Preset generators
Accessible through SoundFont3.presetData.presetGenerators
Defines a preset generator which is a modulator node. This node can be referenced to create a graph of modulators:
Generators may specify a range of MIDI keys or velocities. Some generators only specify a signed 16-bit value.
// Multiple records
uint16_t modulatorId = 1 // 2 byte
// Then any of the combination below:
uint8_t minValue = 0 // 1 byte
uint8_t maxValue = 60 // 1 byte
uint16_t amount1 // 2 byte
int16_t amount2// 2 byte
// Multiple 4 byte
inst
- Instrument headers
Accessible through SoundFont3.presetData.instrumentHeaders
This chunk contains instrument info with one record per instrument.
// Multiple records
char[20] instrumentName = "instrumentName" // 20 byte
uint16_t[] instrumentZoneId = 3 // 2 byte
// Multiple 22 byte
A terminal record is required to signify end of inst
chunk. All values are zero except:
char[20] instrumentName = "EOP" // Indicate end of chunck
uint16_t[] instrumentZoneId = 3 // Number of instrument zones
ibag
- Instrument zone indices
Accessible through SoundFont3.presetData.instrumentZones
List instrument zones. The generator is the output of the modulator.
// Multiple records
uint16_t generatorId = 3 // 2 byte
uint16_t modulatorId = 1 // 2 byte
// Multiple 4 byte total
imod
- Instrument modulators
Accessible through SoundFont3.presetData.instrumentModulators
Defines an instrument modulator. See pmod
for structure.
igen
- Instrument generators
Accessible through SoundFont3.presetData.instrumentGenerators
Defines an instrument generator. See pgen
for structure.
shdr
- Sample Headers
Accessible through SoundFont3.presetData.sampleHeaders
This chunk contains sample info with one record per sample.
// Multiple records
char[20] sampleName = "sampleName" // 20 byte
uint32_t startByte = 0 // 4 byte
uint32_t endByte = 60 // 4 byte
uint32_t startLoopByte = 50 // 4 byte
uint32_t endLoopByte = 60 // 4 byte
uint32_t sampleRate = 44100 // 4 byte
uint8_t originalPitch = 60 // 1 byte
int8_t pitchCorrection = -4 // 1 byte
uint16_t romSampleLink = 0 // 2 byte
uint16_t romSampleType = 0 // 2 byte
// Multiple 46 byte
A terminal record is required to signify end of shdr
chunk. All values are zero except:
char[20] instrumentName = "EOS" // Indicate end of chunck
uint16_t[] instrumentZoneId = 88 // Number of samples