From 037f40546a78559aa62cd6aeaa2ff04ebda26fd4 Mon Sep 17 00:00:00 2001 From: Suvir Kumar Date: Sun, 14 Feb 2021 10:51:46 +0700 Subject: [PATCH] fixed repeater tone logic and functions --- client.go | 2 -- clientcommands.go | 4 ---- commandkeys.go | 16 +++---------- stream.go | 39 ++++++++++++++++++++----------- xmlparser.go | 58 ++++++++++++++++++++--------------------------- 5 files changed, 54 insertions(+), 65 deletions(-) diff --git a/client.go b/client.go index 8636c38..1d5240d 100644 --- a/client.go +++ b/client.go @@ -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: diff --git a/clientcommands.go b/clientcommands.go index 026eee5..9edfb2c 100644 --- a/clientcommands.go +++ b/clientcommands.go @@ -163,10 +163,6 @@ func (b *Talkkonnect) TransmitStart() { b.IsTransmitting = true - if RepeaterToneEnabled { - b.RepeaterTone(RepeaterToneFilenameAndPath, RepeaterToneVolume) - } - if pstream.State() == gumbleffmpeg.StatePlaying { pstream.Stop() } diff --git a/commandkeys.go b/commandkeys.go index 3127ed0..63063f7 100644 --- a/commandkeys.go +++ b/commandkeys.go @@ -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() } diff --git a/stream.go b/stream.go index 69ee4fd..cce96cf 100644 --- a/stream.go +++ b/stream.go @@ -30,6 +30,7 @@ package talkkonnect import ( + "bytes" "encoding/binary" "errors" "fmt" @@ -38,6 +39,7 @@ import ( "github.com/talkkonnect/gumble/gumble" "github.com/talkkonnect/gumble/gumbleffmpeg" "log" + "os/exec" "strconv" "time" ) @@ -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 } diff --git a/xmlparser.go b/xmlparser.go index 2de4ccc..faf42d2 100644 --- a/xmlparser.go +++ b/xmlparser.go @@ -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 ( @@ -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 @@ -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"` @@ -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 @@ -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 ") }