cmd/audio-player: PR fixes

This commit is contained in:
Scott 2020-02-28 11:58:01 +10:30
parent 5e576c3906
commit 27082b2070
2 changed files with 18 additions and 19 deletions

View File

@ -22,8 +22,7 @@ LICENSE
in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
// Audio looper for pi0 model
// Audio looper for pi0 model.
package main
import (
@ -37,9 +36,11 @@ import (
)
func main() {
soundFile := "/home/pi/48khz.wav"
soundcardPath := "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
logFile := "audio.log"
const soundFile = "/home/pi/48khz.wav"
const soundcardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
const logFile = "audio.log"
const sleepDur = 1 * time.Second
const playCmd = "play"
// Making log file.
_, err := os.Stat(logFile)
@ -57,12 +58,12 @@ func main() {
defer f.Close()
log.SetOutput(f)
path, err := exec.LookPath("alsactl") // alsactl is a command that ensures the sound will be played through the correct soundcard
// alsactl is a command that ensures the sound will be played through the correct soundcard.
path, err := exec.LookPath("alsactl")
if err != nil {
log.Fatalf("fatal: didn't find 'alsactl' executable\n")
} else {
log.Printf("debug: 'alsactl' executable is in '%s'\n", path)
}
log.Printf("debug: 'alsactl' executable is in '%s'\n", path)
for {
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
@ -71,16 +72,15 @@ func main() {
break
}
log.Printf("fatal(ish): cmd.Run() for 'alsactl' failed with '%s'\n", err)
time.Sleep(1 * time.Second)
time.Sleep(sleepDur)
}
// Making sure that play command is on the pi.
path, err = exec.LookPath("play")
path, err = exec.LookPath(playCmd)
if err != nil {
log.Fatalf("fatal: didn't find 'play' executable\n")
} else {
log.Printf("debug: 'play' executable is in '%s'\n", path)
}
log.Printf("debug: 'play' executable is in '%s'\n", path)
// Infinite loop that outputs audio and gathers debug information.
numPlays := 0
@ -88,7 +88,7 @@ func main() {
numPlays++
log.Printf("debug: play number: %d\n", numPlays)
cmd := exec.Command("play", soundFile)
cmd := exec.Command(playCmd, soundFile)
var stdoutBuf, stderrBuf bytes.Buffer
stdoutIn, _ := cmd.StdoutPipe()

View File

@ -22,8 +22,7 @@ LICENSE
in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
// Audio looper for pi3 model
// Audio looper for pi3 model.
package main
import (
@ -36,8 +35,8 @@ import (
)
func main() {
soundFile := "/home/pi/48khz.wav"
logFile := "audio.log"
const soundFile = "/home/pi/48khz.wav"
const logFile := "audio.log"
// Making log file.
_, err := os.Stat(logFile)
@ -59,9 +58,9 @@ func main() {
path, err := exec.LookPath("omxplayer")
if err != nil {
log.Fatalf("fatal: didn't find 'omxplayer' executable\n")
} else {
log.Printf("debug: 'omxplayer' executable is in '%s'\n", path)
}
log.Printf("debug: 'omxplayer' executable is in '%s'\n", path)
// Infinite loop that outputs audio and gathers debug information.
numPlays := 0