simple machines forum

Please login or register.

Login with username, password and session length


Remember to make your own backup of posts before submitting.


Author Topic: Sound/BGM work/news  (Read 195 times)

Holy Diver

  • Website System
  • Administrator
  • *****
  • Offline Offline
    • MaleView Profile
    • About/Support Me/Sword of Moonlight
look out honey, 'cause I'm using technology
Holy Diver says,
« on: September 05, 2020, 09:07:41 PM »

Lately I've been working with sound and music parts of SOM, so I thought there's enough to share to make a thread/topic about it.

I will try to remember what I can today, in no particular order, but I expect to be adding more posts to this write-up in the coming days.

Today I did two interesting things. First, lately I've been trying to understand the DirectSound parameters to improve the sound presentation. I ultimately reverted back to almost the same values that SOM uses. The main problem I ran into is sound dropping out at a distance. What I concluded is that DirectSound can't help with that, and so I've added 10 extra meters to SOM's sound distance, and I use the extra space to manually fade out the sounds, so they don't drop out. You can think of it like how the character models fade in. It's not based on how sound works, but it's just a smooth transition so sound never just blanks out of existence.

DirectSound wants to work like real sound I guess. So our game worlds are much more clipped than the real world, so we just have to accept that they fade out on the edge, just like video game fog. That's the best way really. So I consider this an improvement.

A while back I added a masterVol value to the game config INI file. Today I changed it from using 16 values to 255 like the other volume settings. You can't actually control the full range in the game. I noticed the distinction since I was switching the volume controls over to using a new logarithmic mapping that solves the problem with the volume. While I was searching for information about DirectSound online (good luck with that) I happened across the following discussion.

It gave me the clear idea that there was a "scientific" approach to solving this problem.

What this change means is the volume dials are well behaved and cover the full range of what makes sense. DirectSound's volume isn't linear, and I think that's why only the first few settings are usable, and no other reason.

The masterVol setting actually controls a separate volume knob that SOM doesn't use. It's like the volume on your headphones. It may have different results from how SOM changes the sound effects volume, since it changes the volume of the sound sources individually. And I wish that practice could be dispensed with, however DirectSound really doesn't provide another way to control the sound effects and BGM volume independently, so I guess this is the only way. If it turns out using the masterVol provides superior sound then I could work to put the BGM on a different DirectSound instance. I think maybe the physics of pseudo-sound (inverse square law) may be invariant to how you choose to change the volume.

I've introduced two powerful extensions to the [Sample] section of the Ex.ini file. These are called sample_pitch_adjustment and sample_volume_adjustment, and I've used them extensively with my KF2 project. The pitch extension can use SOM's pitch values that I think are based on PlayStation notes, in its MIDI system or frequencies, which DirectSound uses natively. Values larger than 127 are interpreted as frequencies. SOM's note range is very small compared to the PlayStation, sometime I may try to extend it, but it's limited to -24 to 20. It's relative to the sound's sample rate, whereas frequency is absolute.

I've tried different things with the sample_volume_adjustment extension, but have settled on it using negative decibels that have the volume levels subtracted from them. Working with negative values can sometimes be confusing, but it makes the most sense. Really setting the volume is more like muffling the sound since it can't be amplified unless it was already muffled. It can't go higher than the volume in the sound file, similar to how textures normally limit the brightness or color of 3D models under lighting conditions.

Code: [Select]

π = 3.141593

;these override SOM_SYS
_WALK = 1.5
_DASH = 4.5
_TURN = π/2

;SOM's footstep sound (need to find a
;better sound)
se_volume[30] = 1_*2-6

;weapon sounds
se_volume[501] = -12
;dying, falling
se_pitch[504] = -12 -15
;todo: velocity has better resolution
se_volume[505] = -25+2.5*c[Fall]
;scraping door (frequency)
se_pitch[507] = 22050/11.5
;menu failure, enter, cancel, scroll
se_pitch[1008] = 6 -4 -7 4
se_volume[1008] = -12 -5 -5 -15

sample_pitch_adjustment = nan(se_pitch[1_],2_)
sample_volume_adjustment = 2_+nan(se_volume[1_](2_),0)

I've added the ability to use WAV files instead of SND files. I'd like to add support for any sound files, like for BGM, but I have to figure out a reasonable system for scanning for the files. With the BGM you have a particular file name, but with the sound effects there's just a number. SOM can support standard PCM WAV files of any sample rate I think, and it handles the sample rate intelligently, but SOM_SYS seems to not want to play the files in its sound effects menu. I have to take a look at it sometime. I suspect it's locked into the sample rate SOM's SND files use. It uses DirectSound to play them though. It's probably just hard-coded. Luckily som_db.exe is more flexible. KF2 uses sounds that are double the SND sample rate, that I think is one quarter of the CD music sample rate.

