mirror of https://bitbucket.org/ausocean/av.git
cmd/audio-player/looper: created combined audio looper for pi 0 and pi 3
This commit is contained in:
parent
27082b2070
commit
081efe24d7
|
@ -1,15 +1,15 @@
|
|||
#NAME
|
||||
test-audio/looper0/README.md
|
||||
# NAME
|
||||
test-audio/looper/README.md
|
||||
|
||||
#AUTHORS
|
||||
# AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
|
||||
#Pi Setup:
|
||||
# Pi Setup:
|
||||
- pull master
|
||||
- navigate to /go/src/bitbucket.org/auscean/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
|
||||
- Build using $ go build -tags pi0 or $ go build -tags pi3
|
||||
- edit rc.local to run looper at boot
|
||||
$sudo nano /etc/rc.local
|
||||
- paste this in after comments but before 'exit 0': -----------------------------------------------------------
|
||||
|
@ -19,19 +19,19 @@ exec 1>&2 # send stdout to the same log file
|
|||
printf "rc.local started" # show start of execution
|
||||
set -x # tell sh to display commands before execution
|
||||
|
||||
PLAYERPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper0
|
||||
PLAYERPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper
|
||||
cd $PLAYERPATH
|
||||
|
||||
./looper0 &
|
||||
./looper &
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
$systemctl enable rc-local
|
||||
$sudo systemctl start rc-local.service
|
||||
- after starting the service the looping should start straight away
|
||||
|
||||
#Useful commands:
|
||||
# Useful commands:
|
||||
$cat /tmp/rc.local.log
|
||||
$sudo systemctl status rc-local.service
|
||||
$cat audio.log (in looper directory)
|
||||
|
||||
#On computer
|
||||
# On computer
|
||||
$scp something.wav pi@192.168.1.106:/home/pi
|
|
@ -1,12 +1,12 @@
|
|||
/*
|
||||
NAME
|
||||
audio-player/looper3/main.go
|
||||
audio-player/looper/main.go
|
||||
|
||||
AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
audio player is Copyright (C) 2017-2020 the Australian Ocean Lab (AusOcean)
|
||||
audio player 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.
|
||||
*/
|
||||
|
||||
// Audio looper for pi3 model.
|
||||
// Audio looper.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -36,7 +36,7 @@ import (
|
|||
|
||||
func main() {
|
||||
const soundFile = "/home/pi/48khz.wav"
|
||||
const logFile := "audio.log"
|
||||
const logFile = "audio.log"
|
||||
|
||||
// Making log file.
|
||||
_, err := os.Stat(logFile)
|
||||
|
@ -54,13 +54,8 @@ func main() {
|
|||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
// 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")
|
||||
}
|
||||
log.Printf("debug: 'omxplayer' executable is in '%s'\n", path)
|
||||
|
||||
// Pi model specific initialisation
|
||||
initCommand()
|
||||
|
||||
// Infinite loop that outputs audio and gathers debug information.
|
||||
numPlays := 0
|
||||
|
@ -68,7 +63,7 @@ func main() {
|
|||
numPlays++
|
||||
log.Printf("debug: play number: %d\n", numPlays)
|
||||
|
||||
cmd := exec.Command("omxplayer", soundFile)
|
||||
cmd := exec.Command(audioCmd, soundFile)
|
||||
|
||||
var stdoutBuf, stderrBuf bytes.Buffer
|
||||
stdoutIn, _ := cmd.StdoutPipe()
|
|
@ -0,0 +1,40 @@
|
|||
// +build pi0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
const audioCmd = "play"
|
||||
|
||||
func initCommand() {
|
||||
const soundcardPath = "/usr/share/doc/audioInjector/asound.state.RCA.thru.test"
|
||||
const sleepDur = 1 * time.Second
|
||||
|
||||
// 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")
|
||||
}
|
||||
log.Printf("debug: 'alsactl' executable is in '%s'\n", path)
|
||||
|
||||
for {
|
||||
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)
|
||||
time.Sleep(sleepDur)
|
||||
}
|
||||
|
||||
// Making sure that play command is on the pi.
|
||||
path, err = exec.LookPath(audioCmd)
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: didn't find 'play' executable\n")
|
||||
}
|
||||
log.Printf("debug: 'play' executable is in '%s'\n", path)
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// +build pi3
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
const audioCmd = "omxplayer"
|
||||
|
||||
func initCommand() {
|
||||
// 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")
|
||||
}
|
||||
log.Printf("debug: 'omxplayer' executable is in '%s'\n", path)
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
NAME
|
||||
audio-player/looper0/main.go
|
||||
|
||||
AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
|
||||
LICENSE
|
||||
audio player 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
|
||||
Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
in gpl.txt. If not, see http://www.gnu.org/licenses.
|
||||
*/
|
||||
|
||||
// Audio looper for pi0 model.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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)
|
||||
if !os.IsNotExist(err) {
|
||||
err := os.Remove(logFile)
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: error clearing file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
// 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")
|
||||
}
|
||||
log.Printf("debug: 'alsactl' executable is in '%s'\n", path)
|
||||
|
||||
for {
|
||||
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)
|
||||
time.Sleep(sleepDur)
|
||||
}
|
||||
|
||||
// Making sure that play command is on the pi.
|
||||
path, err = exec.LookPath(playCmd)
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: didn't find 'play' executable\n")
|
||||
}
|
||||
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("debug: play number: %d\n", numPlays)
|
||||
|
||||
cmd := exec.Command(playCmd, soundFile)
|
||||
|
||||
var stdoutBuf, stderrBuf bytes.Buffer
|
||||
stdoutIn, _ := cmd.StdoutPipe()
|
||||
stderrIn, _ := cmd.StderrPipe()
|
||||
|
||||
var errStdout, errStderr error
|
||||
stdout := io.MultiWriter(os.Stdout, &stdoutBuf)
|
||||
stderr := io.MultiWriter(os.Stderr, &stderrBuf)
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
log.Fatalf("fatal: cmd.Start() for 'play' failed with '%s'\n", err)
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
_, errStdout = io.Copy(stdout, stdoutIn)
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
_, errStderr = io.Copy(stderr, stderrIn)
|
||||
wg.Wait()
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
|
||||
log.Printf("\nout:\n%s\nerr:\n%s\n____________________________________________________\n\n", outStr, errStr)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#NAME
|
||||
test-audio/looper3/README.md
|
||||
|
||||
#AUTHORS
|
||||
Ella Pietraroia <ella@ausocean.org>
|
||||
|
||||
#Pi Setup:
|
||||
- pull master
|
||||
- navigate to /go/src/bitbucket.org/auscean/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': -----------------------------------------------------------
|
||||
|
||||
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
|
||||
printf "rc.local started" # show start of execution
|
||||
set -x # tell sh to display commands before execution
|
||||
|
||||
PLAYERPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/audio-player/looper3
|
||||
cd $PLAYERPATH
|
||||
|
||||
./looper3 &
|
||||
-----------------------------------------------------------------------------------------------------------------
|
||||
$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
|
Loading…
Reference in New Issue