From c4134fd30e3fe4b0e0f25a8675fa766a865b8756 Mon Sep 17 00:00:00 2001 From: Trek H Date: Mon, 11 Nov 2019 22:26:53 +1030 Subject: [PATCH] audio: renamed ADPCMDevice to ALSA --- device/audio/audio.go | 32 ++++++++++++++++---------------- device/audio/audio_test.go | 2 +- revid/audio_linux.go | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/device/audio/audio.go b/device/audio/audio.go index 244ea195..f67046d4 100644 --- a/device/audio/audio.go +++ b/device/audio/audio.go @@ -61,8 +61,8 @@ const ( stopped ) -// ADPCMDevice holds everything we need to know about the audio input stream and implements io.Reader. -type ADPCMDevice struct { +// ALSA holds everything we need to know about the audio input stream and implements io.Reader and device.AVDevice. +type ALSA struct { l Logger // Logger for device's routines to log to. mode uint8 // Operating mode, either running, paused, or stopped. mu sync.Mutex // Provides synchronisation when changing modes concurrently. @@ -74,7 +74,7 @@ type ADPCMDevice struct { Config // Configuration parameters for this device. } -// Config provides parameters used by ADPCMDevice. +// Config provides parameters used by ALSA. type Config struct { SampleRate int Channels int @@ -93,14 +93,14 @@ type Logger interface { // OpenError is used to determine whether an error has originated from attempting to open a device. type OpenError error -// NewADPCMDevice initializes and returns an ADPCMDevice which has its logger set as the given logger. -func NewADPCMDevice(l Logger) *ADPCMDevice { return &ADPCMDevice{l: l} } +// NewALSA initializes and returns an ALSA which has its logger set as the given logger. +func NewALSA(l Logger) *ALSA { return &ALSA{l: l} } // Set will take a Config struct, check the validity of the relevant fields // and then performs any configuration necessary. If fields are not valid, // an error is added to the multiError and a default value is used. -// It then initialises the ADPCMDevice which can then be started, read from, and stopped. -func (d *ADPCMDevice) Set(c config.Config) error { +// It then initialises the ALSA which can then be started, read from, and stopped. +func (d *ALSA) Set(c config.Config) error { var errs device.MultiError if c.SampleRate <= 0 { errs = append(errs, fmt.Errorf("invalid sample rate: %v", c.SampleRate)) @@ -162,8 +162,8 @@ func (d *ADPCMDevice) Set(c config.Config) error { } // Start will start recording audio and writing to the ringbuffer. -// Once a ADPCMDevice has been stopped it cannot be started again. This is likely to change in future. -func (d *ADPCMDevice) Start() error { +// Once a ALSA has been stopped it cannot be started again. This is likely to change in future. +func (d *ALSA) Start() error { d.mu.Lock() mode := d.mode d.mu.Unlock() @@ -184,15 +184,15 @@ func (d *ADPCMDevice) Start() error { } // Stop will stop recording audio and close the device. -// Once a ADPCMDevice has been stopped it cannot be started again. This is likely to change in future. -func (d *ADPCMDevice) Stop() { +// Once a ALSA has been stopped it cannot be started again. This is likely to change in future. +func (d *ALSA) Stop() { d.mu.Lock() d.mode = stopped d.mu.Unlock() } // ChunkSize returns the number of bytes written to the ringbuffer per d.RecPeriod. -func (d *ADPCMDevice) ChunkSize() int { +func (d *ALSA) ChunkSize() int { return d.chunkSize } @@ -218,7 +218,7 @@ func validate(c *Config) error { // open the recording device with the given name and prepare it to record. // If name is empty, the first recording device is used. -func (d *ADPCMDevice) open() error { +func (d *ALSA) open() error { // Close any existing device. if d.dev != nil { d.l.Log(logger.Debug, pkg+"closing device", "title", d.title) @@ -351,7 +351,7 @@ func (d *ADPCMDevice) open() error { // input continously records audio and writes it to the ringbuffer. // Re-opens the device and tries again if ASLA returns an error. -func (d *ADPCMDevice) input() { +func (d *ALSA) input() { for { // Check mode. d.mu.Lock() @@ -402,7 +402,7 @@ func (d *ADPCMDevice) input() { } // Read reads from the ringbuffer, returning the number of bytes read upon success. -func (d *ADPCMDevice) Read(p []byte) (int, error) { +func (d *ALSA) Read(p []byte) (int, error) { // Ready ringbuffer for read. _, err := d.rb.Next(rbNextTimeout) if err != nil { @@ -414,7 +414,7 @@ func (d *ADPCMDevice) Read(p []byte) (int, error) { } // formatBuffer returns audio that has been converted to the desired format. -func (d *ADPCMDevice) formatBuffer() alsa.Buffer { +func (d *ALSA) formatBuffer() alsa.Buffer { var err error // If nothing needs to be changed, return the original. diff --git a/device/audio/audio_test.go b/device/audio/audio_test.go index c567f550..a84fad81 100644 --- a/device/audio/audio_test.go +++ b/device/audio/audio_test.go @@ -49,7 +49,7 @@ func TestDevice(t *testing.T) { // Create a new ADPCMDevice, start, read/lex, and then stop it. l := logger.New(logger.Debug, os.Stderr, true) - ai := NewADPCMDevice(l) + ai := NewALSA(l) err := ai.Set(c) // If there was an error opening the device, skip this test. if _, ok := err.(OpenError); ok { diff --git a/revid/audio_linux.go b/revid/audio_linux.go index f637b30d..b209480d 100644 --- a/revid/audio_linux.go +++ b/revid/audio_linux.go @@ -29,7 +29,7 @@ import ( // It returns a function that can be used to stop the device and any errors that occur. func (r *Revid) startAudioDevice() (func() error, error) { // Create audio device. - ai := audio.NewADPCMDevice(r.cfg.Logger) + ai := audio.NewALSA(r.cfg.Logger) err := ai.Set(r.cfg) if err != nil {