Csound Csound-dev Csound-tekno Search About

[Csnd] Dynamically loading fluidsynth samples

Date2020-02-12 18:45
FromSyl Morrison
Subject[Csnd] Dynamically loading fluidsynth samples
Hi all, I understand this feature might not be provided in the fluidsynth library, but I'd like to work out a way to dynamically unload and load new individual samples in a soundfont loaded to RAM, (for example, say I want to reload the 40th sample, I'd assume somewhere they'd store an array of pointers to the samples, I'd basically want to change the pointer to point to new sample data), and reflect this in Csound. Do the csound opcodes provide access to that array under the hood? Or is this very much scary, out of my league, OR have I fundamentally misunderstood how Soundfonts work?
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-02-12 19:41
FromPete Goodeve
SubjectRe: [Csnd] Dynamically loading fluidsynth samples
AttachmentsNone  

Date2020-02-12 22:02
FromSyl Morrison
SubjectRe: [Csnd] Dynamically loading fluidsynth samples
Thanks for the link and info Pete, knew it sounded to simple, I was purely basing that on the way a C++ lib called SF2Cute lets you write soundfonts (essentially make an SFSample object, make zone for it, and add to preset, repeat) so at one point I have a vector of SampleZones with the sample data as part of them!

On Wed, Feb 12, 2020 at 7:41 PM Pete Goodeve <pete.goodeve@computer.org> wrote:
On Wed, Feb 12, 2020 at 06:45:01PM +0000, Syl Morrison wrote:
> Hi all, I understand this feature might not be provided in the fluidsynth
> library, but I'd like to work out a way to dynamically unload and load new
> individual samples in a soundfont loaded to RAM, (for example, say I want
> to reload the 40th sample, I'd assume somewhere they'd store an array of
> pointers to the samples, I'd basically want to change the pointer to point
> to new sample data), and reflect this in Csound. Do the csound opcodes
> provide access to that array under the hood? Or is this very much scary,
> out of my league, OR have I fundamentally misunderstood how Soundfonts work?

I'd guess this wouldn't really be possible under any system because
of the convoluted structure of Soundfonts.  I think what you're calling
a "sample" (corresponding to a MIDI "Program Number") is a "Preset"
in a soundfont, which has many components --- one or more "Instruments",
plus "Generators" and "Modulators" that affect the sound.  An instrument
then in turn actually refers to -- probably several -- actual samples, plus
its own generators and modulators.  Conversely a particular sample may
appear in more than one instrument.  In the soundfont file itself each of
these levels has its own region. Fluidsynth has to turn all this into its
own internal structure.

So "replacing a sample" will never be a simple operation . Sorry.

