AeN64DriverFx.c++ 4.24 KB
//
// AeN64DriverFx.c++
//
// This file contains routines for managing n64 built-in
// effects.  The n64 provides five built-in effects that
// require creating and initializing and it also requires
// that all delay values are in samples and aligned to 8 sample
// boundaries.
//

#include <assert.h>
#include <stdlib.h>

#include "AeN64Driver.h"
#include "AeConfig.h"
#include "GioMgr.h"		// PARAMS_PER_SECTION
#include "AeAsset.h"
#include "AeAssetBase.h"
#include "GList.h"


#define N_FX_PARAMS	2
 

//
//		         		        chorus  chorus   filter
//      input  output  fbcoef  ffcoef   gain     rate   depth     coef
//
int SMALLROOM_PARAMS[26] =
{
          3,   100,

           0,   54,     9830,  -9830,      0,      0,      0,      0,
          19,   38,     3276,  -3276, 0x3fff,      0,      0,      0,
           0,   60,     5000,      0,      0,      0,      0, 0x5000
};

int BIGROOM_PARAMS[34] =
{
           4,  100,

           0,   66,     9830,  -9830,      0,      0,      0,      0,
          22,   54,     3276,  -3276, 0x3fff,      0,      0,      0,
          66,   91,     3276,  -3276, 0x3fff,      0,      0,      0,
           0,   94,     8000,      0,      0,      0,      0, 0x5000
};

int ECHO_PARAMS[10] =
{
           1,  200,

           0,  179,    12000,      0, 0x7fff,      0,      0,      0
};

int CHORUS_PARAMS[10] =
{
           1,  20,

	   0,   5,    0x4000,      0,  0x7fff,   7600,   700,      0
};

int FLANGE_PARAMS[10] =
{
           1,  20,

	   0,   5,         0, 0x5fff,  0x7fff,    380,   500,      0
};


void
AeN64Driver::fxCreateBuiltIn (void)
{
    AeFxAsset * asset;

    asset = new AeFxAsset ("smallroom");
    fxParseParamList (asset, SMALLROOM_PARAMS);
    fAssetBase->AppendAsset (asset);

    asset = new AeFxAsset ("bigroom");
    fxParseParamList (asset, BIGROOM_PARAMS);
    fAssetBase->AppendAsset (asset);

    asset = new AeFxAsset ("chorus");
    fxParseParamList (asset, CHORUS_PARAMS);
    fAssetBase->AppendAsset (asset);

    asset = new AeFxAsset ("flange");
    fxParseParamList (asset, FLANGE_PARAMS);
    fAssetBase->AppendAsset (asset);

    asset = new AeFxAsset ("echo");
    fxParseParamList (asset, ECHO_PARAMS);
    fAssetBase->AppendAsset (asset);
}


void
AeN64Driver::fxParseParamList (AeFxAsset * fxAsset, int * params)
{
    AeFxSxnAsset *	sxnAsset;
    int			nSections;
    int			i;
    int *		p;

    p = params;
    nSections = *p++;
    fxAsset->SetLength (*p++);

    for (i=0; i<nSections; i++)
    {
	sxnAsset = new AeFxSxnAsset ("");
	fxAsset->AppendChild (sxnAsset);

	p = fxSxnParseParamList (sxnAsset, p);
    }
}


void
AeN64Driver::fxBuildParamList (AeFxAsset * fxAsset, int ** pParams, int * nParams)
{
    GList<AeAsset *> *	childList;
    AeAsset *		asset;
    int			nSections;
    int *		p;
    int			i;

    
    childList = ((AeContainerAsset *)fxAsset)->GetChildList ();
    assert (childList);

    nSections = childList->GetNum ();
    *nParams = (N_FX_PARAMS + nSections * PARAMS_PER_SECTION);

    if (*pParams = (int *)malloc (*nParams * sizeof (int)))
    {
	p = *pParams;
	*p++ = nSections;
	*p++ = msec2alignedsamples (fxAsset->GetLength ());
	
	childList->Start (i);
	while (childList->Next (i, asset))
	    p =  fxSxnBuildParamList ((AeFxSxnAsset *)asset, p);
    }
}    


int *
AeN64Driver::fxSxnParseParamList (AeFxSxnAsset * sxnAsset, int * params)
{
    sxnAsset->SetInput (*params++);
    sxnAsset->SetOutput (*params++);
    sxnAsset->SetFBCoef (*params++);
    sxnAsset->SetFFCoef (*params++);
    sxnAsset->SetGain (*params++);
    sxnAsset->SetChorusRate (*params++);
    sxnAsset->SetChorusDepth (*params++);
    sxnAsset->SetFilterCoef (*params++);

    return params;
}


int *
AeN64Driver::fxSxnBuildParamList (AeFxSxnAsset * asset, int * params)
{
    *params++ = msec2alignedsamples (asset->GetInput ());
    *params++ = msec2alignedsamples (asset->GetOutput ());
    *params++ = asset->GetFBCoef ();
    *params++ = asset->GetFFCoef ();
    *params++ = asset->GetGain ();
    *params++ = asset->GetChorusRate ();
    *params++ = asset->GetChorusDepth ();
    *params++ = asset->GetFilterCoef ();

    return params;
}


int
AeN64Driver::msec2alignedsamples (int msec)
{
    assert (fConfig);

    long outputRate = fConfig->GetOutputRate ();

    return ((long)msec * outputRate / 1000) & ~0x7;
}