Category Archives: Graphics APIs

Boring progress. But hey! Progress :-)

Today’s work. Just solid satisfying programming, though I am playing fast and loose with pointers because of headaches getting const to behave properly.

  • Working on getting multi buffer support. Done! Also got repeating sound working.
  • Going to put a basic Audio class together to manage SampleSounds.
  • Done. BasicAudio (awesome name, huh?) is pretty wrapped up. Once all this is clean and commented, I’ll post the files.
  • Start on 3D/multichannel tomorrow?

Approaching understanding

Today was a good day of slow progress! Here’s the play by play.

  • Building a copy of XAudio2BasicSound, cleverly calling it ConsoleSound2.
  • Since it depends on SDKwavefile, I had to pull SAFE_DELETE, SAFE_DELETE_ARRAY, and SAFE_RELEASE from dxut.h. It also requires dxerr.h. but that’s in the regular directx include directory.
  • Extremely empty code right now, but it compiles and links. On a side note, the compiler should accept the environment variable $(DXSDK_DIR), but it doesn’t. And adding macros is an enormous pain, as near as I can tell.
  • The code is ported over and works. It’s all stuck in a main() right now. I need to clean up and build an Audio class. Actually, looking at the way the code is set up, a WavSampleSound class might be better. It probably could extend from a SampleSound class, but I’ll break that out later…
  • Class is mostly done and running!
  •  ConsoleSound2
  • The only bug that I have is that I can run the sound only once. I still need to figure out how to reload the buffer.

3D sound compiled and running, if not understood all that well…

Today’s twists and turns:

  • More Audio3d.
  • Starting to add in the 3dAudio based on this and this and this.
  • Got an audio link error and chased that down, discovering a few things along the way.
  • There is directX help for C++ in (“C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Documentation\DirectX9\directx_sdk.chm”). I don’t know it it’s any good, but I’m going to look though it next. Note that this is DX9, not 11. I’m *hoping* that this is all up to date…
  • Pointed Configuration Properties->Linker->General->Additional Library Directories at (C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86), and added the following files to Configuration Properties->Linker->Input->additional dependencies”
    • d3d11.lib
      d3dx11.lib
      winmm.lib
      xinput.lib
      X3DAudio.lib
    • This is a change from the libraries that the demo book points at, which were dxd9 libs. Recompiled and ran the code with no problems. I did attempt to clean up the xact3dInstance pointer in ~Audio3d(), but delete[] threw an exception
  • Reading through the DX documentation, which, though it is in the DX9 folder, contains information about DX11. Whatever.
  • The documentation is kind of what you’d expect, but it let me find the tutorials and demos, which are quite nice. On my machine, the demos that I’m interested in are located here: (C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\C++\XAudio2). It contains 4 projects:
    • XAudio2BasicSound
    • XAudioBasicStream
    • XAudio2CustomAPO
    • XAudio2Sound3D
  • Each project has source and MSVC2008 and MSVC2010 project files. I’ve just opened up the XAudio2Sound3D MSVC2010 project, and it compiled and ran just fine: XAudio2demo
  • This is almost exactly what I intend to build for the test environment, so that’s pretty cool. And using the buttons or the keyboard, I can drive the sound emitter around my head. Woohoo!
  • Next goal is to build up a copy of XAudio2BasicSound and then add the 3D components (without the graphics) from XAudio2Sound3D.

One of those days when work interfered with school

Only a couple of hours worked today – someone decided that today would be a good day to discuss server security, and I had a nice lunch consulting (kibitzing?) with Greg, an old buddy of mine about his new company/product.

  • Work on Audio3d class
  • It appears that you *have* to include <xact3.h> before <xact3d3.h>. It seems to be tied up with <x3daudio.h>, which is declared before <xact3.h> in <xact3d3.h>. If I reverse the order of those calls, no error messages. otherwise I get the following (included for the next poor soul who pastes this error in Google):
    • 1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361): error C2146: syntax error : missing ';' before identifier 'ContextRecord'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(6361): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12983): error C2065: 'PCONTEXT' : undeclared identifier
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2146: syntax error : missing ')' before identifier 'ContextRecord'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): warning C4229: anachronism used : modifiers on data are ignored
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2182: 'RtlCaptureContext' : illegal use of type 'void'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2491: 'RtlCaptureContext' : definition of dllimport data not allowed
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(12984): error C2059: syntax error : ')'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13372): error C2143: syntax error : missing ';' before '__stdcall'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13372): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13376): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(14982): error C3861: '__readfsdword': identifier not found
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C2146: syntax error : missing ';' before identifier 'LPCONTEXT'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C2378: 'PCONTEXT' : redefinition; symbol cannot be overloaded with a typedef
      1>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(13372) : see declaration of 'PCONTEXT'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(1048): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(3610): error C2061: syntax error : identifier 'PCONTEXT'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(4449): error C2061: syntax error : identifier 'LPCONTEXT'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(4457): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(4457): error C2143: syntax error : missing ',' before '*'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(15112): error C2143: syntax error : missing ';' before '__stdcall'
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(15112): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
      1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winbase.h(15116): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
  • This truly is one of the reasons the Microsoft drives me so crazy…

3D sound and the search for a header file.

Today, I was going to extend the audio app to do some simple 3D sound. Nope. Aside from a lot of distractions that really only allowed me to get a couple of hours work done, the C++ documentation for this capability is getting harder and harder to find. And for some reason, Microsoft does not seem to believe in producing samples of code that actually do something. Instead, there are lots of nested pages, each pointing to a tidbit of information. Sigh. Anyway, here’s today’s struggles.

  • I thought this tutorial would be the best way to get positional information, but it appears to be stale. The New Way seems to be this.
  • Close, but it’s actually part of the Windows API now?
  • Nope that’s C#. Still looking. Since I have xact3.h working, trying to stay in this space…
  • Ok, at least for now (and yet again!) I think I know what’s going on and what I should do next. For tomorrow, I start writing a 3D version of Audio.h/Audio.cpp and then try calling that from the ConsoleSoundApp.

A much better day…

Today’s stuff.

  • Imported the sound example code from P2DG chapter 7 into MSVC and successfully compiled.
  • And runs! With sound!
  •  withSound
  • Next we try to put the audio class into a console app (main as opposed to winmain) and see if that can be made to work.
  • That went pretty smoothly. I had to add the DirectX “include” directories, add stdafx.h to the audio.cpp file and cast some char* to LPWSTR. The next step is to fill out the main() so that the audio is initialized and then run a loop to send different audio commands. A good task for Monday.

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:

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.