1 // VoRS -- Vo(IP) Really Simple
2 // Copyright (C) 2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Affero General Public License for more details.
13 // You should have received a copy of the GNU Affero General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 vors "go.stargrave.org/vors/internal"
30 fmt.Fprintf(os.Stderr, "Usage: vors-vad [-rec ...] THRESHOLD\n")
35 recCmd := flag.String("rec", "rec "+vors.SoxParams, "rec command")
38 log.SetFlags(log.Lmicroseconds | log.Lshortfile)
39 if len(flag.Args()) != 1 {
43 thres, err := strconv.ParseUint(flag.Arg(0), 10, 64)
47 buf := make([]byte, 2*vors.FrameLen)
48 pcm := make([]int16, vors.FrameLen)
49 cmd := vors.MakeCmd(*recCmd)
50 mic, err := cmd.StdoutPipe()
61 _, err = io.ReadFull(mic, buf)
65 for i = 0; i < vors.FrameLen; i++ {
66 pcm[i] = int16(uint16(buf[i*2+0]) | (uint16(buf[i*2+1]) << 8))