Skip to content

Commit

Permalink
fixed repeater tone logic and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Feb 14, 2021
1 parent 3c4fa3c commit 037f405
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 65 deletions.
2 changes: 0 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,6 @@ keyPressListenerLoop:
b.cmdPanicSimulation()
case term.KeyCtrlG:
b.cmdPlayRepeaterTone()
time.Sleep(1 * time.Second)
b.cmdPlayRepeaterTone()
case term.KeyCtrlR:
b.cmdRepeatTxLoop()
case term.KeyCtrlS:
Expand Down
4 changes: 0 additions & 4 deletions clientcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ func (b *Talkkonnect) TransmitStart() {

b.IsTransmitting = true

if RepeaterToneEnabled {
b.RepeaterTone(RepeaterToneFilenameAndPath, RepeaterToneVolume)
}

if pstream.State() == gumbleffmpeg.StatePlaying {
pstream.Stop()
}
Expand Down
16 changes: 3 additions & 13 deletions commandkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,19 +822,9 @@ func (b *Talkkonnect) cmdDumpXMLConfig() {
}

func (b *Talkkonnect) cmdPlayRepeaterTone() {
log.Println("debug: Ctrl-Q Pressed")
log.Println("info: Play Repeater Tone File into Stream")
log.Println("debug: Ctrl-G Pressed")
log.Println("info: Play Repeater Tone on Speaker and Simulate RX Signal")

b.BackLightTimer()

if b.IsTransmitting {
log.Println("alert: talkkonnect was already transmitting will now stop transmitting and start to play the repeater tone")
b.TransmitStop(false)
}

go b.playIntoStream(RepeaterToneFilenameAndPath, RepeaterToneVolume)

IsPlayStream = !IsPlayStream
// NowStreaming = IsPlayStream

b.RepeaterTone()
}
39 changes: 26 additions & 13 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package talkkonnect

import (
"bytes"
"encoding/binary"
"errors"
"fmt"
Expand All @@ -38,6 +39,7 @@ import (
"github.com/talkkonnect/gumble/gumble"
"github.com/talkkonnect/gumble/gumbleffmpeg"
"log"
"os/exec"
"strconv"
"time"
)
Expand Down Expand Up @@ -333,20 +335,31 @@ func (b *Talkkonnect) playIntoStream(filepath string, vol float32) {
return
}

func (b *Talkkonnect) RepeaterTone(filepath string, vol float32) {
if pstream != nil && pstream.State() == gumbleffmpeg.StatePlaying {
pstream.Stop()
return
}
pstream = gumbleffmpeg.New(b.Client, gumbleffmpeg.SourceFile(filepath), vol)
if err := pstream.Play(); err != nil {
log.Println("error: Error Playing Repeater Tone ", err)
return
func (b *Talkkonnect) RepeaterTone() {

if RepeaterToneEnabled {

cmdArguments := []string{"-f", "lavfi", "-i", "sine=frequency=" + strconv.Itoa(RepeaterToneFrequencyHz) + ":duration=" + strconv.Itoa(RepeaterToneDurationSec), "-autoexit", "-nodisp"}

cmd := exec.Command("/usr/bin/ffplay", cmdArguments...)

var out bytes.Buffer

LEDOnFunc(VoiceActivityLED)
cmd.Stdout = &out
err := cmd.Run()
LEDOffFunc(VoiceActivityLED)

if err != nil {
log.Println("error: ffplay error ", err)
} else {
log.Println("info: Played Tone at Frequency " + strconv.Itoa(RepeaterToneFrequencyHz) + " Hz With Duration of " + strconv.Itoa(RepeaterToneDurationSec) + " Seconds For Opening Repeater")
}

} else {
log.Println(fmt.Sprintf("warn: Repeater Tone Disabled by Config"))
}
log.Println("info: Repeater Tone File " + filepath + " Playing!")
pstream.Wait()
pstream.Stop()
b.LEDOff(b.TransmitLED)

return
}

Expand Down
58 changes: 25 additions & 33 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (

//version and release date
const (
talkkonnectVersion string = "1.57.01"
talkkonnectReleased string = "January 26 2021"
talkkonnectVersion string = "1.58.01"
talkkonnectReleased string = "February 14 2021"
)

var (
Expand Down Expand Up @@ -193,8 +193,8 @@ var (
RogerBeepSoundFilenameAndPath string
RogerBeepSoundVolume float32
RepeaterToneEnabled bool
RepeaterToneFilenameAndPath string
RepeaterToneVolume float32
RepeaterToneFrequencyHz int
RepeaterToneDurationSec int
ChimesSoundEnabled bool
ChimesSoundFilenameAndPath string
ChimesSoundVolume float32
Expand Down Expand Up @@ -535,8 +535,8 @@ type Document struct {
} `xml:"rogerbeep"`
RepeaterTone struct {
Enabled bool `xml:"enabled,attr"`
FilenameAndPath string `xml:"filenameandpath"`
Volume float32 `xml:"volume"`
ToneFrequencyHz int `xml:"tonefrequencyhz"`
ToneDurationSec int `xml:"tonedurationsec"`
} `xml:"repeatertone"`
Chimes struct {
Enabled bool `xml:"enabled,attr"`
Expand Down Expand Up @@ -1135,16 +1135,8 @@ func readxmlconfig(file string) error {
RogerBeepSoundVolume = document.Global.Software.Sounds.RogerBeep.Volume

RepeaterToneEnabled = document.Global.Software.Sounds.RepeaterTone.Enabled
RepeaterToneFilenameAndPath = document.Global.Software.Sounds.RepeaterTone.FilenameAndPath

if RepeaterToneEnabled && RepeaterToneFilenameAndPath == "" {
path := defaultSharePath + "/soundfiles/repeatertones/Chirsp.wav"
if _, err := os.Stat(path); err == nil {
RepeaterToneFilenameAndPath = path
}
}

RepeaterToneVolume = document.Global.Software.Sounds.RepeaterTone.Volume
RepeaterToneFrequencyHz = document.Global.Software.Sounds.RepeaterTone.ToneFrequencyHz
RepeaterToneDurationSec = document.Global.Software.Sounds.RepeaterTone.ToneDurationSec

ChimesSoundEnabled = document.Global.Software.Sounds.Chimes.Enabled
ChimesSoundFilenameAndPath = document.Global.Software.Sounds.Chimes.FilenameAndPath
Expand Down Expand Up @@ -1486,23 +1478,23 @@ func printxmlconfig() {

if PrintSounds {
log.Println("info: ------------- Sounds ------------------ ")
log.Println("info: Event Sound Enabled " + fmt.Sprintf("%t", EventSoundEnabled))
log.Println("info: Event Sound Filename " + EventSoundFilenameAndPath)
log.Println("info: Alert Sound Enabled " + fmt.Sprintf("%t", AlertSoundEnabled))
log.Println("info: Alert Sound Filename " + AlertSoundFilenameAndPath)
log.Println("info: Alert Sound Volume " + fmt.Sprintf("%v", AlertSoundVolume))
log.Println("info: Incomming Beep Enabled " + fmt.Sprintf("%t", IncommingBeepSoundEnabled))
log.Println("info: Incomming Beep File " + IncommingBeepSoundFilenameAndPath)
log.Println("info: Incomming Beep Volume " + fmt.Sprintf("%v", IncommingBeepSoundVolume))
log.Println("info: Roger Beep Enabled " + fmt.Sprintf("%t", RogerBeepSoundEnabled))
log.Println("info: Roger Beep File " + RogerBeepSoundFilenameAndPath)
log.Println("info: Roger Beep Volume " + fmt.Sprintf("%v", RogerBeepSoundVolume))
log.Println("info: Repeater Tone Enabled " + fmt.Sprintf("%t", RepeaterToneEnabled))
log.Println("info: Repeater Tone File " + RepeaterToneFilenameAndPath)
log.Println("info: Repeater Tone Volume " + fmt.Sprintf("%v", RepeaterToneVolume))
log.Println("info: Chimes Enabled " + fmt.Sprintf("%t", ChimesSoundEnabled))
log.Println("info: Chimes File " + ChimesSoundFilenameAndPath)
log.Println("info: Chimes Volume " + fmt.Sprintf("%v", ChimesSoundVolume))
log.Println("info: Event Sound Enabled " + fmt.Sprintf("%t", EventSoundEnabled))
log.Println("info: Event Sound Filename " + EventSoundFilenameAndPath)
log.Println("info: Alert Sound Enabled " + fmt.Sprintf("%t", AlertSoundEnabled))
log.Println("info: Alert Sound Filename " + AlertSoundFilenameAndPath)
log.Println("info: Alert Sound Volume " + fmt.Sprintf("%v", AlertSoundVolume))
log.Println("info: Incomming Beep Enabled " + fmt.Sprintf("%t", IncommingBeepSoundEnabled))
log.Println("info: Incomming Beep File " + IncommingBeepSoundFilenameAndPath)
log.Println("info: Incomming Beep Volume " + fmt.Sprintf("%v", IncommingBeepSoundVolume))
log.Println("info: Roger Beep Enabled " + fmt.Sprintf("%t", RogerBeepSoundEnabled))
log.Println("info: Roger Beep File " + RogerBeepSoundFilenameAndPath)
log.Println("info: Roger Beep Volume " + fmt.Sprintf("%v", RogerBeepSoundVolume))
log.Println("info: Repeater Tone Enabled " + fmt.Sprintf("%t", RepeaterToneEnabled))
log.Println("info: Repeater Tone Freq (Hz) " + fmt.Sprintf("%v", RepeaterToneFrequencyHz))
log.Println("info: Repeater Tone Length (Sec) " + fmt.Sprintf("%v", RepeaterToneDurationSec))
log.Println("info: Chimes Enabled " + fmt.Sprintf("%t", ChimesSoundEnabled))
log.Println("info: Chimes File " + ChimesSoundFilenameAndPath)
log.Println("info: Chimes Volume " + fmt.Sprintf("%v", ChimesSoundVolume))
} else {
log.Println("info: ------------ Sounds ------------------ SKIPPED ")
}
Expand Down

0 comments on commit 037f405

Please sign in to comment.