And just like that, we have 3D working (not OpenGL) up and running. I found the math problems were just some incorrect calculations of which pixel to use in the texture. BTW, after looking at this code, it wouldn’t be hard to make texture rotate on the walls. … Hmmm…. I have a picture of Elymas’s lair where all the walls are blue and rotating in my head. That would be headache inducing. We’ll save that one for later.
But the above was the easy part. I can walk around and run through the level, kill elves, cast spells, and just generally play the game. But … there’s no sound.
Sound has always been a bit of weird spot for me. You see, I’m deaf in one ear. The technical term is Single Sided Deafness. Through a small birth defect, I have no ear canal on the left side. Everything else is normal, just no ear canal. Sort of like having an ear plug all the time. So, when I hear sound, it is (mostly) in the form of mono. This website does a good job of explaining the side effects of having SSD — both physically and (surprisingly) psychologically.
Making A&A pushed my ability to listen to sounds in stereo and in a game world. And I have always wondered if I went too far with the sounds (super stereo?), but I worked with the team to get it right along with constant flipping around of my head phones. Getting this right is still a priority in the Windows port, but should just be a matter of repeating what was done before, right? (For now, no Dobly 5.1 sound, I have a hard time even contemplating what that really sounds like)
I’ve already done some research into doing sound using SDL and it looks like you have to create your own mixer to combine all the different sounds. Hmm … that’s fairly limited, but that’s what I get for using the Simple DirectMedia Library. Alright, there has to be something out there for this already since I’m not the first game programmer to use the SDL. Fast forward and I’m looking at a library called the SDL_mixer (hey, simple name!). Looks good. Does .mp3 and .ogg files (tuck that away for later), plays samples of all types of formats (stereo, mono, 8-bit, 16-bit, etc.). Let’s use it … right? No. One of the key features A&A is its ability to make sounds appear on the left or right based on where it is on a level. Would you believe that the SDL_mixer allows you to change the volume of any stereo/mono audio sample, but ONLY on both left and right. I can’t pan the sound from left to right! There doesn’t even appear to be separate volume control for left/right. What? Looks like I get to make my own. Oh well, it’ll be more what I need.
So how do we make a audio mixer? Through the years, I’ve always have asked, how do you mix 32 sounds and not make it all sound like trash as the waveforms get louder and louder with all the noise. Mathematically, the noise will start to clip as you “spill” over edges of the digital sample range. So, I have always figured there had to be some fancy algorithm for combining sounds without causing the playing of 8 sounds of silence and 1 sound of music to cause the music to drop to 1/8 the volume. The answer is … no … there isn’t one … you just add. If there is no sound, you add nothing. If there are 2 loud sounds, they add, and you clip. This would explain why in A&A when a ton of fireballs hit at the same time, you start getting a kind of ‘crackle’ sound in the original HMI sound drivers. Over time, I came to like that ‘crackle’ sound effect, so we’ll do the same. Mix by adding, clip the sound range. Luckily, not all sounds play at 100% volume, so if you got two sounds at 50%, then they can add with no penalty. Soft sounds are almost free (10 sounds at 10% max volume). But when the loud action gets going, look out! Strangely, I’ve been doing some video and sound playback at my day job lately that is similar to this.
Enough talk, more action! Off I go to make me a sound mixer…. with stereo panning capabilities.
I thought sdl mixer did let you set panning… the documentation suggests it does (http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_80.html#SEC80), and there even seems to be rudimentary positional audio (http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_82.html#SEC82).
Doh! Alright, you are correct. There it is in plain sight. I think I thought that setting should be in 4.3 Channels. Thanks for the correction.