Skip to content
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

x/mobile/exp/audio: Windows support #15894

Open
EtienneBruines opened this issue May 30, 2016 · 12 comments
Open

x/mobile/exp/audio: Windows support #15894

EtienneBruines opened this issue May 30, 2016 · 12 comments
Labels
mobile Android, iOS, and x/mobile OS-Windows
Milestone

Comments

@EtienneBruines
Copy link

EtienneBruines commented May 30, 2016

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 and alc_notandroid.go file, and updating all build tags to include Windows):

#cgo darwin   CFLAGS:  -DGOOS_darwin
#cgo linux    CFLAGS:  -DGOOS_linux
#cgo windows  CFLAGS:  -DGOOS_windows -I E:/src/golang.org/x/mobile/exp/audio/al/include/
#cgo darwin         LDFLAGS: -framework OpenAL
#cgo linux          LDFLAGS: -lopenal
#cgo windows,386    LDFLAGS: E:/src/golang.org/x/mobile/exp/audio/al/bin/Win32/soft_oal.dll
#cgo windows,amd64  LDFLAGS: E:/src/golang.org/x/mobile/exp/audio/al/bin/Win64/soft_oal.dll

#ifdef GOOS_darwin
#include <stdlib.h>
#include <OpenAL/alc.h>
#endif

#ifdef GOOS_linux
#include <stdlib.h>
#include <AL/alc.h>
#endif

#ifdef GOOS_windows
#include <stdlib.h>
#include <AL/alc.h>
#endif

The caveats

  1. I have no idea how to replace E: by something like $GOPATH (since GOPATH == E:), maybe someone knows?
  2. Those bin and include 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.)
  3. If Go cannot redistribute those files (I dunno, could be the case), would there be any way to allow people to do this themselves? Without having to fork the al implementation? Or could we reference some kind of path and expect Windows-developers to put those files there?

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.

@hyangah hyangah added this to the Unreleased milestone Jun 2, 2016
@hajimehoshi
Copy link
Member

I have no idea how to replace E: by something like $GOPATH (since GOPATH == E:), maybe someone knows?

#cgo windows,386    LDFLAGS: ${SRCDIR}/bin/Win32/soft_oal.dll
#cgo windows,amd64  LDFLAGS: ${SRCDIR}/bin/Win64/soft_oal.dll

should work.

@nigeltao
Copy link
Contributor

nigeltao commented Nov 21, 2016

@rakyll @hyangah @crawshaw who should this issue be assigned to?

I have neither the spare time nor the Windows expertise to work on this myself.

@rakyll
Copy link
Contributor

rakyll commented Nov 21, 2016

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 gomobile init and can fallback to the system paths for non-gomobile users.

@faiface
Copy link

faiface commented Dec 31, 2016

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.

@faiface
Copy link

faiface commented Jan 9, 2017

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?

@rakyll
Copy link
Contributor

rakyll commented Jan 9, 2017

@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.

@faiface
Copy link

faiface commented Jan 9, 2017

@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.

@mattn
Copy link
Member

mattn commented Jan 10, 2017

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.

@rakyll
Copy link
Contributor

rakyll commented Jan 10, 2017

@mattn, you can revert https://go-review.googlesource.com/#/c/27671/ and test.

@mattn
Copy link
Member

mattn commented Jan 10, 2017

@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?

@rakyll
Copy link
Contributor

rakyll commented Jan 10, 2017

@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.

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
@ntop001
Copy link

ntop001 commented Dec 10, 2018

@mattn I don't think you solved the problem, you suppose the OpenAL SDK installed on Windows, so you can use it as #cgo windows LDFLAGS: -lopenal . I just tested the code, got an error:

# golang.org/x/mobile/exp/audio/al
..\golang.org\x\mobile\exp\audio\al\al_notandroid.go:30:19: fatal error: AL/al.h: No such file or directory
compilation terminated.

Windows don't have openal by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile OS-Windows
Projects
None yet
Development

No branches or pull requests

10 participants