mirror of https://bitbucket.org/ausocean/av.git
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
/*
|
|
LICENSE
|
|
Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
This is free software: you can redistribute it and/or modify them
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
*/
|
|
|
|
package revid
|
|
|
|
import (
|
|
"time"
|
|
|
|
"bitbucket.org/ausocean/av/device/audio"
|
|
"bitbucket.org/ausocean/utils/logger"
|
|
)
|
|
|
|
// startAudioDevice is used to start capturing audio from an audio device and processing it.
|
|
// 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)
|
|
|
|
err := ai.Set(r.cfg)
|
|
if err != nil {
|
|
r.cfg.Logger.Log(logger.Fatal, pkg+"failed to setup audio device", "error", err.Error())
|
|
}
|
|
|
|
// Start audio device
|
|
err = ai.Start()
|
|
if err != nil {
|
|
r.cfg.Logger.Log(logger.Fatal, pkg+"failed to start audio device", "error", err.Error())
|
|
}
|
|
|
|
// Process output from audio device.
|
|
r.cfg.ChunkSize = ai.ChunkSize()
|
|
r.wg.Add(1)
|
|
go r.processFrom(ai, time.Duration(float64(time.Second)/r.cfg.WriteRate))
|
|
return func() error {
|
|
ai.Stop()
|
|
return nil
|
|
}, nil
|
|
}
|