Hello everyone,
a library that is painfully missing from Go is a simple, usable and cross-platform audio library. What do you guys think? How hard would it be to implement this API?
package playback
func PlayerDevices() []PlayerDevice { ... }
func RecorderDevices() []RecorderDevice { ... }
func OSPlayerDevice() (PlayerDevice, error) { ... }
func OSRecorderDevice() (RecorderDevice, error) { ... }
type Player interface {
Play(rate float64, samples []float64) (n int, err error)
}
type Recorder interface {
Record(rate float64, samples []float64) (n int, err error)
}
type Device interface {
DeviceInfo() DeviceInfo
}
type PlayerDevice interface {
Player
Device
}
type RecorderDevice interface {
Recorder
Device
}
type DeviceInfo struct {
...
}
Both Play and Record methods would be blocking, but that’s would be easy to overcome with Go’s concurrency. Go is actually great in this, that you don’t need to have any kinds of non-blocking I/O, which simplifies everything.
A library with this API could be preferably implemented in pure Go, with no bindings to anything… or maybe something? I’m not sure, I’ve never done low-level audio, so I’m asking.
A library like this is flexible enough, that it’s easy to build on top of it. Player and Recorder interfaces are analogous to Writer and Reader and are same flexible.
What do you guys think? How hard would it be to implement this in pure Go?