mirror of https://bitbucket.org/ausocean/av.git
cmd/audio-player: PR fixes
This commit is contained in:
parent
5e576c3906
commit
27082b2070
|
@ -22,8 +22,7 @@ LICENSE
|
||||||
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Audio looper for pi0 model
|
// Audio looper for pi0 model.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -37,9 +36,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
soundFile := "/home/pi/48khz.wav"
|
const soundFile = "/home/pi/48khz.wav"
|
||||||
soundcardPath := "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
|
const soundcardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
|
||||||
logFile := "audio.log"
|
const logFile = "audio.log"
|
||||||
|
const sleepDur = 1 * time.Second
|
||||||
|
const playCmd = "play"
|
||||||
|
|
||||||
// Making log file.
|
// Making log file.
|
||||||
_, err := os.Stat(logFile)
|
_, err := os.Stat(logFile)
|
||||||
|
@ -57,12 +58,12 @@ func main() {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
log.SetOutput(f)
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("fatal: didn't find 'alsactl' executable\n")
|
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 {
|
for {
|
||||||
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
|
cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore")
|
||||||
|
@ -71,16 +72,15 @@ func main() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
log.Printf("fatal(ish): cmd.Run() for 'alsactl' failed with '%s'\n", err)
|
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.
|
// Making sure that play command is on the pi.
|
||||||
path, err = exec.LookPath("play")
|
path, err = exec.LookPath(playCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("fatal: didn't find 'play' executable\n")
|
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.
|
// Infinite loop that outputs audio and gathers debug information.
|
||||||
numPlays := 0
|
numPlays := 0
|
||||||
|
@ -88,7 +88,7 @@ func main() {
|
||||||
numPlays++
|
numPlays++
|
||||||
log.Printf("debug: play number: %d\n", numPlays)
|
log.Printf("debug: play number: %d\n", numPlays)
|
||||||
|
|
||||||
cmd := exec.Command("play", soundFile)
|
cmd := exec.Command(playCmd, soundFile)
|
||||||
|
|
||||||
var stdoutBuf, stderrBuf bytes.Buffer
|
var stdoutBuf, stderrBuf bytes.Buffer
|
||||||
stdoutIn, _ := cmd.StdoutPipe()
|
stdoutIn, _ := cmd.StdoutPipe()
|
||||||
|
|
|
@ -22,8 +22,7 @@ LICENSE
|
||||||
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Audio looper for pi3 model
|
// Audio looper for pi3 model.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -36,8 +35,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
soundFile := "/home/pi/48khz.wav"
|
const soundFile = "/home/pi/48khz.wav"
|
||||||
logFile := "audio.log"
|
const logFile := "audio.log"
|
||||||
|
|
||||||
// Making log file.
|
// Making log file.
|
||||||
_, err := os.Stat(logFile)
|
_, err := os.Stat(logFile)
|
||||||
|
@ -59,9 +58,9 @@ func main() {
|
||||||
path, err := exec.LookPath("omxplayer")
|
path, err := exec.LookPath("omxplayer")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("fatal: didn't find 'omxplayer' executable\n")
|
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.
|
// Infinite loop that outputs audio and gathers debug information.
|
||||||
numPlays := 0
|
numPlays := 0
|
||||||
|
|
Loading…
Reference in New Issue