Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (731)
Games in Android Showcase (217)
games submitted by our members
Games in WIP (799)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  GWT-AL - OpenAL implementation for the GWT platform  (Read 5541 times)
0 Members and 1 Guest are viewing this topic.
Offline SHC
« Posted 2016-03-06 17:41:16 »



An OpenAL implementation based on WebAudio API for GWT. Currently supports loading buffers and playing sources as well as setting properties like position, velocity, gain, pitch etc., allowing to easily port OpenAL applications to the Web platform using GWT.

Design


The design is to conform to the OpenAL 1.1 Specification and the API is to be compatible with the OpenAL bindings API of the LWJGL project. The implementation is based on the WebAudio API bindings written internal to this library (but are also exposed). The developer is free to use either OpenAL or WebAudio API with this library.

Installation


The only way to install for now is to clone the repo and build it manually. I will release the JAR and in maven central once the library is out of alpha and all the remaining OpenAL API has been implemented.

1  
./gradlew clean build javadoc

That should create a JAR file called as gwt-al.jar which you should add to the classpath of your GWT project. Now inherit the GWT-AL library in your module.

1  
<inherits name='com.shc.gwtal.client'/>

That should make you able to use the OpenAL API as well as the WebAudio API bindings in the module which inherits GWT-AL. You can now proceed to write your audio application.

Context Creation


The initial step is to create a context that can be used as a handle to the audio. Note that this throws a
AudioContextException
which is a checked exception and must be caught by the developer when creating the context.

1  
2  
3  
4  
5  
6  
7  
8  
try
{
    AudioContext context = AudioContext.create();
}
catch (AudioContextException e)
{
    e.printStackTrace();
}

The OpenAL context creation is different, and you need to make the context current, so as to conform to the API. It will throw the
AudioContextException
too.

1  
2  
3  
4  
5  
6  
7  
8  
9  
try
{
    ALContext context = ALContext.create();
    AL.setCurrentContext(context);
}
catch (AudioContextException e)
{
    e.printStackTrace();
}

Why this occurs is that whenever you create an
ALContext
instance, an
AudioContext
object is created too, because the OpenAL implementation uses the underlying AudioContext to play the actual audio. If that creation is failed, then the exception is thrown, so OpenAL is also not possible on browsers that don't support WebAudio API.

Links


The project is still in the alpha and doesn't even contain the complete implementation. However it does support everything that a normal user needs (except that it's missing features like doppler shift and streaming sources).


GitHub Repository | Online Examples | Examples (Source)


If you would like to be a tester, and have an intermediate knowledge in OpenAL, please contact me. If you had any issues, please report them to me either in this thread, or through PMs, or even on GitHub issues.

Offline SHC
« Reply #1 - Posted 2016-03-27 07:55:17 »

GWT-AL snapshots are now available through OSSRH repositories.

Maven

1  
2  
3  
4  
5  
<dependency>
    <groupId>com.goharsha</groupId>
    <artifactId>gwt-al</artifactId>
    <version>0.1-SNAPSHOT</version>
</dependency>

Gradle

1  
compile 'com.goharsha:gwt-al:0.1-SNAPSHOT'

Make sure that you have maven repository https://oss.sonatype.org/content/repositories/snapshots/ present in your search path and this will work. The builds will be uploaded for every commit on the master branch.

Offline SHC
« Reply #2 - Posted 2016-06-20 15:54:38 »

GWT-AL is now version 0.2-SNAPSHOT. The main change is that the older version will not work anymore due to the recent deprecations to some nodes in the Web Audio API and Chrome is issuing warnings in the console.

The new version have fixed that issue, and also implemented doppler shift on the sources. Additionally a number of old bugs are fixed. In case you are using the older version, change it immediately and if you have any code already compiled, you'd have to recompile it. There is no change in the public API.

Maven

1  
2  
3  
4  
5  
<dependency>
    <groupId>com.goharsha</groupId>
    <artifactId>gwt-al</artifactId>
    <version>0.2-SNAPSHOT</version>
</dependency>

Gradle

1  
compile 'com.goharsha:gwt-al:0.2-SNAPSHOT'

