TinySoundFontBackend
Declaration
public sealed class Strawberry.Sound.Midi.TinySoundFontBackend
High-quality MIDI synthesis backend using TinySoundFont v0.9 via P/Invoke. Requires a compiled libtsf native library on the system library path.
Remarks: This backend uses the channel-based TSF API (tsf_channel_note_on, tsf_channel_note_off, tsf_channel_set_presetnumber, etc.) which correctly routes notes to per-channel presets — matching how MIDI playback works. The low-level tsf_note_on/tsf_note_off functions take a preset_index, NOT a channel number. Using those would cause wrong instruments and crashes.
Implements: Strawberry.Sound.Midi.ISynthBackend
Constructors
TinySoundFontBackend
Load a SoundFont from a file path and initialise the synth.
void TinySoundFontBackend(string soundFontPath, int sampleRate = 44100, int channels = 2, float globalGainDB = -6)
Parameters:
| Name | Type | Description |
|---|---|---|
soundFontPath |
System.String |
Path to a .sf2 SoundFont file. |
sampleRate |
System.Int32 = 44100 |
Output sample rate (default 44100). |
channels |
System.Int32 = 2 |
Output channels: 1 = mono, 2 = stereo (default 2). |
globalGainDB |
System.Single = -6 |
Global gain in dB (default -6 to prevent clipping). |
TinySoundFontBackend
Load a SoundFont from a stream and initialise the synth.
void TinySoundFontBackend(Stream soundFontStream, int sampleRate = 44100, int channels = 2, float globalGainDB = -6)
Parameters:
| Name | Type | Description |
|---|---|---|
soundFontStream |
System.IO.Stream |
|
sampleRate |
System.Int32 = 44100 |
|
channels |
System.Int32 = 2 |
|
globalGainDB |
System.Single = -6 |
Properties
SampleRate
int SampleRate { get }
Channels
int Channels { get }
Methods
NoteOn
void NoteOn(int channel, int key, float velocity)
Parameters:
| Name | Type | Description |
|---|---|---|
channel |
System.Int32 |
|
key |
System.Int32 |
|
velocity |
System.Single |
NoteOff
void NoteOff(int channel, int key)
Parameters:
| Name | Type | Description |
|---|---|---|
channel |
System.Int32 |
|
key |
System.Int32 |
NoteOffAll
void NoteOffAll()
ProgramChange
void ProgramChange(int channel, int program)
Parameters:
| Name | Type | Description |
|---|---|---|
channel |
System.Int32 |
|
program |
System.Int32 |
ControlChange
void ControlChange(int channel, int controller, int value)
Parameters:
| Name | Type | Description |
|---|---|---|
channel |
System.Int32 |
|
controller |
System.Int32 |
|
value |
System.Int32 |
PitchWheel
void PitchWheel(int channel, int value)
Parameters:
| Name | Type | Description |
|---|---|---|
channel |
System.Int32 |
|
value |
System.Int32 |
Reset
void Reset()
RenderShort
int RenderShort(short[] buffer, int offset, int sampleFrames)
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
System.Int16[] |
|
offset |
System.Int32 |
|
sampleFrames |
System.Int32 |
Dispose
void Dispose()