diff --git a/cmd/audio-player/looper/main.go b/cmd/audio-player/looper/main.go index 7d39fd82..93764549 100644 --- a/cmd/audio-player/looper/main.go +++ b/cmd/audio-player/looper/main.go @@ -27,13 +27,13 @@ LICENSE /* Pi Setup: pull master - $sudo nano main.go -chage file variable at top of function to be wav file that you have put onto the pi (hint: spc command) navigate to /go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper + $sudo nano main.go +chage file variable at top of function to be wav file that you have put onto the pi (hint: spc command to put a new file on the pi) and build edit rc.local to run looper at boot $sudo nano /etc/rc.local -paste this in after comments but before 'exit 0': +paste this in after comments but before 'exit 0': ----------------------------------------------------------- exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file exec 1>&2 # send stdout to the same log file @@ -44,9 +44,18 @@ AUDIOPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper cd $AUDIOPATH ./looper & - +----------------------------------------------------------------------------------------------------------------- $systemctl enable rc-local $sudo systemctl start rc-local.service +after starting the service the looping should start straight away + +Useful commands: + $cat /tmp/rc.local.log + $sudo systemctl status rc-local.service + $cat audio.log (in looper directory) + +On computer + $scp something.wav pi@192.168.1.106:/home/pi */ package main @@ -62,24 +71,27 @@ import ( ) func main() { - file := "48khz.wav" //"5mStartToEndOfTrials.wav" + soundFile := "48khz.wav" //"5mStartToEndOfTrials.wav" + soundcardPath := "/usr/share/doc/audioInjector/asound.state.RCA.thru.test" + logFile := "audio.log" //making log file - _, err := os.Stat("audio.log") + _, err := os.Stat(logFile) if !os.IsNotExist(err) { - err := os.Remove("audio.log") + err := os.Remove(logFile) if err != nil { log.Fatalf("fatal: error clearing file: %v", err) } } - f, err := os.OpenFile("audio.log", os.O_RDWR|os.O_CREATE, 0666) //chage to empty each time + f, err := os.OpenFile(logFile, os.O_RDWR|os.O_CREATE, 0666) //chage to empty each time if err != nil { - log.Fatalf("fatal: error opening file: %v", err) + log.Fatalf("fatal: error opening file %s: %v", logFile, err) } defer f.Close() log.SetOutput(f) + //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") @@ -88,12 +100,12 @@ func main() { } for { - cmdInit := exec.Command("alsactl", "-f", "/usr/share/doc/audioInjector/asound.state.RCA.thru.test", "restore") + cmdInit := exec.Command("alsactl", "-f", soundcardPath, "restore") err := cmdInit.Run() if err == nil { 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) } @@ -108,9 +120,9 @@ func main() { numPlays := 0 for { numPlays++ - log.Printf(" Number of times played: %d\n", numPlays) + log.Printf(" Play number: %d\n", numPlays) - cmd := exec.Command("play", file) + cmd := exec.Command("play", soundFile) var stdoutBuf, stderrBuf bytes.Buffer stdoutIn, _ := cmd.StdoutPipe() @@ -122,7 +134,7 @@ func main() { err := cmd.Start() if err != nil { - log.Fatalf("fatal: cmd.Start() failed with '%s'\n", err) + log.Fatalf("fatal: cmd.Start() for 'play' failed with '%s'\n", err) } var wg sync.WaitGroup @@ -138,7 +150,7 @@ func main() { err = cmd.Wait() if err != nil { - log.Fatalf("fatal: cmd.Run() failed with %s\n", err) + log.Fatalf("fatal: cmd.Run() for 'play' failed with %s\n", err) } if errStdout != nil || errStderr != nil { log.Fatal("fatal: failed to capture stdout or stderr\n")