-
Notifications
You must be signed in to change notification settings - Fork 18k
x/mobile/exp/audio: Windows support #15894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
#cgo windows,386 LDFLAGS: ${SRCDIR}/bin/Win32/soft_oal.dll
#cgo windows,amd64 LDFLAGS: ${SRCDIR}/bin/Win64/soft_oal.dll should work. |
Maybe we need to distribute prebuilt dlls, as well as Linux so files, in the openal package downloaded during gomobile init, see https://github.com/golang/mobile/blob/master/cmd/gomobile/init.go#L300 Then, al package practically won't have any external dependencies if you have run |
Is there any chance this problem will ever be resolved? Would be quite helpful. I'd like to help solve it, but I lack the technical experience with OpenAL and I don't have a Windows machine. |
How about including OpenAL sources inside the package and compiling them with it, just like https://github.com/go-gl/glfw does it with GLFW? This way, we would get rid of external DLL dependencies. Or would that be against licence? |
@faiface, we can distribute the library ala how we do it for Android already in the OpenAL archive: https://github.com/golang/mobile/blob/master/cmd/gomobile/init.go#L300. |
@rakyll Well, if you can distribute it like that, then what's the problem with including it's sources directly with the x/mobile/exp/audio package? This way, OpenAL gets statically linked with this package and there are no external dependencies or downloading. Actually, I don't like the idea of downloading OpenAL every time I run my program at all. Am I missing anything? Edit: ok, I see, that it's not downloading every time I run my program, but with desktop, that would not be as easy. |
diff --git a/exp/audio/al/al.go b/exp/audio/al/al.go
index 342d881..bb7bf84 100644
--- a/exp/audio/al/al.go
+++ b/exp/audio/al/al.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin linux
+// +build darwin linux windows
// Package al provides OpenAL Soft bindings for Go.
//
diff --git a/exp/audio/al/al_notandroid.go b/exp/audio/al/al_notandroid.go
index 8d8b745..b3c9518 100644
--- a/exp/audio/al/al_notandroid.go
+++ b/exp/audio/al/al_notandroid.go
@@ -2,15 +2,17 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin linux,!android
+// +build darwin linux windows,!android
package al
/*
#cgo darwin CFLAGS: -DGOOS_darwin
#cgo linux CFLAGS: -DGOOS_linux
+#cgo windows CFLAGS: -DGOOS_windows
#cgo darwin LDFLAGS: -framework OpenAL
#cgo linux LDFLAGS: -lopenal
+#cgo windows LDFLAGS: -lopenal
#ifdef GOOS_darwin
#include <stdlib.h>
@@ -21,6 +23,11 @@ package al
#include <stdlib.h>
#include <AL/al.h> // install on Ubuntu with: sudo apt-get install libopenal-dev
#endif
+
+#ifdef GOOS_windows
+#include <stdlib.h>
+#include <AL/al.h>
+#endif
*/
import "C"
import "unsafe"
diff --git a/exp/audio/al/alc.go b/exp/audio/al/alc.go
index 2c8137d..e70594c 100644
--- a/exp/audio/al/alc.go
+++ b/exp/audio/al/alc.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin linux
+// +build darwin linux windows
package al
diff --git a/exp/audio/al/alc_notandroid.go b/exp/audio/al/alc_notandroid.go
index ff7c59b..c2cbfd9 100644
--- a/exp/audio/al/alc_notandroid.go
+++ b/exp/audio/al/alc_notandroid.go
@@ -2,15 +2,17 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin linux,!android
+// +build darwin linux windows,!android
package al
/*
#cgo darwin CFLAGS: -DGOOS_darwin
#cgo linux CFLAGS: -DGOOS_linux
+#cgo windows CFLAGS: -DGOOS_windows
#cgo darwin LDFLAGS: -framework OpenAL
#cgo linux LDFLAGS: -lopenal
+#cgo windows LDFLAGS: -lopenal
#ifdef GOOS_darwin
#include <stdlib.h>
@@ -21,6 +23,11 @@ package al
#include <stdlib.h>
#include <AL/alc.h>
#endif
+
+#ifdef GOOS_windows
+#include <stdlib.h>
+#include <AL/alc.h>
+#endif
*/
import "C"
import "unsafe"
diff --git a/exp/audio/al/const.go b/exp/audio/al/const.go
index 8c2fc2f..c8a1cdc 100644
--- a/exp/audio/al/const.go
+++ b/exp/audio/al/const.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build darwin linux
+// +build darwin linux windows
package al
I could build with this patch. But no examples try to use. |
@mattn, you can revert https://go-review.googlesource.com/#/c/27671/ and test. |
@rakyll It works with following code on my Windows. package main
import (
"log"
"time"
"golang.org/x/mobile/asset"
"golang.org/x/mobile/exp/audio"
)
func main() {
rc, err := asset.Open("boing.wav")
if err != nil {
log.Fatal(err)
}
player, err := audio.NewPlayer(rc, 0, 0)
if err != nil {
log.Fatal(err)
}
defer player.Close()
player.Seek(0)
player.Play()
time.Sleep(time.Second)
} What is motivation of https://go-review.googlesource.com/#/c/27671/ ? Compatibility for the OSs? |
@mattn, The player needs to use a ring buffer whereas it is buffering the audio resource entirely to the memory. I have no bandwidth to improve it, hence I reverted it. |
@mattn I don't think you solved the problem, you suppose the OpenAL SDK installed on Windows, so you can use it as
Windows don't have openal by default. |
The problem
The current al implementation does not allow for Windows builds. A while ago I posted this on the forums.
The fix
This feels a bit hacky, but I managed to update the C-import stuff to this (on both the
al_notandroid.go
andalc_notandroid.go
file, and updating all build tags to include Windows):The caveats
E:
by something like$GOPATH
(sinceGOPATH == E:
), maybe someone knows?bin
andinclude
directories that are expected to be within the directory, are those from the binaries from https://github.com/kcat/openal-soft . Not sure if we can safely redistribute those? (licensing etc.)I don't need any attribution, therefore there's no PR associated, but it would be nice to let this "fix" be part of Go, instead of having to fork it.
The text was updated successfully, but these errors were encountered: