From 67a0771c32b0783580516d060c2565cdf13b235a Mon Sep 17 00:00:00 2001 From: Saxon Nelson-Milton Date: Mon, 14 Dec 2020 15:56:33 +1030 Subject: [PATCH] device/alsa/alsa.go: removed OpenError --- device/alsa/alsa.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/device/alsa/alsa.go b/device/alsa/alsa.go index be2117a4..b17a5031 100644 --- a/device/alsa/alsa.go +++ b/device/alsa/alsa.go @@ -105,9 +105,6 @@ type Logger interface { Log(level int8, message string, params ...interface{}) } -// OpenError is used to determine whether an error has originated from attempting to open a device. -type OpenError error - // New initializes and returns an ALSA device which has its logger set as the given logger. func New(l Logger) *ALSA { return &ALSA{l: l} } @@ -239,7 +236,7 @@ func (d *ALSA) open() error { d.l.Log(logger.Debug, "opening sound card") cards, err := yalsa.OpenCards() if err != nil { - return OpenError(err) + return err } defer yalsa.CloseCards(cards) @@ -260,13 +257,13 @@ func (d *ALSA) open() error { } } if d.dev == nil { - return OpenError(errors.New("no ALSA device found")) + return errors.New("no ALSA device found") } d.l.Log(logger.Debug, "opening ALSA device", "title", d.dev.Title) err = d.dev.Open() if err != nil { - return OpenError(err) + return err } // Try to configure device with chosen channels. @@ -276,7 +273,7 @@ func (d *ALSA) open() error { channels, err = d.dev.NegotiateChannels(2) } if err != nil { - return OpenError(fmt.Errorf("device is unable to record with requested number of channels: %w", err)) + return fmt.Errorf("device is unable to record with requested number of channels: %w", err) } d.l.Log(logger.Debug, "alsa device channels set", "channels", channels) @@ -309,7 +306,7 @@ func (d *ALSA) open() error { d.l.Log(logger.Warning, "unable to sample at requested rate, default used.", "rateRequested", d.SampleRate) rate, err = d.dev.NegotiateRate(defaultSampleRate) if err != nil { - return OpenError(err) + return err } d.l.Log(logger.Debug, "alsa device sample rate set", "rate", rate) } @@ -321,7 +318,7 @@ func (d *ALSA) open() error { case 32: aFmt = yalsa.S32_LE default: - return OpenError(fmt.Errorf("unsupported sample bits %v", d.BitDepth)) + return fmt.Errorf("unsupported sample bits %v", d.BitDepth) } devFmt, err := d.dev.NegotiateFormat(aFmt) if err != nil { @@ -334,7 +331,7 @@ func (d *ALSA) open() error { case yalsa.S32_LE: bitdepth = 32 default: - return OpenError(fmt.Errorf("unsupported sample bits %v", d.BitDepth)) + return fmt.Errorf("unsupported sample bits %v", d.BitDepth) } d.l.Log(logger.Debug, "alsa device bit depth set", "bitdepth", bitdepth) @@ -349,12 +346,12 @@ func (d *ALSA) open() error { // At least two period sizes should fit within the buffer. bufSize, err := d.dev.NegotiateBufferSize(nearWantPeriodSize * 2) if err != nil { - return OpenError(err) + return err } d.l.Log(logger.Debug, "alsa device buffer size set", "buffersize", bufSize) if err = d.dev.Prepare(); err != nil { - return OpenError(err) + return err } d.l.Log(logger.Debug, "successfully negotiated device params")