Fix audio and music icons on Windows.
Using different audio libraries for Windows and Unix now, on Windows using gopxl/beep and on Linux gen2brain/malgo.master
parent
7eb1ad3bd2
commit
ce1881f349
@ -0,0 +1,77 @@
|
||||
//go:build linux || darwin
|
||||
// +build linux darwin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/gen2brain/malgo"
|
||||
"github.com/youpy/go-wav"
|
||||
)
|
||||
|
||||
func PlayWAVFile(filename string, stopPlaying *bool) error {
|
||||
file, err := os.Open(filename)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
w := wav.NewReader(file)
|
||||
f, err := w.Format()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reader := w
|
||||
channels := uint32(f.NumChannels)
|
||||
sampleRate := f.SampleRate
|
||||
|
||||
ctx, err := malgo.InitContext(nil, malgo.ContextConfig{}, func(message string) {
|
||||
fmt.Printf("LOG <%v>\n", message)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = ctx.Uninit()
|
||||
ctx.Free()
|
||||
}()
|
||||
|
||||
deviceConfig := malgo.DefaultDeviceConfig(malgo.Playback)
|
||||
deviceConfig.Playback.Format = malgo.FormatS16
|
||||
deviceConfig.Playback.Channels = channels
|
||||
deviceConfig.SampleRate = sampleRate
|
||||
deviceConfig.Alsa.NoMMap = 1
|
||||
|
||||
// This is the function that's used for sending more data to the device for playback.
|
||||
onSamples := func(pOutputSample, pInputSamples []byte, framecount uint32) {
|
||||
io.ReadFull(reader, pOutputSample)
|
||||
}
|
||||
|
||||
deviceCallbacks := malgo.DeviceCallbacks{
|
||||
Data: onSamples,
|
||||
}
|
||||
|
||||
device, err := malgo.InitDevice(ctx.Context, deviceConfig, deviceCallbacks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer device.Uninit()
|
||||
|
||||
err = device.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for device.IsStarted() {
|
||||
if *stopPlaying {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gopxl/beep"
|
||||
"github.com/gopxl/beep/speaker"
|
||||
"github.com/gopxl/beep/wav"
|
||||
)
|
||||
|
||||
func PlayWAVFile(filename string, stopPlaying *bool) error {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
streamer, format, err := wav.Decode(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer streamer.Close()
|
||||
|
||||
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
|
||||
|
||||
done := false
|
||||
callbackFunc := beep.Callback(func() {
|
||||
done = true
|
||||
})
|
||||
|
||||
speaker.Play(
|
||||
beep.Seq(streamer, callbackFunc),
|
||||
)
|
||||
|
||||
for done == false {
|
||||
if *stopPlaying {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 326 B |
@ -0,0 +1,37 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
// File generated by 2goarray v0.1.0 (http://github.com/cratonica/2goarray)
|
||||
|
||||
package darkmusicicon
|
||||
|
||||
var Data []byte = []byte{
|
||||
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x20, 0x20, 0x02, 0x00, 0x01, 0x00,
|
||||
0x01, 0x00, 0x30, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
|
||||
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03,
|
||||
0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x83,
|
||||
0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf3,
|
||||
0xff, 0xff, 0xff, 0xf3, 0xef, 0xff, 0xff, 0xf3, 0xcf, 0xff, 0xff, 0xf3,
|
||||
0xcf, 0xff, 0xff, 0xf3, 0x8f, 0xff, 0xff, 0xf3, 0x9f, 0xff, 0xff, 0xf0,
|
||||
0x3f, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff,
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 326 B |
@ -0,0 +1,37 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
// File generated by 2goarray v0.1.0 (http://github.com/cratonica/2goarray)
|
||||
|
||||
package lightmusicicon
|
||||
|
||||
var Data []byte = []byte{
|
||||
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x20, 0x20, 0x02, 0x00, 0x01, 0x00,
|
||||
0x01, 0x00, 0x30, 0x01, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x28, 0x00,
|
||||
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 0xff, 0x03,
|
||||
0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03,
|
||||
0xff, 0xff, 0xff, 0x83, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf3,
|
||||
0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf3, 0xef, 0xff, 0xff, 0xf3,
|
||||
0xcf, 0xff, 0xff, 0xf3, 0xcf, 0xff, 0xff, 0xf3, 0x8f, 0xff, 0xff, 0xf3,
|
||||
0x9f, 0xff, 0xff, 0xf0, 0x3f, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0x87, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03,
|
||||
0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x83,
|
||||
0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf3, 0xff, 0xff, 0xff, 0xf3,
|
||||
0xff, 0xff, 0xff, 0xf3, 0xef, 0xff, 0xff, 0xf3, 0xcf, 0xff, 0xff, 0xf3,
|
||||
0xcf, 0xff, 0xff, 0xf3, 0x8f, 0xff, 0xff, 0xf3, 0x9f, 0xff, 0xff, 0xf0,
|
||||
0x3f, 0xff, 0xff, 0xf0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff,
|
||||
}
|
||||
Loading…
Reference in New Issue