Game Development Community

Music Data Sensing

by Andrew H · in Torque Game Builder · 09/16/2011 (7:50 pm) · 7 replies

Is there any way to sense the current amplitude of a music file you are playing so you can sense the intensity and have the game react to it?

If there's a better way to do it, please inform me.

#1
09/17/2011 (12:39 am)
You'd have to get somewhat low-level with OpenAL to do this, and create some custom functions if you want it exposed to TorqueScript. Definitely a standard engine feature, though ;)

I know I've seen people discuss this on other sites, so you should be able to find OpenAL examples for this sort of thing. Just figure out where in the audio code the raw buffers are and extract some relevant data/averages for it, and maybe fill up another buffer for your custom code to "drain" as needed for visual/logical variation in the game.
#2
09/17/2011 (6:38 am)
Okay - let me see if I've got this straight. I integrate OpenAL into T2D, and then I can do this? I'm not really an expert in any one programming language...but I would need to know C++ in order to integrate it?
#3
09/17/2011 (6:42 am)
OpenAL is already used by T2D, but you'd have to be fairly familiar (at least comfortable) with C++ to set up and expose your extended functionality to TorqueScript so that you could use it.
#4
09/17/2011 (6:53 am)
Ah, okay. Learn C++, add TorqueScript functions to do what I want it to, and then it's been set up to where those functions exist - right? Where would I need to set up the functions? New file? Existing file? A certain folder?
#5
09/17/2011 (7:50 am)
Well, that depends on how you're managing your code. I would use the project source folder to set up my extended functionality by deriving from the audio systems that I needed. I'm not expert on the audio code, so I'm afraid I can't be much help just yet.

The other option is to simply add the new functionality into the current audio classes in the engine codebase directly, but then this code will be included in every project you create from here on out from this T2D install. That might be desirable, and it might not.

The first approach is better, in my opinion, because you can always take your new code and add it to any new project very easily if you want it. It also doesn't pollute the main codebase.

In all of this I think the "learn C++" part is the hardest. It is a powerful language with many features and though easy enough to learn it is difficult to master.
#6
09/19/2011 (4:23 am)
I think the "learn C++" part won't need to be too involved, but at least the ability to write a function in C++ that is available from script is needed. The rest is all mathematics (taking amplitudes and averaging).
#7
09/19/2011 (6:48 pm)
I see...maybe this is too complicated for a first game.