mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
horn limits and such
This commit is contained in:
+18
-13
@@ -66,13 +66,14 @@ type AudioConfig struct {
|
||||
}
|
||||
|
||||
type HornConfig struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
Volume float64 `yaml:"volume" json:"-"`
|
||||
SampleRate int `yaml:"sampleRate" json:"-"`
|
||||
Channels int `yaml:"channels" json:"-"`
|
||||
Device string `yaml:"device" json:"-"`
|
||||
SineGain float64 `yaml:"sineGain" json:"-"`
|
||||
SawGain float64 `yaml:"sawGain" json:"-"`
|
||||
Enabled bool `yaml:"enabled" json:"enabled"`
|
||||
Volume float64 `yaml:"volume" json:"-"`
|
||||
SampleRate int `yaml:"sampleRate" json:"-"`
|
||||
Channels int `yaml:"channels" json:"-"`
|
||||
Device string `yaml:"device" json:"-"`
|
||||
SineGain float64 `yaml:"sineGain" json:"-"`
|
||||
SawGain float64 `yaml:"sawGain" json:"-"`
|
||||
MaxDuration Duration `yaml:"maxDuration" json:"-"`
|
||||
}
|
||||
|
||||
type MediaConfig struct {
|
||||
@@ -172,12 +173,13 @@ func LoadConfig(path string) (*Config, error) {
|
||||
DefaultPitch: 50,
|
||||
},
|
||||
Horn: HornConfig{
|
||||
Enabled: false,
|
||||
Volume: 0.25,
|
||||
SampleRate: 48000,
|
||||
Channels: 1,
|
||||
SineGain: 1.0,
|
||||
SawGain: 0.7,
|
||||
Enabled: false,
|
||||
Volume: 0.25,
|
||||
SampleRate: 48000,
|
||||
Channels: 1,
|
||||
SineGain: 1.0,
|
||||
SawGain: 0.7,
|
||||
MaxDuration: Duration{Duration: 1200 * time.Millisecond},
|
||||
},
|
||||
NightVision: NightVisionConfig{
|
||||
Enabled: true,
|
||||
@@ -330,6 +332,9 @@ func validateHornConfig(cfg *HornConfig) {
|
||||
if cfg.SawGain <= 0 {
|
||||
cfg.SawGain = 0.7
|
||||
}
|
||||
if cfg.MaxDuration.Duration <= 0 {
|
||||
cfg.MaxDuration = Duration{Duration: 1200 * time.Millisecond}
|
||||
}
|
||||
}
|
||||
|
||||
func validateNightVisionConfig(cfg *NightVisionConfig) error {
|
||||
|
||||
+10
-2
@@ -135,7 +135,11 @@ func (h *HornSynth) run(waveform string, freqs []float64, stop <-chan struct{})
|
||||
h.mu.Unlock()
|
||||
|
||||
writer := bufio.NewWriterSize(stdin, 32*1024)
|
||||
if err := h.synthLoop(writer, waveform, freqs, rate, channels, volume, stop); err != nil {
|
||||
maxFrames := 0
|
||||
if h.cfg.MaxDuration.Duration > 0 {
|
||||
maxFrames = int(float64(rate) * h.cfg.MaxDuration.Duration.Seconds())
|
||||
}
|
||||
if err := h.synthLoop(writer, waveform, freqs, rate, channels, volume, maxFrames, stop); err != nil {
|
||||
h.log.Printf("horn: synth failed: %v", err)
|
||||
}
|
||||
_ = writer.Flush()
|
||||
@@ -151,7 +155,7 @@ func (h *HornSynth) run(waveform string, freqs []float64, stop <-chan struct{})
|
||||
h.mu.Unlock()
|
||||
}
|
||||
|
||||
func (h *HornSynth) synthLoop(writer *bufio.Writer, waveform string, freqs []float64, rate, channels int, volume float64, stop <-chan struct{}) error {
|
||||
func (h *HornSynth) synthLoop(writer *bufio.Writer, waveform string, freqs []float64, rate, channels int, volume float64, maxFrames int, stop <-chan struct{}) error {
|
||||
phase := make([]float64, len(freqs))
|
||||
increment := make([]float64, len(freqs))
|
||||
for i, f := range freqs {
|
||||
@@ -182,6 +186,10 @@ func (h *HornSynth) synthLoop(writer *bufio.Writer, waveform string, freqs []flo
|
||||
}
|
||||
}
|
||||
for i := 0; i < framesPerChunk; i++ {
|
||||
if maxFrames > 0 && sampleIndex >= maxFrames && !stopRequested {
|
||||
stopRequested = true
|
||||
releaseStart = sampleIndex
|
||||
}
|
||||
env := 1.0
|
||||
if attackFrames > 0 && sampleIndex < attackFrames {
|
||||
env = float64(sampleIndex) / float64(attackFrames)
|
||||
|
||||
@@ -52,6 +52,7 @@ horn:
|
||||
channels: 1
|
||||
sineGain: 1.0
|
||||
sawGain: 0.7
|
||||
maxDuration: 1.2s
|
||||
nightVision:
|
||||
enabled: true
|
||||
gpioPin: 22
|
||||
|
||||
Reference in New Issue
Block a user