Skip to content

Commit

Permalink
Add in the SinkName when Writing
Browse files Browse the repository at this point in the history
  • Loading branch information
paultag committed Sep 22, 2022
1 parent ce4b236 commit 465a29a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

// #cgo pkg-config: libpulse libpulse-simple
//
// #include <stdlib.h>
// #include <pulse/simple.h>
import "C"

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 465a29a

Please sign in to comment.