Low level control

Vectrex

24-04-2007 11:36:06

howdy, I'm making a kart simulator and was wondering on an approach to doing the engine sounds. Now, normally people record engine loops at different RPMs and blend between them in game, which is what I do at the moment. But I want to actually trigger a single cylinder sample synced to the engine simulation. I've mocked up a version in a music program and it sounds good, but I'm not sure how or if you can do it in fmod or ogreAL.
Would I have to have this code in the audio thread? Since I can't exactly trigger a sample 15,000 times a second when I'm running at 50 fps :)
I know you CAN do it, but I've no idea where to start looking.

CaseyB

24-04-2007 15:22:47

Playing a single sample 15,000 times a second is probably not the way you want to do this since sound devices actually have a very low number of sounds that they can play simultaneously (like 25-30). What exactly is it you are tying to accomplish? Maybe if I better understand I can make some suggestions.

Vectrex

24-04-2007 15:43:39

yeah nothing like that :) Here's an edited irc log with P about it as I think the same questions will come up (I hope P doesn't mind :) ). The top bit is all you need.

[22:51] <P__> you want to play 15000 sounds a sec ? :)
[22:52] <Vectrex> hehe, yep
[22:52] <P__> the problem is that the internal refresh rate of openAL is to 40Hz if i remember correctly
[22:52] <Vectrex> basically so it sythesises like a real engine
[22:52] <P__> i'm not sure about how it works internally, but i'm almost sure you will run into precision issues
[22:53] <P__> you could just record at several rpm, and blend that with piching, that's what most game do, ok not as fun as what you want, but works ;à
[22:53] <Vectrex> heh yeah that's what we've done now
[22:53] <Vectrex> works ok, but not good enough :)
[22:53] <Vectrex> I know you can do it, I'll have to run another thread though I think
[22:54] <P__> i don't think it's possible to spawn 15000 sounds a sec, just because they will overlap, and the max simultaneous sources available will be quickly overtaken
[22:54] <Vectrex> nah, nothing like that. I'm simulating a one cylinder engine, so they can cut each other off
[23:02] <Vectrex> ok here is a recording of a real kart
[23:03] <Vectrex> we straped 2 microphones to the artist who is a karter :)
[23:03] <Vectrex> http://users.on.net/~edan/games/KartSimulator/visible/
[23:03] <Vectrex> play the 'zac real kart lap' mp3 first
[23:03] <P__> ok
[23:05] <Vectrex> so with the synth version I'm only using one cylinder sample, so it sounds bad down low, but we'll sample lots of varations
[23:06] <Vectrex> and we also need to do some filtering of the engine sound, so another thing i have no idea how to do :)
[23:06] <P__> downloading the second sound now
[23:07] <P__> it sounds like a bee :)
[23:07] <P__> if it's the right word
[23:07] <P__> a bad mood one !
[23:07] <Vectrex> hehe yeah, the little buggers rev at like 16,000 rpm
[23:07] <Vectrex> with no gears
[23:08] <Vectrex> so that's a mockup in this music program I use
[23:08] <P__> filtering in which sense ?
[23:08] <Vectrex> when you decellerate a value closes and muffles the firing sound
[23:09] <P__> ok
[23:09] <P__> i think it can be done 2 ways, by applying a filter like the one presents in openAL EFX extension, or by making the filter yourself
[23:10] <Vectrex> well we have filter code used for realtime apps (flatmate ;)
[23:10] <P__> the seonc is more tricky maybe, because you need to divide the sound in several buffers like if you were streaming it
[23:10] <P__> hehe
[23:10] <P__> sounds a lot of experimenting and fun
[23:10] <Vectrex> can't I run this in another thread and pass basic info to it from the main thread?
[23:11] <P__> you will not be able to modify a buffer while it's playing, by design
[23:11] <Vectrex> so just as my music program is simulating it running at 15,000 a sec only using 2% cpu?
[23:11] <P__> i can be wrong but that how i understand it
[23:11] <Vectrex> no that's what I want
[23:11] <Vectrex> each fire sound it unique, I don't actually change the pitch at all in the mockup
[23:11] <Vectrex> like a real engine :)
[23:12] <Vectrex> the pitch is coming from the fact that it's being fired so many times a second
[23:12] <P__> yes i understand
[23:12] <P__> the second thread would then control the firing isn't it ?
[23:12] <Vectrex> so basically I can pass the current engine rpm from the main thread to the audio one and change the rate there
[23:12] <P__> playing the sound i mean
[23:12] <Vectrex> yeah
[23:12] <P__> yes that would be possible i think
[23:13] <P__> as long as all the audio stuff is done in the second thread
[23:13] <Vectrex> yep
[23:13] <Vectrex> only basic low rate info would be passed one way to the audio thread
[23:13] <Vectrex> like acceleration amount, current rpm etc
[23:13] <P__> but why not using loop at diferent rpm, won't the effect be the same ? unless you change the pitch at a very high frequency, which mean that the game has to be updated at very high freq
[23:14] <Vectrex> the audio thread would then do a little bit of interpolation between values to avoid low framerate jumping of the frequency
[23:14] <Vectrex> well the thing with that is the pitch shifting sounds totally wrong
[23:14] <Vectrex> engines don't change the pitch, they change the firing rate
[23:15] <Vectrex> so I play the samples at the originally recorded pitch
[23:15] <P__> yes it's not exact
[23:15] <Vectrex> plus a big bonus is I can pass engine damage parameters to the audio thread, to subtly change the timing
[23:15] <P__> it modifies the sound freq
[23:15] <Vectrex> for tuning the engine
[23:16] <Vectrex> yeah, we do it the 'normal' way now and it works, but it's really not that great
[23:16] <P__> how many loops ?
[23:16] <Vectrex> 6
[23:16] <P__> maybe that's the point and it should be increased to 20, i don't know
[23:17] <P__> i don't say you are wrong with what you want to try at all, just that sounds a bit overkill
[23:17] <Vectrex> yeah, but it's very very hard to match up the samples with rate and pitch when fading
[23:17] <Vectrex> we'll have to put it on a bench and record exact rpms
[23:17] <Vectrex> otherwise it sounds like multiple karts like it does now :)
[23:18] <Vectrex> if we could match it up nicely then yeah more levels would work
[23:18] <P__> can't you find the rpm with your audio software, and then scale it as needed ?
[23:18] <Vectrex> yep, but it will always never quite match up, because engines aren't that stable
[23:18] <P__> to make it match perfectly, well i guess the rpm isn't something perfect constant
[23:18] <Vectrex> so it always sounds like there's 2 karts
[23:18] <P__> ok same understanding :)
[23:19] <Vectrex> it's easier with cars because they rev so low :)
[23:19] <Vectrex> or indeed tractors ;P
[23:19] <P__> i haven't work with the sound on this project, the other dev did, but we don't even have several loops
[23:20] <P__> so i'm just guessing on this point, never tried it
[23:20] <Vectrex> hehe, I've never seen a tractor go that fast :)
[23:29] <Vectrex> check this out
[23:29] <Vectrex> http://www.youtube.com/watch?v=OdSPHFqplfA
[23:29] <Vectrex> richard burns rally
[23:29] <Vectrex> THE hardest/most realistic car get ever
[23:29] <Vectrex> this uses the synth engine idea
[23:30] <P__> far from toca3 :)
[23:31] <Vectrex> haha just a bit ;)

Vectrex

01-05-2007 14:47:51

I thought I wouldn't get much of a response :)
Anyway I did it, I spawn a new thread with a slightly higher priority and trigger the sound in time to the engine rpm independant of the main program.
Btw I didn't mean 15,000 A SECOND, I meant 15,000 a minute, so much more sane :) Thankfully openAL lets me trigger it that fast (I'm only restarting the same sound really), unlike FMOD which seems to cap around 50 times a second (I need more like 300)
It's not perfect, there's still a slight timing problem even though I'm using performanceQuery so at high rpm the sound looses it, but I'm getting there.

CaseyB

02-05-2007 01:38:06

Cool, I'm glad you got it working! I had no idea how to help you with that one!