Crawling back to C++

Posted November 5, 2010

Today I recently started up C++ again. I wanted to implement FMOD in a game that Nocturnal Minds is working on.

I had learned C++ in the first programming courses I took. Initially I took the high school courses offered, then took the community college course after realizing the high school courses were crap. Me and my good friend Reid learned a lot at CGCC, but still did not move much further past basic operations and creating objects on the stack without really knowing the difference between stack and heap.

Although I had a vague idea of stack vs. heap and references and pointers from working in managed languages for the past 2 years (especially with C#), I was deathly afraid of memory management up until this past summer. I had to read and debug someone else’s microcontroller code that used pointer arithmetic, so that helped immensely.

Thus, working with FMOD was an opportunity to exercise my ability to use pointers. I managed to successfully write a function that takes a reference to an array of pointers (char **) and dynamically allocates it. The reason for it was I wanted to the designer API and fill an array of C-strings with the names of events and event parameters.

The API is actually really straightforward to use, although I can see what people mean when they say it requires more communication between programmer and sound designer/composer. I’ll have to think a while on how to properly make use of this. My solution with XNA and exact was to have an audio manager associate generic game events cue names, so a similar system might work here. It would just require a little more effort implement the audio manager and using whatever the standard library has available for hash tables.

My little test program just read in a .fev file and loaded the group at index 0, then listed all the events in it that could be triggered. From there you could then hit ‘e’, type in an event name, and hear the event play back. All in a console interface–ugly but functional.

I’m running into a weird issue in which a parameter to which I assigned a velocity and start and end values isn’t affecting the Event properly. It’s et up to crossfade between two sound definitions as the parameter moves forward over time (for simplicity’s sake, I called it ‘time’). From a cold start, it will sometimes start as 0, or already be at 1.5. Of course there’s probably some delay in reporting the value, but it will often not sound, or only play part of the sound. I’ll have to test this more later this weekend. For now, it’s time to write some music!