package sine import ( "io" "log" "time" "git.icedream.tech/icedream/uplink/app/channels" humanize "github.com/dustin/go-humanize" "github.com/viert/lame" ) type pluginInstance struct { channelManager *channels.ChannelManager } func (instance *pluginInstance) SetChannelManager(channelManager *channels.ChannelManager) { instance.channelManager = channelManager } func (instance *pluginInstance) Init() { channelManager := instance.channelManager go func() { c, err := channelManager.Open("sine") if err != nil { log.Println("ERROR: sine channel could not be opened:", err) log.Println("Skipping sine channel creation") return } go func() { lastTime := time.Now() for { lastTime = lastTime.Add(time.Second) time.Sleep(time.Until(lastTime)) c.SetMetadata(map[string]string{ "StreamTitle": "beep - time: " + time.Now().String(), }) } }() outputStream := c.AddOutputStream("mp3") defer outputStream.Close() outputContainer := c.AddOutputContainer("mp3") defer outputContainer.Close() w := io.MultiWriter( outputContainer, outputStream, ) wr := lame.NewWriter(w) wr.Encoder.SetBitrate(192) wr.Encoder.SetQuality(1) wr.Encoder.SetInSamplerate(44100) wr.Encoder.SetNumChannels(2) wr.Encoder.InitParams() log.Println("Sine stream goroutine started") sine := new(SineStream) sine.Samplerate = 44100 sine.Frequency = 990 sine.Beep = true sine.Timestamp = time.Now() log.Println("Will now broadcast sine stream") n, err := io.Copy(wr, sine) if err != nil { log.Fatal("Sine stream copy failed:", err) } log.Println("Sine stream finished, written", humanize.Bytes(uint64(n)), "bytes") }() }