Skip to content

Commit

Permalink
Add ALSA support. Don't depend on going through pulseaudio, which doe…
Browse files Browse the repository at this point in the history
…sn't always start on boot.
  • Loading branch information
bradfitz committed Jan 21, 2013
1 parent 7ea47db commit 97172b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 0 additions & 5 deletions Makefile

This file was deleted.

9 changes: 8 additions & 1 deletion sonden.go
Expand Up @@ -29,6 +29,7 @@ import (
var (
ampAddrs = flag.String("amps", "", "Comma-separated list of ip:port of Denon amps")
idleSec = flag.Int("idlesec", 300, "number of seconds of silence before turning off amps")
alsaDev = flag.String("alsadev", "", "If non-empty, arecord(1) is used instead of rec(1) with this ALSA device name. e.g. plughw:CARD=Audio,DEV=0 (see arecord -L)")
)

const (
Expand Down Expand Up @@ -99,6 +100,12 @@ func main() {
"-b", "16", // 16 bits per sample
"-c", "1", // one channel
"-")
if *alsaDev != "" {
cmd = exec.Command("arecord",
"-D", *alsaDev,
"-f", "S16_LE",
"-t", "raw")
}
out, _ := cmd.StdoutPipe()
err := cmd.Start()
if err != nil {
Expand Down Expand Up @@ -127,7 +134,7 @@ func main() {
var sample int16
err := binary.Read(out, binary.LittleEndian, &sample)
if err != nil {
log.Fatalf("error reading next sample: %v")
log.Fatalf("error reading next sample: %v", err)
}
ring.Add(sample)
if ring.i != 0 {
Expand Down

0 comments on commit 97172b9

Please sign in to comment.