AeN64Config.c++ 3.06 KB
/******************************************************************************
 *
 *    Configuration Manager for AudioEditor
 *
 *****************************************************************************/
#include <stdio.h>     
#include <stdlib.h>
#include <string.h>

#include "n64.h"
#include "AeErr.h"
#include "AeConfig.h"
#include "AeN64ConfigFile.h"

#if 0
#define ms2smp(a)  (((int)((float)a * (float)OUTPUT_RATE/1000))&~0x7)
#endif

#define SECTION_SIZE  8


#define DEF_NUMBER_DMA_BUFFS              80
#define DEF_DMA_BUFF_SIZE               1024
#define DEF_DMA_FRAME_LAG                  4
#define DEF_NUMBER_SYNTH_VIRTUAL_VOICES   32
#define DEF_NUMBER_SYNTH_PHYSICAL_VOICES  32
#define DEF_NUMBER_SEQP_VOICES            32
#define DEF_DMA_QUEUE_SIZE                50
#define DEF_NUMBER_SYNTH_UPDATES         128
#define DEF_NUMBER_SEQP_EVENTS           128
#define DEF_CMD_LIST_SIZE               5000
#define DEF_SAMPLES_PER_FRAME            640 /* Best if a multiple of 160 */
#define DEF_OUTPUT_RATE                44100
#define DEF_NUMBER_CHANNELS		  16


AeN64Config::AeN64Config (void)
{
    c.audioHeap = 0;                           // should be set by giomgr
    c.heapSize = 0;                            // should be set by giomgr
    c.frameSize = DEF_SAMPLES_PER_FRAME;
    c.maxCmdListSize = DEF_CMD_LIST_SIZE;
    c.numDMABuffs = DEF_NUMBER_DMA_BUFFS;
    c.dmaBufSize = DEF_DMA_BUFF_SIZE;
    c.frameLag = DEF_DMA_FRAME_LAG;
    c.dmaQSize = DEF_DMA_QUEUE_SIZE;

    c.synConfig.maxVVoices = DEF_NUMBER_SYNTH_VIRTUAL_VOICES;
    c.synConfig.maxPVoices = DEF_NUMBER_SYNTH_PHYSICAL_VOICES;
    c.synConfig.maxUpdates = DEF_NUMBER_SYNTH_UPDATES;
    c.synConfig.maxFXbusses = 1;
    c.synConfig.outputRate = DEF_OUTPUT_RATE;
    c.synConfig.fxType = AL_FX_NONE;
    c.synConfig.params = 0;
    c.synConfig.heap = 0;                      // set by AudioApp
    c.synConfig.dmaproc = 0;                   // set by AudioApp 
    c.seqpConfig.maxVoices = DEF_NUMBER_SYNTH_VIRTUAL_VOICES;
    c.seqpConfig.maxEvents = DEF_NUMBER_SEQP_EVENTS;
    c.seqpConfig.maxChannels = DEF_NUMBER_CHANNELS;
    c.seqpConfig.debugFlags = NO_SOUND_ERR_MASK | NOTE_OFF_ERR_MASK | NO_VOICE_ERR_MASK;
    c.seqpConfig.heap = 0;                     // set by AudioApp
    c.seqpConfig.initOsc = 0;
    c.seqpConfig.updateOsc = 0;
    c.seqpConfig.stopOsc = 0;
    
    fFx = NULL;
    fFile = NULL;
}


AeN64Config::~AeN64Config (void)
{
    if (fFile)
	delete fFile;
}


AeErr
AeN64Config::ReadFromFile (const char * fileName)
{
    AeErr err = kAeNoErr;

    if (fFile)
	fFile->SetFullName (fileName);
    else
	fFile = new AeN64ConfigFile (fileName);

    if (fFile)
	err = fFile->Read (this);

    return err;
}


AeErr
AeN64Config::WriteToFile (const char * fileName)
{
    AeErr err = kAeNoErr;

    if (fFile)
	fFile->SetFullName (fileName);
    else
	fFile = new AeN64ConfigFile (fileName);

    if (fFile)
	err = fFile->Write (this);

    return err;
}


void
AeN64Config::SetFxAsset (AeFxAsset * fx)
{
    fFx = fx;

    if (fFx)
	c.synConfig.fxType = AL_FX_CUSTOM;
    else
	c.synConfig.fxType = AL_FX_NONE;
}