Author Archives: pgfeldman

Standard programming mysteries.

I hate it when I’m starting off with an API and the tutorials don’t work.

I was working with the LWJGL OpenAl examples described in earlier posts, and could not get the audio files in the examples to open. The file was there, it could be converted to an InputStream, but when I tried creating a LWJGL WaveData object, the underlying java audio code would throw an error and I’d get a null object.

So since I’m now trying to figure out what gives with the javax.sound.sampled.* system, I might as well see if I can do what I want to do here. So off we go to the Internet once more, looking for examples that work.

The first thing I found was the Oracle Java Sound API documents, which are huge, loaded with theory and very little code. I’m not complaining really, because they look like they will be really useful when I have a little bit of code working. But there needs to be a “Hello, World”.

Which showed up after a bit of searching. There is a website JSResources, put together by two German (?) developers; Florian Bomers and Matthias Pfisterer. It is loaded with examples that seem to work. I’ve just gotten one of their simple examples running with a minimum of fuss. (Here’s the (slightly) modified code).  Since this is straight sound library, we know that we can run all the channels. Now we just need to get from here to there.

Multichannel sound

It was looking like Java3D only handled Mono and stereo, but I just found com.sun.j3d.audioengines.javasound .JavaSoundMixer, It also uses javax.media.j3d.PhysicalEnvironment, which looks like it has built-in head tracking.

Darn it – got my hopes up too soon: “While the sound image created for final output to the playback system is either only mono or stereo, most device driver implementations will mix the left and right image signals generated for each rendered sound source before outputting the final playback image. Each sound source will use N input channels of this internal mixer. Each implemented Java3D audio device driver will have its own limitations and driver-specific characteristics. These include channel availability and usage (during rendering). Methods for querying these device-driver specific characteristics are provided.” (from javax.media.j3d.AudioDevice)

OK, I’m not ready to give up on Java yet. According to this bug report, multichannel support has been working for a while. My two options at this point are OpenAl through the LWJGL folks, and the javax.sound.sampled library.

Because I’d like to show graphically where the sounds are coming from, I’m going to try the LWJGL approach first.

Looks like multichannel support is in OpenAl, but will require care: “The multi-channel extension provides a mechanism to play multi-channel data via OpenAL. A variety of formats are supported. Multi-channel buffers can be attached or queued on a source. Note that when using the “Generic Software” device, the multi-channel buffers are mixed down to a stereo output. On a hardware device (such as the “Generic Hardware” device or a native device), each channel of a buffer requires a hardware voice. So, for example playing a buffer using the AL_FORMAT_51CHN16 format will require 6 free hardware voices. If the hardware resources are unavailable, the call to alSourceQueueBuffers or alSourcei will fail.”


And then there’s Javascript….

It turns out that there is a good deal of work going on in bringing multichannel audio to your browser. Since this *is* the future, it’s not a thing that I want to overlook, but I don’t want to put all that much time into it right now either. So here are some links:

Now, where was I?

Not a good week for development.

The headgear is done, the divers are in, and I was ready to start doing a serious dive into the Java3D sound capabilities (as per Section 2 of the plan “Develop codebase for testing haptic rendering”). Then my father got sick and landed in the hospital for a week. Which kinda shot productivity to hell.

