• entries
3
5
• views
3312

## Sound Engine Todo

I haven't gotten much done so far this weekend on the sound engine. I keep opening Visual Studio and realizing that I'm not sure what task to work on next, then I find myself watching some Air Gear, or ordering 600 bucks worth of guitar equipment.

In an attempt to reorganize myself to work on the sound engine, here's my todo list:

-Code for case when mod is not looping
-turn on DirectSound debugging to see if any resources are not released during testing
-ability to mute entire sound system
-ability to disable entire sound system
-test non-looping wav/mod/ogg.
-add optional callback at end of non-looping wav/mod/ogg
-test static wav/ogg (must use wav/ogg shorter than 3 seconds, otherwise it is automatically streamed)
-test playing more than one same wav/ogg at once (duplicate buffers)
-volume, pan, frequency get/set functions
-fade functions (volume/pan/freq set-functions over time) (see advanced section of dx9 documentation regarding optimization)
-Calculate current position in entire song. (harder than it seems, because dsound might loop the circular buffer back to the start before the next chunk of the song is rendered; essentially moving "backwards" in position). Will need to increment a total var everytime the buffer halve changes, then add current position to that. Reset var when sound restarts.
-Test various streaming buffer sizes
-Enumeration and selection of DirectSound devices

When the sound engine is complete, I was contemplating writing an article for gamedev.net, but I'm not sure yet. The existing article on Streaming Wave Files with DirectSound is old, but a lot of the info I would provide would be redundant. That, and I'm pretty lazy. I'll probalby just release the source. So far, the engine can play streaming/static wav, ogg, and various mod formats. As you can see from the todo list, there's still quite a bit of functionality to add though.

As for the guitar equipment, Raging Hermit has helped me pick out the following:

http://www.musiciansfriend.com/product/Guitar/Electric?sku=516643

http://www.musiciansfriend.com/product/Guitar/Amps?sku=480022

http://www.musiciansfriend.com/product/Guitar/Effects?sku=150846

## Things Falling Apart

You know you play too much WoW when...
I went to the bar downtown Columbus last night with a coworker friend. We were feelin pretty good by about midnight and the place started to get hoppin. A bunch of girls came in along with two guys. Friend says, "There's only two of em, we can take em". I said, "No way man, the girls might aggro". Hrmmm maybe you have to be drunk to find that funny? [smile]

Anyway, I get home to install my new Audigy 2 Zs card (been using a Live for ages). I install it, I have sound once again, life is good... That is, until I realize the network connection no longer works. I uninstalled the audigy card, and tried everything imaginable to try and get it back to the same state it was before the audigy card... still no go. Time to head to micro center for a lan card. /sigh

On a side note, I believe Nine Inch Nails tickets go on sale today for a concert in Columbus. I saw them in Detroit not too long ago. Awesome show, but it must be funny to see one preppy guy in the middle of thousands of goth. [smile]

I finally made the jump to GDNET+. I've been posting to my own site for a while now. If you want to see those posts, they're at http://www.illusivestudios.com/journal/index.php?finger=Nightshift.

The past month or so, i've been working on a sound/music engine for custom game engine using DirectX 9.

The sound engine works great in the main thread of an app, but I'd like to put the sound engine in it's own thread, so that window messages don't interfere with filling sound buffers. The problem is I'm not very good with multithreaded programming. Even though I've been programming since high school (96), I still haven't played much with threads (at least not in Windows).

Within the sound engine test app, I create a separate thread, in which all it does is check to see if all sound buffers need to be updated, and updates them if needed. (Yes, it polls.. I simply haven't gotten around to setting up notifications just yet).

The problem is that when stopping the buffer from within the main thread, DirectSound could potentially stop the buffer while it's being updated in the other thread, which makes things sound out of place if Play( ) is called again.

So I thought I could use the CRITICAL_SECTION related win32 functions, but when I press the key that calls Stop( ), sometimes it takes a good 5 seconds before the buffer actually stops playing.

I also tried writing my own "critical section" code.... so basically, in the Update and Stop functions, I do this...

// at start of both Update and Stop...while(g_bLocked);g_bLocked = TRUE; ...// at end of both Update and Stopg_bLocked = FALSE;

The problem with this is that when I call Stop, it gets stuck in the while loop and never actually stops the buffer. I think that because it's not getting back to the main message loop, the process never does a context switch to the other thread. (Again, it goes back to me not understanding threads).

Unless anyone can clue me in on what i'm doing wrong, I think how I'm gonna fix it is have a Queue object within the sound engine, and that's how it would determine what operations to perform next... so when I call Update in the thread, it will "Queue" a call to Update in the main thread. Calling Stop will also Queue up a stop event in the main thread, which will cause the sound engine to "wait" until the Update for that particular buffer is done.

The problem then becomes one of syncronizing reads and writes to the queue.

I'm not sure why the CRITICAL_SECTION related win32 functions would not work. Aren't these supposed to be pretty effecient? Makes me wonder how long the Updates are taking. I know the Updates are NOT taking 5 seconds tho [smile]

EDIT: I think I found out what I'm doing wrong with the CRITICAL_SECTION functions. I'm only calling InitializeCriticalSection once upon engine initialization, and calling DeleteCriticalSection once upon engine shutdown. Wups. Now I just need to get out of work, so I can go home and try it out.