(I have a nice HTML intro to Soundfonts by Josh Green, who started
fluidsynth, but I can only find a text version on the web:

   http://freepats.zenvoid.org/sf2/SF2_Intro.txt  )

        -- Pete --

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-02-12 22:46
Frommskala@ANSUZ.SOOKE.BC.CA
SubjectRe: [Csnd] Dynamically loading fluidsynth samples
On Wed, 12 Feb 2020, Syl Morrison wrote:
> Thanks for the link and info Pete, knew it sounded to simple, I was purely
> basing that on the way a C++ lib called SF2Cute lets you write soundfonts

What is your use case here?

Do you have a set of samples that really are samples, and you want to play
the samples on demand but sometimes change which ones are in use?  In that
case, it might make sense to load the samples into function tables, play
them from there, and not use fluidsynth at all.

Do you have sounds that are real soundfont sounds - that is, not
necessarily samples as such, possibly more complicated - but you want to
switch among them?  In that case it might make sense to just *do* that:
load all your soundfonts, and remap the instrument numbers in your own
code (possibly through some kind of lookup table) to invoke whichever
sounds you want when you want.  It's probably a premature optimization to
assume that you need to replace loaded samples with other samples and
can't afford to load them all.

Are you trying to create and edit soundfont files?  In that case Csound
may simply be the wrong tool.

-- 
Matthew Skala
mskala@ansuz.sooke.bc.ca                 People before tribes.
https://ansuz.sooke.bc.ca/

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2020-02-12 23:14
FromPete Goodeve
SubjectRe: [Csnd] Dynamically loading fluidsynth samples
AttachmentsNone  

Date2020-02-13 20:32
FromSyl Morrison
SubjectRe: [Csnd] Dynamically loading fluidsynth samples
So my use case for this is moreso that samples may be generated on the fly as the program runs, and I'd like them to be able to be accessed by the playback instrument in csound (the generation happens in c++). I think you might be right about it making more sense to essentially make a multisampler wherein the samples can be dynamically unloaded and reloaded, but yeah, it's not as much a lack of ram issue as a time issue, some samples we want might not be available at init time!

On Wed, Feb 12, 2020 at 11:14 PM Pete Goodeve <pete.goodeve@computer.org> wrote:
On Wed, Feb 12, 2020 at 10:02:39PM +0000, Syl Morrison wrote:
> Thanks for the link and info Pete, knew it sounded to simple, I was purely
> basing that on the way a C++ lib called SF2Cute lets you write soundfonts
> (essentially make an SFSample object, make zone for it, and add to preset,
> repeat) so at one point I have a vector of SampleZones with the sample data
> as part of them!
>
Yr Welcome...  But thanks in turn for the reference to SF2Cute!
Hadn't heard of that.  Have to check it out.  I have Swami on Linux,
but I've never really used it due to its complexity.  (Except once
to fix a faulty instrument in the TimGM font.)

On somewhat the same subject, does anyone know the history
of the soundfonts in the "examples" folder with the manual?
Using the "strings" command I found names that let me track
down the originals (like "Florestan Soundfonts") but the examples
are all severely cut down from their sources.  Also, strangely,
the originals have names that begin with the instrument number
of the sound; the examples also begin with numbers... that bear
no relation to the instrument!  Anyone know why?

        -- Pete--

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2020-02-13 20:42
FromSyl Morrison
SubjectRe: [Csnd] Dynamically loading fluidsynth samples
And yeah, SF2Cute is absolutely class, using it for writing soundfonts based on dynamic inputs

On Thu, Feb 13, 2020 at 8:32 PM Syl Morrison <honoonu@gmail.com> wrote:
So my use case for this is moreso that samples may be generated on the fly as the program runs, and I'd like them to be able to be accessed by the playback instrument in csound (the generation happens in c++). I think you might be right about it making more sense to essentially make a multisampler wherein the samples can be dynamically unloaded and reloaded, but yeah, it's not as much a lack of ram issue as a time issue, some samples we want might not be available at init time!

On Wed, Feb 12, 2020 at 11:14 PM Pete Goodeve <pete.goodeve@computer.org> wrote:
On Wed, Feb 12, 2020 at 10:02:39PM +0000, Syl Morrison wrote:
> Thanks for the link and info Pete, knew it sounded to simple, I was purely
> basing that on the way a C++ lib called SF2Cute lets you write soundfonts
> (essentially make an SFSample object, make zone for it, and add to preset,
> repeat) so at one point I have a vector of SampleZones with the sample data
> as part of them!
>
Yr Welcome...  But thanks in turn for the reference to SF2Cute!
Hadn't heard of that.  Have to check it out.  I have Swami on Linux,
but I've never really used it due to its complexity.  (Except once
to fix a faulty instrument in the TimGM font.)

On somewhat the same subject, does anyone know the history
of the soundfonts in the "examples" folder with the manual?
Using the "strings" command I found names that let me track
down the originals (like "Florestan Soundfonts") but the examples
are all severely cut down from their sources.  Also, strangely,
the originals have names that begin with the instrument number
of the sound; the examples also begin with numbers... that bear
no relation to the instrument!  Anyone know why?

        -- Pete--

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here