]> code.octet-stream.net Git - broadcaster/blobdiff - radio/main.go
Configure CI
[broadcaster] / radio / main.go
index 6e317721235654db46d291980588cd5c511252a7..1f95d76e6bdd0c13816959501cfc48b73b3780e8 100644 (file)
@@ -1,15 +1,9 @@
 package main
 
 import (
 package main
 
 import (
-       "code.octet-stream.net/broadcaster/internal/protocol"
        "encoding/json"
        "flag"
        "fmt"
        "encoding/json"
        "flag"
        "fmt"
-       "github.com/gopxl/beep/v2"
-       "github.com/gopxl/beep/v2/mp3"
-       "github.com/gopxl/beep/v2/speaker"
-       "github.com/gopxl/beep/v2/wav"
-       "golang.org/x/net/websocket"
        "log"
        "os"
        "os/signal"
        "log"
        "os"
        "os/signal"
@@ -17,6 +11,13 @@ import (
        "strings"
        "syscall"
        "time"
        "strings"
        "syscall"
        "time"
+
+       "code.octet-stream.net/broadcaster/internal/protocol"
+       "github.com/gopxl/beep/v2"
+       "github.com/gopxl/beep/v2/mp3"
+       "github.com/gopxl/beep/v2/speaker"
+       "github.com/gopxl/beep/v2/wav"
+       "golang.org/x/net/websocket"
 )
 
 const version = "v1.0.0"
 )
 
 const version = "v1.0.0"
@@ -55,7 +56,7 @@ func main() {
        signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
        go func() {
                sig := <-sig
        signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
        go func() {
                sig := <-sig
-               log.Println("Radio shutting down due to signal", sig)
+               log.Println("Radio shutting down due to signal:", sig)
                // Make sure we always stop PTT when program ends
                ptt.DisengagePTT()
                os.Exit(0)
                // Make sure we always stop PTT when program ends
                ptt.DisengagePTT()
                os.Exit(0)
@@ -130,6 +131,7 @@ func runWebsocket(fileSpecChan chan []protocol.FileSpec, playlistSpecChan chan [
                }
 
                if t == protocol.StopType {
                }
 
                if t == protocol.StopType {
+                       log.Println("Received stop transmission message from server")
                        stop <- true
                }
        }
                        stop <- true
                }
        }
@@ -240,7 +242,7 @@ func playlistWorker(ch <-chan []protocol.PlaylistSpec, stop <-chan bool) {
                                }
                        }
                        if found {
                                }
                        }
                        if found {
-                               duration := soonestTime.Sub(time.Now())
+                               duration := time.Until(soonestTime)
                                log.Println("Next playlist will be id", nextId, "in", duration.Seconds(), "seconds")
                                timer = time.NewTimer(duration)
                        } else {
                                log.Println("Next playlist will be id", nextId, "in", duration.Seconds(), "seconds")
                                timer = time.NewTimer(duration)
                        } else {
@@ -270,6 +272,7 @@ entries:
                select {
                case <-time.After(duration):
                case <-cancel:
                select {
                case <-time.After(duration):
                case <-cancel:
+                       log.Println("Cancelling pre-play delay")
                        break entries
                }
 
                        break entries
                }
 
@@ -284,7 +287,6 @@ entries:
                        Playlist: playlist.Name,
                        Filename: p.Filename,
                }
                        Playlist: playlist.Name,
                        Filename: p.Filename,
                }
-               ptt.EngagePTT()
                f, err := os.Open(filepath.Join(config.CachePath, p.Filename))
                if err != nil {
                        log.Println("Couldn't open file for playlist", p.Filename)
                f, err := os.Open(filepath.Join(config.CachePath, p.Filename))
                if err != nil {
                        log.Println("Couldn't open file for playlist", p.Filename)
@@ -308,13 +310,18 @@ entries:
                defer streamer.Close()
 
                done := make(chan bool)
                defer streamer.Close()
 
                done := make(chan bool)
+               log.Println("PTT on for playback")
+               ptt.EngagePTT()
 
                if format.SampleRate != sampleRate {
 
                if format.SampleRate != sampleRate {
+                       log.Println("Configuring resampler for audio provided at sample rate", format.SampleRate)
                        resampled := beep.Resample(4, format.SampleRate, sampleRate, streamer)
                        resampled := beep.Resample(4, format.SampleRate, sampleRate, streamer)
+                       log.Println("Playing resampled audio")
                        speaker.Play(beep.Seq(resampled, beep.Callback(func() {
                                done <- true
                        })))
                } else {
                        speaker.Play(beep.Seq(resampled, beep.Callback(func() {
                                done <- true
                        })))
                } else {
+                       log.Println("Playing audio at native sample rate")
                        speaker.Play(beep.Seq(streamer, beep.Callback(func() {
                                done <- true
                        })))
                        speaker.Play(beep.Seq(streamer, beep.Callback(func() {
                                done <- true
                        })))
@@ -322,10 +329,13 @@ entries:
 
                select {
                case <-done:
 
                select {
                case <-done:
+                       log.Println("Audio playback complete")
                case <-cancel:
                case <-cancel:
+                       log.Println("Disengaging PTT and aborting playlist playback")
                        ptt.DisengagePTT()
                        break entries
                }
                        ptt.DisengagePTT()
                        break entries
                }
+               log.Println("PTT off since audio file has finished")
                ptt.DisengagePTT()
        }
        log.Println("Playlist finished", playlist.Name)
                ptt.DisengagePTT()
        }
        log.Println("Playlist finished", playlist.Name)