2019-11-22 05:52:23 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
audio_linux.go
|
|
|
|
|
|
|
|
AUTHORS
|
|
|
|
Alan Noble <alan@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
revid is Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It 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 (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"bitbucket.org/ausocean/av/codec/codecutil"
|
|
|
|
"bitbucket.org/ausocean/av/codec/pcm"
|
|
|
|
"bitbucket.org/ausocean/av/container/mts"
|
|
|
|
"bitbucket.org/ausocean/av/device/alsa"
|
|
|
|
"bitbucket.org/ausocean/utils/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *Revid) setupAudio() error {
|
2020-05-02 06:55:13 +03:00
|
|
|
mts.Meta.Add("sampleRate", strconv.Itoa(int(r.cfg.SampleRate)))
|
|
|
|
mts.Meta.Add("channels", strconv.Itoa(int(r.cfg.Channels)))
|
2019-11-22 05:52:23 +03:00
|
|
|
mts.Meta.Add("period", fmt.Sprintf("%.6f", r.cfg.RecPeriod))
|
2020-05-02 06:55:13 +03:00
|
|
|
mts.Meta.Add("bitDepth", strconv.Itoa(int(r.cfg.BitDepth)))
|
2019-11-22 05:52:23 +03:00
|
|
|
|
|
|
|
switch r.cfg.InputCodec {
|
|
|
|
case codecutil.PCM:
|
|
|
|
mts.Meta.Add("codec", "pcm")
|
|
|
|
case codecutil.ADPCM:
|
|
|
|
mts.Meta.Add("codec", "adpcm")
|
|
|
|
default:
|
2020-03-27 17:34:02 +03:00
|
|
|
r.cfg.Logger.Log(logger.Fatal, "no audio codec set in config")
|
2019-11-22 05:52:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
r.input = alsa.New(r.cfg.Logger)
|
|
|
|
|
|
|
|
l, err := codecutil.NewByteLexer(pcm.DataSize(r.cfg.SampleRate, r.cfg.Channels, r.cfg.BitDepth, r.cfg.RecPeriod, r.cfg.InputCodec))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
r.lexTo = l.Lex
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|