All the users are requested to update to the new version as soon as possible.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ranger
« Reply #3 - Posted 2016-10-03 05:46:12 »

Hi SHC,

Just playing around with your library.  The Web Audio API example works perfectly, however, the Open AL example only comes through the right speaker.

Any ideas?  I'm using Chrome on Windows 10.

Thanks.

EDIT:  Looks like it's only Chrome that the sound comes out only through the right speaker.  Firefox works with both speakers, while IE and Edge don't work at all.  You can see it happening in http://drift.team/, just click on the "Sounds" button.  Do you know if these browsers should be working with GWT-AL?
Offline SHC
« Reply #4 - Posted 2016-10-04 14:44:48 »

I have seen your post, but sorry for the late reply, it is festival time here, and my semester examinations are also approaching at the same time. I did saw the same issue, and it really seems like a bug in the WebAudio API implementations of Chrome and Firefox. I find that there are small differences between the versions of the specifications used by these two browsers.

Right now, it appears that Chrome implementing the latest draft specification, which Firefox is with an older spec, and that both browsers has the same amount of bugs in some areas. IMO Edge has a better implementation than these major browsers, but unfortunately Edge does not support OGG file format.

My latest commit (e6d9eb9) tries to fix the issue on Chrome by disconnecting the sound's panner nodes once the playback is done, and this seems to have some effect at least. As a test, you can try my Lost-Orion game and check it's audio. It fixes the issue in Chrome as per my ears, but there are still issues in FF.

The major issue I find in Firefox is with sound sources that move while the source is still playing. When this happens, Chrome handles this perfectly smooth, but in FF I'm seeing some small pauses while the position of the node is being changed. I'm still looking for a solution to this.

Offline Ranger
« Reply #5 - Posted 2016-10-05 03:15:57 »

Thanks SHC.  It appears your Lost-Orion game has the same problem as I am having (sound only comes out of the right speaker in Chrome).

I'll look into doing direct JS calls to the Web Audio API, to see if I can work out what is going on.

Cheers.
Offline Ranger
« Reply #6 - Posted 2016-10-09 05:25:04 »

Update:  I created a bare bones AudioContext, I didn't do anything fancy like in your AudioContext.java when you decodeAudioData, you do some sort of slicing, instead I just passed the ArrayBuffer straight into the decodeAudioData.  Basically, I implemented https://www.html5rocks.com/en/tutorials/webaudio/intro/ in GWT.

I also called createStereoPanner, and I could move my sounds between the speakers.

However, when I called createOscillator, the sound from that only came out the right speaker, and completely ignored my connected Stereo Panner.
Offline SHC
« Reply #7 - Posted 2016-10-09 06:37:22 »

@Ranger

There is a reason why I do slicing the buffer audio data. It is because Firefox doesn't copy the data into the buffer, but it uses the same buffer. It does also modify the contents. For example, I got a buffer, and if I create two source nodes with that buffer, then it will not play the second node. Only the first node can be heard.

Did you test it with both Chrome and Firefox? Last time I tried, Chrome throw'ed me an error when I created SterioPannerNode. All the code in GWT-AL is using PannerNode instead of SterioPannerNode.

GWT-AL does not use the OscillatorNode, so am not actually sure where the bug is coming from. Maybe I have to check again and replace PannerNode with SterioPannerNode. Will check this and reply back soon.

Offline Ranger
« Reply #8 - Posted 2016-10-09 08:27:06 »

Firefox seems to work fine.  Although the looping of a sound is a little glitchy.  There is no problem with playing multiple sounds at the same time.  I just deployed a new version, so you can hear it running with direct calls to AudioContext, and coming through both speakers http://drift.team/.

I think Chrome has a bug in it with the OscillatorNode, as other people's examples also only come through the right speaker.  Eg: http://www.javascripture.com/OscillatorNode Edit: I was wrong, Chrome works fine.

Also, AudioContext seems to work fine on Android, but I haven't been able to get it to work on an iPhone.

Cheers.
Offline Ranger
« Reply #9 - Posted 2016-10-20 22:51:07 »

