Game Development Community

Torque 3D 1.1 Alpha SFX Workflows

by Rene Damm · in Torque 3D Professional · 12/01/2009 (12:26 am) · 75 replies

In this thread, I will progressively add some quick instructions on how to use several of the new SFX features in 1.1 Alpha.

For suggestions/requests/criticism/thoughts/whatever, feel free to comment.
Page«First 1 2 3 4 Next»
#61
11/18/2010 (3:39 pm)

And in SFXDescription::packData change

if( stream->writeFlag( mParameters[ i ] ) )

to

if( stream->writeFlag( mParameters[ i ] && mParameters[ i ][ 0 ] ) )

and in unpackData change

mParameters[ i ] = NULL;

to

mParameters[ i ] = StringTable->EmptyString();
#62
11/18/2010 (3:41 pm)

In both SFXTrack constructors, change

dMemset( mParameters, 0, sizeof( mParameters ) );

to

for( U32 i = 0; i < MaxNumParameters; ++ i )
      mParameters[ i ] = StringTable->EmptyString();

and in packData and unpackData, apply the same change as in the corresponding methods of SFXDescription as described in the previous post.
#63
11/18/2010 (3:42 pm)
Lastly, in AddFMODProjectDlg.ed.cs, change AddFMODProjectDlg::show to read

function AddFMODProjectDlg::show( %this )
{
   if( $platform $= "macos" )
   {
      %fmodex = "libfmodex.dylib";
      %fmodevent = "libfmodevent.dylib";
   }
   else
   {
      %fmodex = "fmodex.dll";
      %fmodevent = "fmod_event.dll";
   }

   // Make sure we have FMOD running.
   
   if( getField( sfxGetDeviceInfo(), $SFX::DEVICE_INFO_PROVIDER ) !$= "FMOD" )
   {
      MessageBoxOK( "Error",
         "You do not currently have FMOD selected as your sound system." NL
         "" NL
         "To install FMOD, place the FMOD DLLs (" @ %fmodex @ " and " @ %fmodevent @ ")" SPC
         "in your game/ folder alongside your game executable" SPC
         "and restart Torque." NL
         "" NL
         "To select FMOD as your sound system, choose it as the sound provider in" SPC
         "the audio tab of the Game Options dialog."
      );
      
      return;
   }
   
   // Make sure we have the FMOD Event DLL loaded.
   
   %deviceCaps = getField( sfxGetDeviceInfo(), $SFX::DEVICE_INFO_CAPS );
   if( !( %deviceCaps & $SFX::DEVICE_CAPS_FMODDESIGNER ) )
   {
      MessageBoxOK( "Error",
         "You do not have the requisite FMOD Event DLL in place." NL
         "" NL
         "Please copy " @ %fmodevent @ " into your game/ folder and restart Torque."
      );
      return;
   }
   
   // Show it.
      
   Canvas.pushDialog( %this, 0, true );
}

The only explanation I have for this is that it must be a big fuckup on my part. I must have stupidly namespaced the SFX_ stuff to SFX:: during the documentation push.

//Edit: sorry, accidentally pasted the wrong version
#64
11/18/2010 (4:58 pm)
That worked !!
Thank you Rene so much for your help.
#65
11/20/2010 (11:54 am)
I went through the Fmod tutorial about creating a car engine sound effect but got stuck on how to hook it up to T3d vehicle engine sound. Any pointings are welcome and thank you in advance.
#66
11/20/2010 (12:13 pm)
@Akiraa: I'm not familiar with that resource, but this is how you'd hook an rpm value to a Designer project loaded in mEngineSound:

SFXParameter* param_rpm = SFXParameter::find( mEngineSound->getTrack()->getParameter(0) );
   param_rpm->setValue( mCurrRPM );

