synthInternals.h 6.84 KB
/*====================================================================
 * audioInternals.h
 *
 * Synopsis:
 *
 * Copyright 1993, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

#ifndef __audioInternals__
#define __audioInternals__

#include <libaudio.h>

/*
 * filter message ids
 */
enum {
    AL_FILTER_SET_SOURCE,
    AL_FILTER_ADD_SOURCE,
    AL_FILTER_ADD_UPDATE,
    AL_FILTER_RESET,
    AL_FILTER_SET_WAVETABLE,
    AL_FILTER_SET_DMA_PROC,
    AL_FILTER_SKIP_LOOP,
    AL_FILTER_SET_DRAM,
    AL_FILTER_SET_PITCH,
    AL_FILTER_SET_UNITY_PITCH,
    AL_FILTER_START,
    AL_FILTER_SET_DECAY,
    AL_FILTER_SET_FC,
    AL_FILTER_SET_STATE,
    AL_FILTER_SET_VOLUME,
    AL_FILTER_SET_PAN,
    AL_FILTER_SET_FXAMT
};

/*
 * buffer locations
 */
#define AL_DECODER_IN	        0
#define	AL_RESAMPLER_OUT	0
#define AL_TEMP_0	        0
#define	AL_DECODER_OUT	        320
#define	AL_TEMP_1	        320
#define	AL_MAIN_L_OUT	        1088
#define	AL_MAIN_R_OUT	        1408
#define	AL_AUX_L_OUT	        1728
#define	AL_AUX_R_OUT	        2048

/*
 * filter types
 */
enum {
    AL_ADPCM,
    AL_RESAMPLE,
    AL_BUFFER,
    AL_SAVE,
    AL_ENVMIX,
    AL_FX,
    AL_AUXBUS,
    AL_MAINBUS
};

typedef struct ALParam_s {
    struct ALParam_s    *next;
    short               delta;
    short               type;
    union {
        float           f;
        int             i;
    } data;
    union {
        float           f;
        int             i;
    } moredata;
} ALParam;

typedef Acmd *(*ALCmdHandler)(void *, short *, int, int, Acmd *);
typedef int   (*ALSetParam)(void *, int, void *);

typedef struct ALFilter_s {
    struct ALFilter_s   *source;
    ALCmdHandler        handler;
    ALSetParam          setParam;
    short               inp;
    short               outp;
    int                 type;
} ALFilter;

void    alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, int type);

#define AL_MAX_ADPCM_STATES     2       /* Depends on number of subframes
                                         * per frame and loop length
                                         */
typedef struct {
    ALFilter                    filter;
    ADPCM_STATE                 state[AL_MAX_ADPCM_STATES];
    ALADPCMloop                 loop;
    struct ALWaveTable_s        *table;
    int                         bookSize;
    ALDMAproc                   dma;
    int                         current;
    int                         sample;
    int                         lastsam;
    int                         first;
    int                         memin; 
    int                         dramstart;
} ALADPCMFilter;

void    alAdpcmNew(ALADPCMFilter *f);
Acmd    *alAdpcmPull(void *f, short *outp, int byteCount, int flags, Acmd *p);
int     alAdpcmParam(void *filter, int paramID, void *param);

typedef struct {
    float		fc;
    short		fgain;
    union {
        short		fccoef[16];
        long long       force_aligned;
    } fcvec;
    POLEF_STATE		fstate;
    int			first;
} ALLowPass;

typedef struct {
    short		*base;
    int			length;
    short		*tap;
    short		coef;
    ALLowPass		lpfilt;
} ALDelay;

#define AL_MAX_NUM_OF_EFFECTS	3
#define AL_MAX_NUM_OF_SECTIONS	3
#define AL_MAX_NUM_OF_FX_PARAMS 3
typedef struct {
    struct ALFilter_s   filter;
    ALDelay		delay[AL_MAX_NUM_OF_SECTIONS];
    int			param[AL_MAX_NUM_OF_FX_PARAMS];
    int			section_count;
    int			motion;
    ALFxId		id;
} ALFx;

void	alReverbNew(ALFx *r, ALFxId id, short *mem, int size, float rate);
Acmd    *alSmallRoomPull(void *f, short *outp, int out, int flags, Acmd *p);
Acmd    *alEchoPull(void *f, short *outp, int out, int flags, Acmd *p);
int     alReverbParam(void *filter, int paramID, void *param);

#define AL_MAX_MAIN_BUS_SOURCES       1
typedef struct ALMainBus_s {
    ALFilter            filter;
    int                 sourceCount;
    int                 maxSources;
    ALFilter            **sources;
} ALMainBus;

void    alMainBusNew(ALMainBus *m, void *ptr, int len);
Acmd    *alMainBusPull(void *f, short *outp, int outCount, int flags, Acmd *p);
int     alMainBusParam(void *filter, int paramID, void *param);

#define AL_MAX_AUX_BUS_SOURCES       8
#define AL_MAX_AUX_BUS_FX	     1
typedef struct ALAuxBus_s {
    ALFilter            filter;
    int                 sourceCount;
    int                 maxSources;
    ALFilter            **sources;
    ALFx		fx[AL_MAX_AUX_BUS_FX];
} ALAuxBus;

void    alAuxBusNew(ALAuxBus *m, void *ptr, int len);
Acmd    *alAuxBusPull(void *f, short *outp, int outCount, int flags, Acmd *p);
int     alAuxBusParam(void *filter, int paramID, void *param);

typedef struct ALResampler_s {
    ALFilter            filter;
    RESAMPLE_STATE      state;
    float               ratio;
    int			upitch;
    float		delta;
    int			first;
    ALParam		*ctrlList;
    ALParam		*ctrlTail;
    int                 motion;
} ALResampler;

void    alResampleNew(ALResampler *r);
Acmd    *alResamplePull(void *f, short *outp, int out, int flags, Acmd *p);
int     alResampleParam(void *f, int paramID, void *param);

typedef struct ALSave_s {
    ALFilter            filter;
    int	       		dramout;
    float               ratio;
    float               delta;
    RESAMPLE_STATE      stateL;
    RESAMPLE_STATE      stateR;
    int                 first;
} ALSave;

void    alSaveNew(ALSave *r);
Acmd    *alSavePull(void *f, short *outp, int outCount, int flags, Acmd *p);
int     alSaveParam(void *f, int paramID, void *param);

typedef struct ALEnvMixer_s {
    ALFilter            filter;
    ENVMIX_STATE	state;
    short		pan;
    short		volume;
    short		cvolL;
    short		cvolR;
    short		dryamt;
    short		wetamt;
    unsigned short      lratl;
    short               lratm;
    short               ltgt;
    unsigned short      rratl;
    short               rratm;
    short               rtgt;
    int                 delta;
    int                 segEnd;
    int			first;
    ALParam		*ctrlList;
    ALParam		*ctrlTail;
    ALFilter            **sources;
    int                 motion;
} ALEnvMixer;

void    alEnvmixerNew(ALEnvMixer *e);
Acmd    *alEnvmixerPull(void *f, short *outp, int out, int flags, Acmd *p);
int     alEnvmixerParam(void *filter, int paramID, void *param);

#endif