From 465a29a63525128dbe2b7034f74ea3ccc3f5d34c Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Wed, 21 Sep 2022 21:46:34 -0400 Subject: [PATCH] Add in the SinkName when Writing --- config.go | 3 +++ writer.go | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 88dcb4a..15e4154 100644 --- a/config.go +++ b/config.go @@ -46,6 +46,9 @@ type Config struct { // StreamName is the name of the audio stream from the Application. StreamName string + + // SinkName is the name of the PulseAudio sink to write to. + SinkName string } // SampleFormat denotes the audio format to be used by the pulse streamer. diff --git a/writer.go b/writer.go index 5864302..ca06e76 100644 --- a/writer.go +++ b/writer.go @@ -27,6 +27,7 @@ import ( // #cgo pkg-config: libpulse libpulse-simple // +// #include // #include import "C" @@ -91,11 +92,20 @@ func newWriter(cfg Config) (*writer, error) { ) } + var ( + sinkName *C.char = nil + ) + + if cfg.SinkName != "" { + sinkName = C.CString(cfg.SinkName) + defer C.free(unsafe.Pointer(sinkName)) + } + simple := C.pa_simple_new( nil, C.CString(cfg.AppName), C.PA_STREAM_PLAYBACK, - nil, + sinkName, C.CString(cfg.StreamName), &sampleSpec, nil, @@ -173,7 +183,6 @@ func (w Writer) writeF32NE(samples []float32) error { // // - []float32 (Format: SampleFormatFloat32NE, Channels: 1) // - [][2]float32 (Format: SampleFormatFloat32NE, Channels: 2) -// func (w Writer) Write(samples interface{}) error { switch s := samples.(type) { case [][2]float32: