feat: full WSL2 audio support and Windows audio stability fix
This commit is contained in:
45
pkg/audio/global_linux.go
Normal file
45
pkg/audio/global_linux.go
Normal file
@@ -0,0 +1,45 @@
|
||||
//go:build linux
|
||||
|
||||
package audio
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/gordonklaus/portaudio"
|
||||
)
|
||||
|
||||
var (
|
||||
paMu sync.Mutex
|
||||
paRefCount int
|
||||
)
|
||||
|
||||
func initPortAudio() error {
|
||||
paMu.Lock()
|
||||
defer paMu.Unlock()
|
||||
|
||||
if paRefCount == 0 {
|
||||
if err := portaudio.Initialize(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices, err := portaudio.Devices()
|
||||
if err == nil {
|
||||
fmt.Fprintf(os.Stderr, "[Audio] Linux/PortAudio initialized globally. Devices found: %d\n", len(devices))
|
||||
}
|
||||
}
|
||||
paRefCount++
|
||||
return nil
|
||||
}
|
||||
|
||||
func terminatePortAudio() {
|
||||
paMu.Lock()
|
||||
defer paMu.Unlock()
|
||||
|
||||
paRefCount--
|
||||
if paRefCount == 0 {
|
||||
fmt.Fprintf(os.Stderr, "[Audio] Linux/PortAudio terminating globally...\n")
|
||||
portaudio.Terminate()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user