I've been trying to get sounds working in Chrome on the iPhone.  First it was failing with the XMLHttpRequest, so I wrote a method that converted the DataResource to a ArrayBuffer without using XMLHttpRequest (as the DataResource was already loaded by GWT):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
/**
 * Convert a base64 URL into an array buffer.  Ref: http://stackoverflow.com/questions/21797299
 */

private static native ArrayBuffer arrayBufferFromBase64Url(String base64Url) /*-{
   var base64Value = base64Url.split(',')[1];
   var binaryStr = $wnd.atob(base64Value);
   var len = binaryStr.length;
   var bytes = new Uint8Array(len);

   for (var i=0; i<len; i++) {
      bytes[i] = binaryStr.charCodeAt(i);
   }

   return bytes.buffer;
}-*/
;

/**
 * Create the sound Array Buffer from the data resource.
 */

public static ArrayBuffer createSoundArrayBuffer(DataResource soundData) {
   String url = soundData.getSafeUri().asString();

   return arrayBufferFromBase64Url(url);
}


However, now it hangs on the decodeAudioData call.  It doesn't seem to call the success or failed function:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
public class AudioContext extends JavaScriptObject {
   public native final void decodeAudioData(ArrayBuffer audioData, Loaded<AudioBuffer> success, Loaded<String> failed) /*-{
      this.decodeAudioData(
         audioData,
         function (decodedData) {
            success.@team.drift.client.common.model.Loaded::data(*)(decodedData);
         },
         function (e) {
            failed.@team.drift.client.common.model.Loaded::data(*)(e.err);
         }
      );
   }-*/
;
}


It works fine in Chrome on PC, Mac, and Android.  Just the iPhone is failing.  Any ideas would be great!

EDIT:  Finally got it working on iPhone.  Turns out, iPhone does not support OGG files.  Angry  Switching to MP3 made the sounds work.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #10 - Posted 2016-11-02 16:02:30 »

@Ranger

Sorry for being so late to reply, was having my end semester exams, and I have to study hard to keep my grades. Anyways, I don't think you are using panner at all, you seem to not needing the 3D sound right? My observation is that this issue appears only when we needed panning and had a panner node created.

This might be with the panning models, I will revisit the specification soon and will try to find out the problem.

Offline Ranger
« Reply #11 - Posted 2016-11-05 00:30:04 »

No problem at all.  Good luck with your exams!

Yes, you are correct, I don't need a panner or any 3D sound.

I'm finding out that there is a lot of stuff happening in the background.  Eg:  GWT converts DataResources into inline data URLs if the sound byte is small enough (around 50K), so, when you call getSafeUri(), you will either get a base64 data url, or an http url, depending on the size.  Then, the XMLHttpRequest request will fail on the iPhone if it is a base64 data url, however, if it is a http url, then you need the XMLHttpRequest call.

So, the code I posted above will only work on small sound bytes that have been converted to base64 data urls.

Right now, I have all my sound effects small enough so they all get converted into base64 urls, and have written my own hooks into JS to play them, setting their volume, pitch, etc.  And for the music, I'm using GWTs default Audio.createIfSupported().  I noticed there was a bug in that code when listening for the end of a music track, so I wrote a new JS method:

1  
2  
3  
4  
5  
private static native final void listenForEnd(AudioElement aud, Command onComplete) /*-{
   aud.onended = function() {
      onComplete.@com.google.gwt.user.client.Command::execute(*)();
   };
}-*/
;


Anyway, I seem to have everything now working on all supported platforms.  Let me know if you have any problems with your framework, maybe I can help out.

Cheers.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
Archive (341 views)
2017-04-27 17:45:51

buddyBro (538 views)
2017-04-05 03:38:00

CopyableCougar4 (988 views)
2017-03-24 15:39:42

theagentd (1020 views)
2017-03-24 15:32:08

Rule (995 views)
2017-03-19 12:43:22

Rule (978 views)
2017-03-19 12:42:17

Rule (975 views)
2017-03-19 12:36:21

theagentd (1077 views)
2017-03-16 05:07:07

theagentd (997 views)
2017-03-15 22:37:06

theagentd (771 views)
2017-03-15 22:32:18
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!