Skip to content

Instantly share code, notes, and snippets.

@faiface
Created July 19, 2017 19:43
Show Gist options
  • Save faiface/80ad7e89f102c6d914ce2a1bb6cb3c47 to your computer and use it in GitHub Desktop.
Save faiface/80ad7e89f102c6d914ce2a1bb6cb3c47 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/wav"
)
func main() {
beep.SampleRate = 44100
speaker.Init(time.Second / 60)
f, _ := os.Open("13 Face to Face.wav")
s, _ := wav.Decode(f)
v := &effects.Volume{
Streamer: s,
Base: math.Phi,
Volume: 0.0,
}
speaker.Play(v)
for {
var volume float64
fmt.Scan(&volume)
speaker.Lock()
v.Volume = volume
speaker.Unlock()
const (
sliderLen = 16
volumeMin = -8
volumeMax = 0
)
dots := int(sliderLen * (volume - volumeMin) / (volumeMax - volumeMin))
fmt.Print("[")
for i := 0; i < dots; i++ {
fmt.Print("#")
}
for i := dots; i < sliderLen; i++ {
fmt.Print(" ")
}
fmt.Println("]")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment