diff --git a/output/driver-alsa.go b/output/driver-alsa.go index e2bf5bb..a6f5bd2 100644 --- a/output/driver-alsa.go +++ b/output/driver-alsa.go @@ -54,18 +54,18 @@ type alsaOutput struct { err chan error } -func newAlsaOutput(reader librespot.Float32Reader, sampleRate int, channels int, device string, mixer string, control string, initialVolume float32, externalVolume bool, volumeUpdate chan float32) (*alsaOutput, error) { +func newAlsaOutput(opts *NewOutputOptions) (*alsaOutput, error) { out := &alsaOutput{ - reader: reader, - channels: channels, - sampleRate: sampleRate, - device: device, - mixer: mixer, - control: control, - volume: initialVolume, + reader: opts.Reader, + channels: opts.ChannelCount, + sampleRate: opts.SampleRate, + device: opts.Device, + mixer: opts.Mixer, + control: opts.Control, + volume: opts.InitialVolume, err: make(chan error, 2), - externalVolume: externalVolume, - volumeUpdate: volumeUpdate, + externalVolume: opts.ExternalVolume, + volumeUpdate: opts.VolumeUpdate, } if err := out.setupMixer(); err != nil { diff --git a/output/driver-pulseaudio.go b/output/driver-pulseaudio.go index e1999b6..61e9830 100644 --- a/output/driver-pulseaudio.go +++ b/output/driver-pulseaudio.go @@ -22,7 +22,7 @@ type pulseAudioOutput struct { err chan error } -func newPulseAudioOutput(reader librespot.Float32Reader, sampleRate int, channels int, externalVolumeUpdate chan float32) (*pulseAudioOutput, error) { +func newPulseAudioOutput(opts *NewOutputOptions) (*pulseAudioOutput, error) { // Initialize the PulseAudio client. // The device name is shown by PulseAudio volume controls (usually built // into a desktop environment), so we might want to use device_name here. @@ -32,21 +32,21 @@ func newPulseAudioOutput(reader librespot.Float32Reader, sampleRate int, channel return nil, err } out := &pulseAudioOutput{ - sampleRate: sampleRate, - reader: reader, + sampleRate: opts.SampleRate, + reader: opts.Reader, client: client, - externalVolumeUpdate: externalVolumeUpdate, + externalVolumeUpdate: opts.VolumeUpdate, err: make(chan error, 2), } // Create a new playback. var channelOpt pulse.PlaybackOption - if channels == 1 { + if opts.ChannelCount == 1 { channelOpt = pulse.PlaybackMono - } else if channels == 2 { + } else if opts.ChannelCount == 2 { channelOpt = pulse.PlaybackStereo } else { - return nil, fmt.Errorf("cannot play %d channels, pulse only supports mono and stereo", channels) + return nil, fmt.Errorf("cannot play %d channels, pulse only supports mono and stereo", opts.ChannelCount) } volumeUpdates := make(chan proto.ChannelVolumes, 1) out.stream, err = out.client.NewPlayback(pulse.Float32Reader(out.float32Reader), pulse.PlaybackSampleRate(out.sampleRate), channelOpt, pulse.PlaybackVolumeChanges(volumeUpdates)) @@ -60,7 +60,7 @@ func newPulseAudioOutput(reader librespot.Float32Reader, sampleRate int, channel // PulseAudio provided volume. cvol, _ := out.stream.Volume() out.volume = cvol.Avg() - sendVolumeUpdate(externalVolumeUpdate, float32(out.volume.Norm())) + sendVolumeUpdate(opts.VolumeUpdate, float32(out.volume.Norm())) // Listen for volume changes (through the volume mixer application, usually // built into the desktop environment), and send them back to Spotify. @@ -70,7 +70,7 @@ func newPulseAudioOutput(reader librespot.Float32Reader, sampleRate int, channel out.volumeLock.Lock() if volume != out.volume { - sendVolumeUpdate(externalVolumeUpdate, float32(volume.Norm())) + sendVolumeUpdate(opts.VolumeUpdate, float32(volume.Norm())) out.volume = volume } out.volumeLock.Unlock() diff --git a/output/output.go b/output/output.go index 1b752e1..e8da553 100644 --- a/output/output.go +++ b/output/output.go @@ -89,13 +89,13 @@ type NewOutputOptions struct { func NewOutput(options *NewOutputOptions) (Output, error) { switch options.Backend { case "alsa": - out, err := newAlsaOutput(options.Reader, options.SampleRate, options.ChannelCount, options.Device, options.Mixer, options.Control, options.InitialVolume, options.ExternalVolume, options.VolumeUpdate) + out, err := newAlsaOutput(options) if err != nil { return nil, err } return out, nil case "pulseaudio": - out, err := newPulseAudioOutput(options.Reader, options.SampleRate, options.ChannelCount, options.VolumeUpdate) + out, err := newPulseAudioOutput(options) if err != nil { return nil, err }