sqweek / fluidsynth

Fluidsynth bindings for Go
1 stars 2 forks source link

How to use this #1

Open Mike77154 opened 5 years ago

Mike77154 commented 5 years ago

Sorry but, how I use this binding for example

Adding as part of another Go application, e.g. Ikemen Go Plus

sqweek commented 5 years ago

Hey Mike!

  1. What's your end goal?

  2. Are you familiar with fluidsynth?

  3. Do you have other sound effects/audio in your app already?

Mike77154 commented 4 years ago

My Goal is adding a native GM midi soundfont sinthetizer for the ikemen engine (a clone of mugen), so the idea is that You specify the soundfont and the Game playa every midi With that soundfont

Other question, does this hace support With OpenAl

Mike77154 commented 4 years ago

https://github.com/Windblade-GR01/Ikemen_GO/blob/master/src/sound.go

sqweek commented 4 years ago

@Mike77154 Note that fluidsynth is a C library, and this project is simply go bindings for it. So you'll need to build the fluidsynth shared library for this to work. There's pre-built binaries for windows at least available from the official repo: https://github.com/FluidSynth/fluidsynth/releases

The documentation available at https://github.com/FluidSynth/fluidsynth/wiki/Documentation is also useful as the go bindings closely follows the C api.

Anyway once you've got the library set up, to load up a sound font you go:

    //assuming: import "github.com/sqweek/fluidsynth"

    settings := fluidsynth.NewSettings()
    settings.setNum("synth.sample-rate", float64(audioFrequency)) // this should match your openAL config
    // customise more settings here if you like; see "FluidSettings" in the documentation for a full list
    synth := fluidsynth.NewSynth(settings)
    soundfontId := synth.SFLoad(soundfontPath, true)

SFLoad can take awhile for large soundfonts, so you might want to do this initialisation in the background.

Now you can do basic midi things like synth.NoteOn/NoteOff/ProgramChange, however nothing is going to happen until you take the audio samples produced by the synthesizer and send them to the soundcard. It's possible to create a fluidsynth.Driver to take care of that, but in your case you probably want to use synth.WriteS16 to get the samples directly as 16-bit integers which you can use to fill your OpenAL buffers.

Does that make sense?