🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Sweet.

Published September 21, 2005
Advertisement
Heh. This is cool as hell. I've (sorta) finished all of the unit generators Burk provides on the CD-ROM that game with GG3. I've tidied them up a bit, turned them into chainable modules, and exported them to Lua. I say sorta, because I haven't thoroughly tested them, and there are apparently some bugs somewhere.

I have gotten the Wind, Rocket Engine, and Sonar Ping circuits to work using the chaining structure, but I'm stumbling on the Helicopter one. It mostly works, component-wise, but I think I have a problem with the InterpolatingDelay module, since that is where it seems to break. I'll have to fuxxor with it some more, see if I can find what the problem is.

But other than that, this thing is cool as hell. I can simply create chains of modules that combine various signal generators, filters, and other operations, then call the module at the end of the chain to fill an SDL_mixer chunk with a sample of a given length, then play the resulting sound effect, all from a Lua prompt. Observe:

-- Generate a series of sonar pingsrate=CConstantModule(0.4)pulsecon=CConstantModule(7.0)moddepth=CConstantModule(80.0)modrate=CConstantModule(180.0)freq=CConstantModule(700.0)Q=CConstantModule(1000.0)amp=CConstantModule(1.0)pulse=CImpulseOscillatorModule()rn=CRedNoiseModule()filter=CLowpassFilterModule()mult=CMultiplierModule()adder=CAdderModule()pulse:setSource(pulsecon,0)pulse:setSource(rate,1)rn:setSource(moddepth,0)rn:setSource(modrate,1)filter:setSource(pulse,0)filter:setSource(adder,2)filter:setSource(Q,3)mult:setSource(filter,0)mult:setSource(amp,1)adder:setSource(rn,0)adder:setSource(freq,1)snd=CSoundEffectCreate()snd:loadSoundUnit(mult, 200000)snd:play(0,0)


That Lua code when executed by the application sets up the module chain to generate a series of sonar pings, and dumps 200,000 samples worth of sound data (currently at the default SDL_mixer sample rate of 22050, so a couple of seconds) into a sound effect which can then be sent to SDL_mixer to play.

The binding works similarly to how libnoise works. Each module can have a certain number of input sources, themselves also modules, that are read when a module's getValue() is called. For example, a SineOscillator module has two sources, for Amplitude and Frequency. Using CConstant modules for each produces a steady note at a steady volume; interjecting a little red or white noise in there for frequency causes the pitch to vary. And so forth. A low-pass filter has 3 sources--signal source, frequency, and Q. Sources are set using the generic setSource() function, with reasonable defaults if a required source hasn't been set. (Should probably raise an exception, but what the hell).

So the above sonar ping (pretty much a direct refactoring of the sample given in the book) combines a red noise generator, impulse oscillator, and a low-pass filter with some combiner trickery, and results in a fairly elementary (yet reasonable) imitation of a sonar ping. Pretty fun stuff. Now to figure out the module chain for ass-kicking, bass-rumbling explosions. [grin]
Previous Entry Noise and sound
Next Entry Sacred
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement