Coder Social home page Coder Social logo

fluidsynth2's Introduction

Fluidsynth2 bindings for Go

This package allows you to interface with FluidSynth 2 using Go. FluidSynth is great for playing back MIDI, both realtime through the audio output or to a file for offline consumption. There is just something magical about hearing a terrible MIDI cover of Neil Young playing back through a bad soundfont that prompted me to work on these bindings.

It's based on the repo by sqweek with updates for FluidSynth2 and a lot more that allows you to actually use most of the functionality in FluidSynth.

Installation

  1. Get the bindings:
$ go get -u github.com/coral/fluidsynth2
  1. Import it in your code:
import "github.com/coral/fluidsynth2"

Simple Example

This example will play a MIDI file from disk. You need a MIDI file and a Soundfont in order for audio to play.

s := fluidsynth2.NewSettings()
synth := fluidsynth2.NewSynth(s)
synth.SFLoad("soundfont.sf2", false)

player := fluidsynth2.NewPlayer(synth)
player.Add("song.mid")

fluidsynth2.NewAudioDriver(s, synth)

player.Play()
player.Join()

Configuring FluidSynth

Most of the methods needed to configure FluidSynth are exposed. Here is an example of how you can query FluidSynth for avaliable audio drivers.

s := fluidsynth2.NewSettings()

audioDrivers := s.GetOptions("audio.driver")

for _, driver := range audioDrivers {
	fmt.Print(driver + " ")
}

//Perform logic here to decide what driver to use.
//In this case we are going to use coreaudio

s.SetString("audio.driver", "coreaudio")

Playing MIDI from a buffer

Sometimes you want to load files through Go rather than FluidSynth, the bindings provide a simple way to play back byte slices of MIDI.

s := fluidsynth2.NewSettings()

synth := fluidsynth2.NewSynth(s)
synth.SFLoad("files/soundfont.sf2", false)

dat, err := ioutil.ReadFile("midifile.mid")
if err != nil {
	panic(err)
}

player.AddMem(dat)

fluidsynth2.NewAudioDriver(s, synth)

player.Play()
player.Join()

Contributing

m8 just open a PR with some gucchimucchi code and I'll review it.

KADSBUGGEL

fluidsynth2's People

Contributors

coral avatar taroodr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.