I've added environment acoustics to emulate the PlayStation's reverb effect that KF2 uses. Right now I've made it to always use the "room" preset, that's probably not appropriate, but is modest. I've done some experimenting, but only Alt+Alt+X can be used to test different presets and turn the reverb on and off, or hear just the reverb.

EDITED: This requires "do_reverb" to enable it. It's still experimental really.

Code: [Select]
static const char *i3dl2[] =
//"studio", //i.e. soundproof (how to communicate this??)
"no fx",
    "padded cell",
    "living room",
    "stone room",
    "concert hall",
    "carpeted hallway",
    "stone corridor",
    "parking lot",
    "sewer pipe",
    "underwater", //(23)
//note: these are said to be "'musical'" and so may not be
//appropriate (a "room" and "hall" mean performance areas)
    "'small room'", //"approximately 5 meter room"
    "'large room'", //"approximately 10 meter room"
    "'large room'", //"A large size room suitable for live performances"
    "'medium hall'", //A medium size concert hall
    "'large hall'", //A large size concert hall suitable for a full orchestra
    "'plate reverb'" //A plate reverb simulation (29)

I'm planning to work on a system to assign arbitrary values to the tilescells in SOM_MAP. I'm going to use that to add KF2's lighting variations to my project, but also I think it will be useful to control the monster AI since it seems KF2 encodes monster territories separate for its flying and swimming and terrestrial monsters. I think the light levels are linked to the territories of the terrestrial monsters. I'm going to encode this data in an image file that can be edited with SOM_MAP, and I intend to use it to manage acoustic changes.

Strikeout: Not the PRT files/tiles ("parts") but to the cells you assign them to. Of course that's what you do with SOM_MAP.

I will have to add some Ex.ini extensions that I think will specify up to two presets and two weights that can be used to mix the preset acoustics and blend them for transitions. But there will be an automatic transition system too, so you don't have to manually manage blending just for transitions, but if you think an area has kind of the quality of two different presets you can mix them or make them more or less pronounced this way.

To do this I had to get DirectSound 8 working with SOM, but that turned out to be very easy. I don't know if it has any other benefits. I know I wanted to try this in the past but I didn't because it needed DS 8. It wasn't a matter of adding a whole other pathway for DS 8. I wish Direct X was always so easy.

For the record, masterVol is controlled with the keyboard. It's there to be more convenient than the Options menu. And it works with the controller too if you have F12 assigned to any button. You can increase and decrease it and mute it with the controller, using the attack buttons as key modifiers. And F12 also shows/hides the function overlay. So it can do 4 different functions with one button. The keys that can work with it are F12, +, -, and Backspace. Backspace goes to full volume and overrides the limits that can be set in the Ex.ini file. I've already explained this some time ago when it was added.
« Last Edit: September 06, 2020, 10:11:48 AM by Holy Diver »

Holy Diver has 2452 posts

Holy Diver

  • Website System
  • Administrator
  • *****
  • Offline Offline
    • MaleView Profile
    • About/Support Me/Sword of Moonlight
look out honey, 'cause I'm using technology
Holy Diver says,
« Reply #1 on: September 14, 2020, 05:38:43 PM »

Yesterday I was trying to play a sound for KF2's fountain in the lobby area. I think maybe that fountain plays its sound multiple times, overlapping. I'm not quite sure on the timing, but I realized SOM doesn't really offer convenient ways to play sounds.

Because the fountain isn't technically animated, I found setting its looping sound didn't work, and maybe that's because it's using a MDO and not MDL model.

So I didn't want to switch to MDL and make a dummy animation to attach sounds too, so I tried to use an event instead. In that case the sound wasn't played in 3D. I found that a little surprising since I'd noticed in the past weeks the sound event does have a 3D path.

So I changed the sound event criteria to play 3D sounds for object bound events. Its old criteria was to play one-off sounds as 3D but not continuous sounds. It wasn't possible under the old behavior to make an unbound event, with the exception of the 3 system events. But now there's an option to make new system events.

And it doesn't play the sound as a loop either. So I had to set up a timer. Timers have a resolution of one second. But I don't know if it's best to alter the sound event to loop sounds because I think in practice maybe looping sounds need to overlap a little (or a lot) to feel continuous, and this can depend on the desired effect.

Long term I'm going to use a MDL but I have to figure out the best timing somehow, or close enough. But the bottom line is under the do_sound extension it's now possible to play noninteractive 3D sounds.

A problem I'm having lately is trying to find the right lengths of sound clips, I'm constantly restarting a game session to test every guess I make. (I guess I could be using audio software, but I'm not.) That's actually a recurring strategy that I've wanted to put an end to for a while. So I'm very seriously considering a project to add an interactive system for dialing variables to find their sweet spot. It will be very limited to Ex.ini Numbers marked as interactive variables. I would start working on that right now but I think maybe I should push on and try to finish a new demo for my KF2 project without it first. It will probably be the start of an Exselector.dll project since I think I want its UI framework to be a module that's not loaded until it's needed.