Assuming that your first param (getParameter(0)) is for passing an rpm value (mCurrRPM).
#67
11/20/2010 (9:47 pm)
Thank you Konrad.
I am working with the code from beta3. I might give mCurrRPM a fixed value just for testing.
The tutorial is in the Fmod_designer.pdf, page 129.
#68
11/27/2010 (10:59 am)
Konrad,
I was able to hook the "engineSound" to a music fmod event "music.fev" with a "listener angle" parameter, but not to an an engine sound event with "rpm" and "load" parameters. I have tried with my own Fmod fev. file but also with "V-twin.fev" from Sonory.
I am getting console errors :

SFXFMODProject::acquire - could not load 'art/sound/vehicles/fmod_project_V-twin/V-twin.fev' (FMOD_ERR_FILE_NOTFOUND)
SFXFMODEventGroup::loadData - could not load data: FMOD_ERR_INVALID_PARAM
SFXSystem::createSource - cannot create source for 9351 (fmodVtwinProject_VtwinEvent_V_twin) of type 'SFXFMODEvent'
SFXSystem::createSource - maybe you are using the wrong SFX provider for this type of track


Any idea as why this is happening ?
Thank you again for your help.
#69
11/27/2010 (11:34 am)
I am getting the feeling that it is related to the "mCurrRPM" declaration.
Sorry for my persistance, how is mCurrRPM declared ?
#70
11/27/2010 (1:17 pm)
I'm not sure what's wrong. mCurrRPM is a float with valid values in the 850-7000 range in my case (I'm also using the Sonory project). Hmm..

This is just temp code, as it does not have gears emulated, but try this:

Declarations:
// >>>
   F32 mCurrRPM;
   F32 mTargetRPM;
   U32 mLastRPMSampleTime;
   F32 mCurrLoad;
   F32 mTargetLoad;
   // <<<

WheeledVehicle constructor:
// >>>
   mCurrRPM = 850;
   mTargetRPM = 850;
   mCurrLoad = 0.5f;
   mTargetLoad = 0.5f;
   mLastRPMSampleTime = Platform::getVirtualMilliseconds();
   // <<<

//----------------------------------------------------------------------------
/** Update engine sound
   This method is only invoked by clients.
*/
void WheeledVehicle::updateEngineSound(F32 level)
{
   if ( !mEngineSound )
      return;

   if ( !mEngineSound->isPlaying() )
      mEngineSound->play();

   mEngineSound->setTransform( getTransform() );
   mEngineSound->setVelocity( getVelocity() );
   //mEngineSound->setVolume( level );

   // >>>
   EaseF easing = EaseF(EaseF::Out, EaseF::Linear);

   F32 rpm = 0.0f;

   // get a simple rpm from the speed
   MatrixF currMatrix;
   mRigid.getTransform(&currMatrix);

   Point3F pos, r, localVel;
   currMatrix.mulP(mWheel[0].data->pos, &pos);
   mRigid.getOriginVector(pos,&r);
   mRigid.getVelocity(r, &localVel);

   // extract wheel info
   U32 contactCount = 0;
   F32 wheelAVel = 0;
   Wheel* wend = &mWheel[mDataBlock->wheelCount];
   for (Wheel* wheel = mWheel; wheel < wend; wheel++) 
   {
      if (wheel->tire && wheel->spring && wheel->surface.contact) 
         contactCount++;

      if (mFabs(wheel->avel)>wheelAVel)
         wheelAVel = mFabs(wheel->avel);
   }
   F32 maxAVel = mDataBlock->maxWheelSpeed / mWheel[0].tire->radius;
   F32 rpmScale = (wheelAVel > maxAVel) ? 0 : 1 - (wheelAVel / maxAVel);

   // do we have an rpm spike because all wheels are in the air?
   F32 spikePerc = 0.0f;
   if (contactCount == 0) {
      spikePerc = 1.0f;
   }

   rpm = 850 + 6000 * (1-rpmScale) + spikePerc * 2000;

   // add small fluctuations to make it more realistic
   rpm += mRandF(-200, 200);

   rpm = mClampF(rpm, 850, 7000);

   U32 currTime = Platform::getVirtualMilliseconds();
   U32 ellapsed = currTime - mLastRPMSampleTime;

   mLastRPMSampleTime = currTime;

   mTargetRPM = mClampF(mTargetRPM, 850, 6800);

   mTargetRPM = rpm;

   if (mTargetRPM<mCurrRPM) {
      mCurrRPM = easing.getValue(mClampF(200 - ellapsed, 0, 200)/200.0f, mTargetRPM, mCurrRPM - mTargetRPM, 1.0f);
   } else {
      mCurrRPM = easing.getValue(mClampF(ellapsed, 0, 200)/200.0f, mCurrRPM, mTargetRPM - mCurrRPM, 1.0f);
   }
   mCurrRPM = mClampF(mCurrRPM, 850, 7000);

   F32 load = 0.5f;
   load += (mCurrRPM < mTargetRPM ? 1 : -1) * 0.35f;

   F32 dtload = mTargetLoad - mCurrLoad;
   F32 loadchpersec = 4.0f;
   mTargetLoad = mTargetLoad - (dtload - dtload * mClampF(loadchpersec * ellapsed/1000.0f, 0.0f, 1.0f));

   mTargetLoad = mClampF(load, 0.01f, 0.99f);

   if (mTargetLoad<mCurrLoad) {
      mCurrLoad = easing.getValue(mClampF(200 - ellapsed, 0, 200)/200.0f, mTargetLoad, mCurrLoad - mTargetLoad, 1.0f);
   } else {
      mCurrLoad = easing.getValue(mClampF(ellapsed, 0, 200)/200.0f, mCurrLoad, mTargetLoad - mCurrLoad, 1.0f);
   }
   mCurrLoad = mClampF(mCurrLoad, 0.05f, 0.95f);

   SFXParameter* param_rpm = SFXParameter::find( mEngineSound->getTrack()->getParameter(0) );
   param_rpm->setValue( mCurrRPM );
   SFXParameter* param_load = SFXParameter::find( mEngineSound->getTrack()->getParameter(1) );
   param_load->setValue( mCurrLoad );
   // <<<
}

This sets both load and rpm, adds slight rpm fluctuations for more realism and.. works ok so far.

It's full of fixed values and it's still a WIP, but I hope this will help you some. Let me know how that goes.
#71
11/27/2010 (11:15 pm)
Thank you Konrad, your help is much appreciated.
I am having a crash when trying to assign an SFX FMOD Event to engineSound. I suspect something in the way I have converted "SFXProfile" to "SFXTrack".
Here is how It was done :

addField( "engineSound", TYPEID< SFXProfile >(), Offset(sound[EngineSound], WheeledVehicleData),

converted to :

addField( "engineSound", TypeSFXTrackName, Offset(sound[EngineSound], WheeledVehicleData),

Please forgive my ignorance, is that how it should be done ?

Thank you again for your patience.
#72
11/29/2010 (9:07 am)
Konrad,
I am re-editing my post.
Well I have managed to get the full code working.
Having the level starting with a vehicle instead of a player seemed to be a problem.
I am still having issues with saving my defaultCar setting from within the editor and the engine sound being local.

I will investigate this further.
Thank you again for your help.
#73
06/25/2012 (9:36 am)
Can I use the SFXPlayList to play 2 sounds simultaneously?

could you provide an example?

#74
06/25/2012 (10:03 am)
Should work doing it like this...

new SFXPlayList()
{
    description = AudioMusic2D;

    // Set tracks to play.
    track[ 0 ] = MyTrack1;
    track[ 1 ] = MyTrack2;

    // Don't wait up after starting to play the first track.
    transitionOut[ 0 ] = "None";

    // But wait for all tracks (i.e. #0 and #1) to finish playing after starting
    // the second one.
    transitionOut[ 1 ] = "WaitAll";
};
#75
06/25/2012 (10:08 am)
Worded like a charm thanks


It seems you are the Audio expert could you give me some advice for my new thread www.garagegames.com/community/forums/viewthread/130846
Page«First 1 2 3 4 Next»