2022-11-18 21:18:12 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2023-11-25 19:05:26 +00:00
|
|
|
"math"
|
2023-11-02 20:30:29 +00:00
|
|
|
|
2023-10-26 20:49:39 +00:00
|
|
|
"github.com/gopxl/beep"
|
|
|
|
"github.com/gopxl/beep/effects"
|
2022-11-18 21:18:12 +00:00
|
|
|
|
|
|
|
discordspeaker "dndmusicbot/speaker"
|
|
|
|
)
|
|
|
|
|
2023-11-25 19:05:26 +00:00
|
|
|
const (
|
|
|
|
volmin = -10.0
|
|
|
|
volmax = 0.0
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
pl_volume *effects.Volume
|
|
|
|
amb_volume *effects.Volume
|
|
|
|
ambMixer beep.Mixer
|
|
|
|
plMixer beep.Mixer
|
|
|
|
)
|
|
|
|
|
|
|
|
func PercentToVolume(p float64) float64 {
|
|
|
|
return (p * (volmax - volmin) / 100) + volmin
|
|
|
|
}
|
|
|
|
|
|
|
|
func VolumeToPercent(v float64) float64 {
|
|
|
|
ratio := math.Pow(10, 2)
|
|
|
|
return math.Round(((v-volmin)*100)/(volmax-volmin)*ratio) / ratio
|
|
|
|
}
|
2022-12-03 18:22:05 +00:00
|
|
|
|
2022-11-18 21:18:12 +00:00
|
|
|
func init() {
|
2023-10-26 20:49:39 +00:00
|
|
|
log.Println("beep.go loading..")
|
2023-11-25 19:05:26 +00:00
|
|
|
ambMixer = beep.Mixer{}
|
2022-12-03 18:22:05 +00:00
|
|
|
|
|
|
|
amb_volume = &effects.Volume{
|
2023-11-25 19:05:26 +00:00
|
|
|
Streamer: &ambMixer,
|
2022-12-03 18:22:05 +00:00
|
|
|
Base: 2,
|
2023-11-02 20:30:29 +00:00
|
|
|
Volume: -2,
|
2022-12-03 18:22:05 +00:00
|
|
|
Silent: false,
|
|
|
|
}
|
2023-11-02 20:30:29 +00:00
|
|
|
|
2022-12-03 18:22:05 +00:00
|
|
|
discordspeaker.Play(amb_volume)
|
2022-11-18 21:18:12 +00:00
|
|
|
|
2023-11-25 19:05:26 +00:00
|
|
|
/*
|
|
|
|
amb_stream, err := snapcast.New("127.0.0.1", config.GetInt("mpd.ambiance"))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// ambMixer.Add(amb_stream)
|
2023-11-02 20:30:29 +00:00
|
|
|
|
2023-11-25 19:05:26 +00:00
|
|
|
plMixer = beep.Mixer{}
|
2022-11-23 07:37:59 +00:00
|
|
|
|
2022-12-03 18:22:05 +00:00
|
|
|
pl_volume = &effects.Volume{
|
2023-11-25 19:05:26 +00:00
|
|
|
Streamer: &plMixer,
|
2022-11-23 22:29:45 +00:00
|
|
|
Base: 2,
|
|
|
|
Volume: -2,
|
|
|
|
Silent: false,
|
|
|
|
}
|
|
|
|
|
2023-11-25 19:05:26 +00:00
|
|
|
discordspeaker.Play(beep.Resample(4, beep.SampleRate(44100), beep.SampleRate(48000), pl_volume))
|
|
|
|
/*
|
|
|
|
pl_stream, err := snapcast.New("127.0.0.1", config.GetInt("mpd.playlist"))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-11-02 20:30:29 +00:00
|
|
|
|
2023-11-25 19:05:26 +00:00
|
|
|
plMixer.Add(pl_stream)
|
|
|
|
*/
|
2023-11-02 20:30:29 +00:00
|
|
|
|
2023-11-25 19:05:26 +00:00
|
|
|
discordspeaker.Lock()
|
|
|
|
plMixer.Add(player)
|
|
|
|
discordspeaker.Unlock()
|
2023-10-26 20:49:39 +00:00
|
|
|
log.Println("beep.go done.")
|
2022-11-18 21:18:12 +00:00
|
|
|
}
|