looper: commenting

This commit is contained in:
Ella Pietraroia 2020-02-27 14:29:45 +10:30
parent 9faa1940a8
commit db773444d3
2 changed files with 22 additions and 28 deletions

View File

@ -1,12 +1,12 @@
/*
NAME
test-audio/main.go
test-audio/looper0/main.go
AUTHORS
Ella Pietraroia <ella@ausocean.org>
LICENSE
revid is Copyright (C) 2017-2020 the Australian Ocean Lab (AusOcean)
revid is Copyright (C) 2020 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
@ -22,7 +22,7 @@ LICENSE
in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
//testing for underwater speaker audio playing on pi
// Audio looper for pi0 model
package main
@ -37,11 +37,11 @@ import (
)
func main() {
soundFile := "/home/pi/48khz.wav" //"5mStartToEndOfTrials.wav"
soundFile := "/home/pi/48khz.wav"
soundcardPath := "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
logFile := "audio.log"
//making log file
// Making log file.
_, err := os.Stat(logFile)
if !os.IsNotExist(err) {
err := os.Remove(logFile)
@ -50,26 +50,18 @@ func main() {
}
}
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE, 0666) //chage to empty each time
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatalf("fatal: error opening file %s: %v", logFile, err)
}
defer f.Close()
log.SetOutput(f)
path, err := exec.LookPath("alsactl")
path, err := exec.LookPath("alsactl") // alsactl is a command that ensures the sound will be played through the correct soundcard
if err != nil {
log.Fatalf("fatal: didn't find 'alsactl' executable\n")
} else {
log.Printf("'alsactl' executable is in '%s'\n", path)
}
//alsactl ensures that 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("'alsactl' executable is in '%s'\n", path)
log.Printf("debug: 'alsactl' executable is in '%s'\n", path)
}
for {
@ -82,18 +74,19 @@ func main() {
time.Sleep(1 * time.Second)
}
//making sure that play is on pi
path, err = exec.LookPath("play")
// Making sure that play command is on the pi.
path, err := exec.LookPath("play")
if err != nil {
log.Fatalf("fatal: didn't find 'play' executable\n")
} else {
log.Printf("'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
for {
numPlays++
log.Printf(" Play number: %d\n", numPlays)
log.Printf("debug: play number: %d\n", numPlays)
cmd := exec.Command("play", soundFile)

View File

@ -1,6 +1,6 @@
/*
NAME
test-audio/main.go
test-audio/looper3/main.go
AUTHORS
Ella Pietraroia <ella@ausocean.org>
@ -22,7 +22,7 @@ LICENSE
in gpl.txt. If not, see http://www.gnu.org/licenses.
*/
//testing for underwater speaker audio playing on pi
// Audio looper for pi3 model
package main
@ -36,10 +36,10 @@ import (
)
func main() {
soundFile := "/home/pi/48khz.wav" //"5mStartToEndOfTrials.wav"
soundFile := "/home/pi/48khz.wav"
logFile := "audio.log"
//making log file
// Making log file.
_, err := os.Stat(logFile)
if !os.IsNotExist(err) {
err := os.Remove(logFile)
@ -48,25 +48,26 @@ func main() {
}
}
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE, 0666) //chage to empty each time
f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
log.Fatalf("fatal: error opening file %s: %v", logFile, err)
}
defer f.Close()
log.SetOutput(f)
//making sure that play is on pi
// Making sure that omxplayer command is on the pi.
path, err := exec.LookPath("omxplayer")
if err != nil {
log.Fatalf("fatal: didn't find 'omxplayer' executable\n")
} else {
log.Printf("'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
for {
numPlays++
log.Printf(" Play number: %d\n", numPlays)
log.Printf("debug: play number: %d\n", numPlays)
cmd := exec.Command("omxplayer", soundFile)