Monday, February 15, 2010

Fun with Sound

I've been doing some more work on the sound subsystem, as there have been a few outstanding items with it. What I'm hoping that you will be able to do is:

  • Specify a sampling rate on the command-line using -sndspeed; 11, 11025, 22, 22050, 44, 44100, 48 and 48000 will all be supported values (the lower figures are just bumped up to the higher ones to let you use whichever method you prefer).
  • Change it at runtime using the s_khz cvar (name chosen because that's what Quake II uses) using the same values - this can happen even while a map is running.
  • Restart the sound subsystem at any time using the snd_restart command. May be useful if sound goes screwy on you. It will auto-restart if s_khz changes (this is a very fast operation).
  • Have a menu option for this too (possibly).
Most of this is actually up and running, or I wouldn't have posted, and I'm fairly happy that I'll get the remainder up and running soon enough too.

One thing that does happen is that - because sounds need memory allocated for them - we have a little extra overhead from the old discarded sounds until the map is either changed or reloaded. In practice it won't affect anything, but I do however think that I might change the memory handling for sounds to prevent this. I also want to change a few other things in relation to how DirectQ handles sounds in general, as the default ID implementation is now becoming quite clunky and awkward to work with.

Overall though I'm thinking that I'm going to put a good run at this one, as I'm overdue a decent batch of work, and this seems a nice cure for renderer burn-out.

7 comments:

Coranth said...

Hey...

When you start the game, have it 'default' to the best sample rate that sound hardware supports, maybe...

mhquake said...

Nah, 11k for compatibility with original ID Quake is required (the original Q1 sounds just sound really poor, shrill and thin at too high a rate).

Jeffrey said...

..That's for sure! I have experienced that 1at hand.

Coranth said...

Ack! I didn't know that! I thought that increasing the sample rate would up their quality; just make them sound a bit 'crisper'. *sigh* This is why you're the programmer and I'm the idiot...

mhquake said...

Actually thinking about it, and examining Quake's sound resampling code, reveals a possible solution to the problem (sound resampling in Quake is basically so wrong it's not even funny). Only trouble is that for every one person who is made happy by it, there will be another who preferred it done the wrong way! You can't win.

Coranth said...

Devil: Use the solution, MH! It's another optimization. Do it; you know you want to...

Angel: Whoa, now hold on, here; he said some people might not be happy with it, and that he couldn't win!

Devil: Pah, if you can't win, cheat! It's HIS Quake Engine; he can do what he wants; who cares about those poor slobs who don't like it! Do it, MH; you're tinkering with the sound code now, yes? Just slip it in, they'll never know...

Angel: *looks royally PISSED at Devil* Grrr! Cheating is bad, m'kay!

Devil: *bitch-slaps Angel*

mhquake said...

Very good, although I think in this case Devil is saying "leave it be".