Anyway, I’m picking up the pieces. The (official) java3d.java.net site was down for most of yesterday, so I’ve only just connected to it again. So far I’ve downloaded and installed the AMD64 version of the jar files, hooked up my Eclipse IDE to the J3d-examples subversion repository (https://svn.java.net/svn/j3d-examples~svn).

The downloaded code compiles and runs as an ant file, but the structure doesn’t accommodate Eclipse’s code navigation for some reason. To fix this, I created a new Java project and copied the entire “resources” tree over and the tree that starts under “classes” in the original file. Here’s a screenshot:

J3D project layout

J3D project layout

This still didn’t compile though. I got an “Access restriction on class due to restriction on required library“, which I’ve never seen before. Poking around led me to StackOverflow, where there was this suggestion:

“go to java build path and under Library tab, remove JRE System Library. Then again Add Library –> JRE System Library”

Well, that makes no sense. It is just deleting and re-adding the system library. On the other hand, that’s exactly the kind of senseless thing that fixes weird errors, so I gave it a shot. Worked like a charm.

Anyway, now I’m having problems locating files that are right where the code says they are, but the loader’s can’t find them. Regardless, it’s time to go take care of Dad.

iRevolution?

So I have this project that might be a really interesting, though somewhat dark excursion into CSCW. I’m not quite sure what to do with it, but when I hear things like this on Morning Edition, I really wonder if I just shouldn’t figure out a way to go all in. The question is – is a solution that winds up with fewer people getting killed in a war always better?

And here’s something that matters for this: http://securityledger.com/mobile-phone-use-patterns-the-new-fingerprint/. This is the paper the article references: http://www.nature.com/srep/2013/130325/srep01376/fig_tab/srep01376_F1.html

A few more useful links:

Eight channels of sonic goodness

After a frustrating couple of days trying to get my Vantec USB Dolby 7.1 unit working, I gave up and sent it back to Amazon. Who, I must say, in their vast, impersonal way, really did a good job. The new replacement unit was on its way and arrived the day I sent the old unit back on their dime. Pretty impressive.

After letting the device sit in its box for a while as I worked up the energy to try something that I suspected would not work, I finally tried it this morning, and it works like a charm. Yay! Now I noticed something different, so it’s possible that the old unit worked fine.

When I plugged in the new controller, I happened to notice that there was a new icon in my system tray:

And what does this do?

And what does this do?

Clicking the icon brought up a tool that I hadn’t seen before:

2 Channel Config

2 Channel Config

Note that the System input seems to default to 2 CH, though 8 are available. More importantly, on the right side of the screen note that the “DSP Effect” seems to be getting 2CH data that it then sends to all the speakers. This was the behavior that I was getting that I couldn’t seem to fix.

Selecting “8 CH” in the combobox has the following effect:

8 channel configuration

8 channel configuration

After making that change, I clicked on each of the speaker icons in the lower right image and was rewarded by a synthetic voice coming out of the appropriate helmet speaker. Hooray!

Now this configuration tool must have been installed with the device, but it wasn’t mentioned anywhere in the documentation and didn’t pop up in the install procedure. It looks like you just have to know that it’s there. I guess that’s not surprizing, in that all these USB systems use the same chipset, made by C-Media, and they wrote the driver.

Anyway, I now have a functioning system. I need to play around with the best way to have the actuators contact the user’s head, but I think that’s the last remaining hardware task.

I’ve also finished getting the correct speaker lead to go to the correct amplifier, and cleaned up the wiring harness. Here’s a picture of the leads coming off the helmet:

The latest style in HCC

The latest style in HCC

I’m sure that no one would look twice at me walking down the street wearing that and four glowing amplifiers strapped to my back…

Done with wiring. Well, for now.

Today’s job was twofold – get all the speakers wired up and test everything as a unit, and if that works, get a cheap bike helmet to mount them all to.

8speakers

Eight Speakers and Blinky Lights

Testing was a breeze – it turns out that Windows has a nice control panel for configuring speakers:

SpeakerConfigAll I have to do is click on the speaker, which gives me a convenient tone. Otherwise, I’m not sure I ever would have been really sure as to which speaker was what.

Anyway, everything works. The next picture should be looking something like Rick Moranis  in Ghostbusters:

Early Proof-of-Concept

Early Proof-of-Concept

Ok, I’ve got the actuators mounted in the helmet and they work pretty well. The only problem is that the Dolby until is locked into stereo mode and I can’t seem to get it to think that it’s 7.1. Sigh. Guess that’s the problem for tomorrow…

wiredHelmet

John Carmack on Latency in Virtual Reality

For those who don’t know him, John Carmack II is one of the premier game programmers. He was a co-founder of id Software, which you may have heard of. Among his credits as lead programmer are Wolfenstein 3D, Doom, Quake, Rage and their sequels. And he’s the founder and lead engineer of Armadillo Aerospace.

In this article for #AltDevBlogADay, he discusses latency, one of the major problems in VR. Absolutely worth the read.