AEReverb.c++ 4.07 KB
/*****************************************************************************
 *  File:  AEReverb.c++ 
 *
 *  AEReverb Class Implementations
 *
 ****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "Assets.h"
#include "Mgrs.h"

/*****************************************************************************
 *
 *   Initialization Routines
 * 
 ****************************************************************************/

AEReverb::AEReverb()
{
    type = AL_FX_NONE;
    params = 0;
    maxParam = 0;
}

AEReverb::~AEReverb()
{

}

/*****************************************************************************
 *
 *    Asset's Methods
 *
 ****************************************************************************/
#define ms *(((s32)((f32)44.1))&~0x7)
 

s32 SMALLROOM_PARAMS[26] = {
    /* sections	   length */
          3,        100 ms,
                                      /*       chorus  chorus   filter
       input  output  fbcoef  ffcoef   gain     rate   depth     coef  */
           0,   54 ms,  9830,  -9830,      0,      0,      0,      0,
       19 ms,   38 ms,  3276,  -3276, 0x3fff,      0,      0,      0,
           0,   60 ms,  5000,      0,      0,      0,      0, 0x5000
};

s32 BIGROOM_PARAMS[34] = {
    /* sections	   length */
          4,        100 ms,
                                      /*       chorus  chorus   filter
       input  output  fbcoef  ffcoef   gain     rate   depth     coef  */
           0,   66 ms,  9830,  -9830,      0,      0,      0,      0,
       22 ms,   54 ms,  3276,  -3276, 0x3fff,      0,      0,      0,
       66 ms,   91 ms,  3276,  -3276, 0x3fff,      0,      0,      0,
           0,   94 ms,  8000,      0,      0,      0,      0, 0x5000
};

s32 ECHO_PARAMS[10] = {
    /* sections	   length */
          1,       200 ms,
                                      /*       chorus  chorus   filter
       input  output  fbcoef  ffcoef   gain     rate   depth     coef   */
           0,  179 ms, 12000,      0, 0x7fff,      0,      0,      0
};

s32 CHORUS_PARAMS[10] = {
    /* sections	   length */
          1,        20 ms,
                                      /*       chorus  chorus   filter
       input  output  fbcoef  ffcoef   gain     rate   depth     coef   */
	  0,   5 ms, 0x4000,      0,  0x7fff,   7600,   700,      0
};

s32 FLANGE_PARAMS[10] = {
    /* sections	   length */
          1,        20 ms,
                                      /*       chorus  chorus   filter
       input  output  fbcoef  ffcoef   gain     rate   depth     coef   */
	   0,   5 ms,      0, 0x5fff, 0x7fff,    380,   500,      0
};

s32 NULL_PARAMS[10] = {
    0, 0,
    0, 0, 0, 0, 0, 0, 0, 0
};


void AEReverb::SetType(int t)
{
    type = t;
    switch(t)
    {
        case AL_FX_SMALLROOM:   params = SMALLROOM_PARAMS;       break;
        case AL_FX_BIGROOM:     params = BIGROOM_PARAMS;         break;
        case AL_FX_CHORUS:      params = CHORUS_PARAMS;          break;
        case AL_FX_FLANGE:      params = FLANGE_PARAMS;          break;
        case AL_FX_ECHO:        params = ECHO_PARAMS;            break;
        default:                params = NULL_PARAMS;            break;
    }
    if(params)
	maxParam = (params[0] * PARAMS_PER_SECTION) + 2;
}

int AEReverb::GetType(void)
{
    return type;
}

void AEReverb::AllocParamBuf(int numSections)
{
    maxParam = (numSections * 8) + 2;
    params = (s32*)malloc(maxParam * sizeof(s32));
    if(!params)
    {
	maxParam = 0;
	printf("Unable to allocate memory for reverb params\n");
    }
    else
	params[0] = numSections;
}

s32* AEReverb::GetParamBuf(void)
{
    return params;
}

void AEReverb::SetParam(int index, s32 value)
{
    if(index == 0)
	printf("Setting number of reverb sections not allowed\n");
    else if(index > maxParam)
	printf("trying to access invalid index %d\n",index);
    else if (!params)
	printf("Reverb param buffer not allocated\n");
    else
	params[index] = value;
}

int AEReverb::GetParam(int index, s32 *value)
{
    if(params)
    {
	*value = params[index];
	return(1);
    }
    return(0);
}