Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 469278f

Browse files
committed
Stupid duct tape fix
1 parent 4f82762 commit 469278f

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ I know. It's a bug somewhere in the audio library used by Screm Bot 3000. Follow
4444
1. Switch `screm.exe`'s output to your desired output (e.g. "VoiceMeeter Input")
4545
1. Change the default sound output to the previous value (e.g. "USB Sound Card")
4646
1. Verify that sounds from various programs are going through your desired outputs
47+
48+
### Some of my sound files sound like a whale or chipmunk...?
49+
50+
Yeah, so, there's this thing in audio files called a "sample rate". It's basically how fast the sound data gets played to the speaker. The [audio library I'm using](https://github.com/faiface/beep) is *supposed* to support different sample rates across your collection of sound files, but I've tested, retested, refactored, and cried over why that's not working so instead I hardcoded the library to expect 44100 as the sample rate and put a `fix-sample-rates.sh` script in `./sounds` that forces all audio files in a provided directory (e.g. `./fix-sample-rates.sh e-epic`) to 44100 `.wav`. That's the only way I've found to prevent crashes. Writing Screm Bot 3000 in Go was a mistake.

main.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func main() {
6767
}
6868
}()
6969

70-
err = startupSound()
70+
err = configureSpeaker()
7171
if err != nil {
7272
log.Fatal("Could not configure speaker:", err.Error())
7373
}
@@ -239,8 +239,14 @@ func registerShortcuts() error {
239239
return nil
240240
}
241241

242-
func startupSound() error {
242+
func configureSpeaker() error {
243243
path := soundsDir + "/startup.wav"
244+
_, format, err := decodeFile(path)
245+
if err != nil {
246+
return err
247+
}
248+
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
249+
244250
playSfx(path)
245251
return nil
246252
}
@@ -265,7 +271,7 @@ func playSfx(path string) error {
265271
// Use a Goroutine so keyboard shortcuts work during sound playback
266272
go func() error {
267273
mutex.Lock()
268-
streamer, format, err := decodeFile(path)
274+
streamer, _, err := decodeFile(path)
269275
if err != nil {
270276
// TODO: Bubble this error up somehow
271277
log.Println("Error decoding sound file:", err.Error)
@@ -275,12 +281,8 @@ func playSfx(path string) error {
275281

276282
log.Println("Playing " + path)
277283

278-
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
279-
280-
speaker.Lock()
281284
ctrl.Paused = true
282285
ctrl = &beep.Ctrl{Streamer: beep.Seq(streamer, beep.Callback(func() { done <- true })), Paused: false}
283-
speaker.Unlock()
284286
speaker.Play(ctrl)
285287
mutex.Unlock()
286288

screm.exe

-4.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)