Location-Based Ambient Sound in JKO Multiplayer
A discussion on the technical limitations of implementing location-specific stereo ambience in Jedi Outcast multiplayer. Mapping techniques like target_speaker arrays, bot-based audio hacks, and the lack of SP-style soundsets in the MP engine are explored.
Channel: #mappingSource window: 2023-11-11 22:40 - 2023-11-11 23:148 posts6 views0 votes
Tags: JKOMultiplayerOpenJK
Contributors: Deleted User #135808 (52), .mjt (47), fau5006 (7), ramikad_1091 (3)
Comms log
[2023-11-11 22:40] <Deleted User> is it possible to have ambient sound based on location? i'd like to use the music thing for it but can i change it based on location or such?
[2023-11-11 22:40] <Deleted User> just to have some nice stereo ambience based on where u are
[2023-11-11 22:41] <Deleted User> actually maybe thats not good since most ppl have music disabled π€
[2023-11-11 22:42] <Deleted User> or what would generally be the correct way to do this?
[2023-11-11 22:42] <fau5006> speakers?
[2023-11-11 22:45] <ramikad_1091> I concur with fau, target_speaker is the most obvious answer - you just put different speakers in different rooms, and voila.
[2023-11-11 22:45] <.mjt> hard spawn bots and trap them in a certain place, then use their voice channel and a custom playermodel to make sure they cannot disable it - jk (edited)
[2023-11-11 22:46] <ramikad_1091> You joke, but that's what I did for the Cube hatches π
[2023-11-11 22:46] <.mjt> though... tbh that might be mono
[2023-11-11 22:46] <.mjt> the cube cube?
[2023-11-11 22:47] <ramikad_1091> Yeah
[2023-11-11 22:47] <Deleted User> jk2 doesnt have npcs
[2023-11-11 22:47] <Deleted User> in mp
[2023-11-11 22:47] <.mjt> noice π I should redownload that and actually test it xD
[2023-11-11 22:47] <.mjt> I didn'T say NPCs
[2023-11-11 22:47] <.mjt> I said bots
[2023-11-11 22:47] <Deleted User> oh
[2023-11-11 22:47] <Deleted User> lol
[2023-11-11 22:47] <.mjt> Ofc - you cannot force other people hosting the map to do that... but as long as you host
[2023-11-11 22:47] <.mjt> it's in your control
[2023-11-11 22:48] <.mjt> since you can include such a playermodel in your map pk3 which clients and servers will have
[2023-11-11 22:48] <.mjt> and then you can at least on your server deploy them to where you need them
[2023-11-11 22:48] <Deleted User> oh "Multiple identical looping sounds will just increase volume without any speed cost." ok
[2023-11-11 22:48] <Deleted User> but do loops work with stereo?
[2023-11-11 22:48] <.mjt> no idea...
[2023-11-11 22:48] <Deleted User> ok so basically i plaster the whole map in speakers?
[2023-11-11 22:49] <.mjt> I think only with same origin will boost volume
[2023-11-11 22:49] <.mjt> but still cost entities? IDK
[2023-11-11 22:49] <Deleted User> but i need it across huge areas
[2023-11-11 22:49] <Deleted User> thinkmonocle
[2023-11-11 22:50] <fau5006> would be best to play it as music then I guess, because music is stereo mixed. or maybe you can attach entities to left/right side of the player? this is how openal plays music iirc
[2023-11-11 22:52] <Deleted User> i mean its a huge open map
[2023-11-11 22:52] <Deleted User> theres no left and right side
[2023-11-11 22:52] <Deleted User> per se
[2023-11-11 22:52] <fau5006> music with openal is basically two speakers attached to player's head
[2023-11-11 22:52] <fau5006> like headphones
[2023-11-11 22:53] <fau5006> playing left and right channel of the stereo track
[2023-11-11 22:53] <fau5006> and then openal does spatialisation as with everything else
[2023-11-11 22:53] <fau5006> that was my idea. dunno if it's possible without a mod
[2023-11-11 22:53] <Deleted User> doubt it
[2023-11-11 22:54] <.mjt> well you could force players to all use the same playermodel and include a looping .efx file that is constantly emitted and specified in animevents.cfg or whatever equivalent JK2 uses... (if at all in MP) and attach your sounds to that instead
[2023-11-11 22:55] <.mjt> in that .efx you could place two mono soundfiles with a certain offset next to where the sounds get rendered from
[2023-11-11 22:55] <.mjt> and loop it that way xD
[2023-11-11 22:55] <Deleted User> ?!?!?!
[2023-11-11 22:55] <Deleted User> no
[2023-11-11 22:55] <Deleted User> π
[2023-11-11 22:55] <.mjt> have it your way then π
[2023-11-11 22:55] <Deleted User> i like the creativity tho
[2023-11-11 22:55] <Deleted User> lol
[2023-11-11 22:57] <Deleted User> in code: / // Firstly, check if any single-shot sounds have completed, or if they need more data (for streaming Sources), / // and/or if any of the currently playing (non-Ambient) looping sounds need to be stopped / ch = s_channels ; / for (i = 0; i < s_numChannels; i++, ch++) / {
[2023-11-11 22:57] <Deleted User> π€ "non-ambient"
[2023-11-11 22:57] <Deleted User> wonder what they are referring to
[2023-11-11 22:58] <.mjt> ambient sounds wouldn't be stopped
[2023-11-11 22:58] <.mjt> what prevents you from retriggering your target_speakers with the same interval as the ambient tracks?
[2023-11-11 22:58] <Deleted User> ooooh ambient type doesnt exist in jk2 apparently
[2023-11-11 22:58] <Deleted User> nothing, i mean they support looping sounds
[2023-11-11 22:58] <Deleted User> i just wonder if they will stay in sync and not use up memory/IO
[2023-11-11 22:58] <.mjt> wouldn't global be the one you're looking for?
[2023-11-11 22:59] <.mjt> no idea
[2023-11-11 22:59] <.mjt> probably not xD
[2023-11-11 22:59] <Deleted User> :(
[2023-11-11 22:59] <.mjt> A global sound will play full volume throughout the level.
[2023-11-11 22:59] <.mjt> wouldn't that mean only one target_speaker?
[2023-11-11 22:59] <Deleted User> true
[2023-11-11 22:59] <.mjt> and autolooping?
[2023-11-11 22:59] <Deleted User> oh yea
[2023-11-11 22:59] <Deleted User> hm
[2023-11-11 22:59] <.mjt> since only looped_on and looped_off exists for toggleable sounds?
[2023-11-11 23:00] <Deleted User> but then i cant change it depending on location
[2023-11-11 23:00] <Deleted User> π€
[2023-11-11 23:00] <.mjt> oh yeah - that was your requirement, I forgot
[2023-11-11 23:00] <.mjt> well port over DMS to MP π
[2023-11-11 23:00] <.mjt> waaaait
[2023-11-11 23:00] <.mjt> do soundsets in MP work?
[2023-11-11 23:00] <Deleted User> what?
[2023-11-11 23:00] <.mjt> wait a sec
[2023-11-11 23:01] <.mjt> check sound/sound.txt in assets 0
[2023-11-11 23:02] <.mjt> though providing updated sound.txt should not be done unless total conversion...
[2023-11-11 23:02] <.mjt> someone's gonna slap you π
[2023-11-11 23:03] <.mjt> soundsets you can set on func_ movers
[2023-11-11 23:03] <.mjt> but also probably on some triggers or other stuff
[2023-11-11 23:04] <.mjt> from ns_streets SP map in JK2 / [attachment: https://cdn.discordapp.com/attachments/1103343199113711766/1173035443344916580/image.png?ex=6a026063&is=6a010ee3&hm=e413edf145693c6561bed1ceb72c88e6873e750efca4ec03583695fc838f3336&]
[2023-11-11 23:04] <.mjt> test if those work in MP too
[2023-11-11 23:04] <.mjt> and if they do but only for mono, then live with mono
[2023-11-11 23:04] <Deleted User> i searched for "soundset" in the code and nothing
[2023-11-11 23:04] <.mjt> damn
[2023-11-11 23:04] <.mjt> in JKA too?
[2023-11-11 23:05] <Deleted User> only SP i g uess
[2023-11-11 23:05] <Deleted User> idk about jka
[2023-11-11 23:05] <.mjt> hehe we have them https://github.com/search?q=repo%3Ajedis%2Fjediacademy+soundset+path%3A%2F%5Ecodemp%5C%2F%2F&type=code
[2023-11-11 23:05] <Deleted User> :(
[2023-11-11 23:06] <.mjt> but potentially only for the bmodel sounds
[2023-11-11 23:06] <.mjt> not the ambient tracks
[2023-11-11 23:07] <Deleted User> ill just have to plaster target_speaker i think
[2023-11-11 23:07] <Deleted User> i think you need a distance of about 1300 between the speakers
[2023-11-11 23:07] <Deleted User> from what i saw in code
[2023-11-11 23:07] <Deleted User> to make sure there are no muted areas
[2023-11-11 23:10] <.mjt> well good luck with that... falloffs and behaviour will be different between default dma and openal / EAX - there's no way to perfectly balance both
[2023-11-11 23:10] <.mjt> but still probably your best shot
[2023-11-11 23:12] <Deleted User> yea
[2023-11-11 23:12] <Deleted User> thats based for dma
[2023-11-11 23:12] <.mjt> most likely the bigger userbase
[2023-11-11 23:13] <Deleted User> loooool
[2023-11-11 23:13] <Deleted User> this idea wont work i think
[2023-11-11 23:13] <Deleted User> my map is so big, i'd need over 2000 speakers at those distances to even cover one layer
[2023-11-11 23:13] <Deleted User> xd
[2023-11-11 23:14] <Deleted User> altho maybe i'd need a bit less if im being smarter about it
[2023-11-11 23:14] <Deleted User> ok maybe i just do a global sound as main ambience and then just layer other sounds locally
[2023-11-11 23:14] <Deleted User> not ideal but eh
Deleted User #135808
Is it possible to have ambient sound based on location? I'd like to use the music system for it, but I need it to change based on where the player is to get some nice stereo ambience. The problem is that most people have music disabled in their settings, so I'm wondering what the correct way to handle this would be.
fau5006
Have you tried using speakers? That's the standard way to handle localized audio in-engine.
ramikad_1091
I concur with fau, target_speaker is the most obvious answer. You just put different speakers in different rooms and you're set. I've even used bots trapped in specific places to trigger sounds for the Cube hatches before.
.mjt
You could technically hard-spawn bots and trap them, then use their voice channel and a custom playermodel to make sure players can't disable the audioβjust kidding (mostly). Though that would probably end up being mono anyway.
If you host the server, you have control over the playermodels. You could include a specific model in your map PK3 and deploy them where needed. But for a general map, target_speaker is the standard. Just keep in mind that multiple identical looping sounds at the same origin will increase volume, but I'm not sure if they work with stereo files.
Deleted User #135808
JK2 doesn't have NPCs in multiplayer, so the bot idea is interesting but maybe too hacky. My main issue is that I need this across huge open areas. If I use target_speaker, I'm worried about the entity count and whether they'll stay in sync or eat up I/O. I'm looking at the code and it mentions 'non-ambient' looping sounds being stopped, which makes me wonder how the engine handles these.
fau5006
If you need stereo, music is probably your only bet because it's stereo mixed. OpenAL plays music basically like two speakers attached to the player's head (like headphones), playing the left and right channels of the stereo track while the engine handles spatialization for everything else. Doing that for localized ambient sounds without a specific mod might be impossible.
.mjt
I was looking into whether soundsets work in MP. In JKA they seem to have some support for bmodel sounds, but in JKO it looks like they might be SP-only. I checked the code and soundset doesn't even return results for the MP side of JKO.
You could try a global sound, which plays at full volume throughout the level using a single target_speaker with the global flag, but then you lose the location-based requirement. Another crazy idea: use an .efx file attached to a playermodel that emits sounds, but that's getting into 'total conversion' territory.
Deleted User #135808
I did the math based on the distance required between speakers to avoid muted areas (about 1300 units according to the code). My map is so big I'd need over 2000 speakers just to cover one layer. That's definitely not going to work.
I think I'll have to go with a global sound as the main background ambience and then just layer specific local sounds using target_speaker in key areas. It's not the perfect stereo localized solution I wanted, but it's the most realistic for the JKO MP engine.