Home | History | Annotate | Download | only in lib_src
      1 /*----------------------------------------------------------------------------
      2  *
      3  * File:
      4  * eas_wtengine.h
      5  *
      6  * Contents and purpose:
      7  * This file defines the interface for wavetable synthesis engine
      8  *
      9  * Copyright Sonic Network Inc. 2004
     10 
     11  * Licensed under the Apache License, Version 2.0 (the "License");
     12  * you may not use this file except in compliance with the License.
     13  * You may obtain a copy of the License at
     14  *
     15  *      http://www.apache.org/licenses/LICENSE-2.0
     16  *
     17  * Unless required by applicable law or agreed to in writing, software
     18  * distributed under the License is distributed on an "AS IS" BASIS,
     19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     20  * See the License for the specific language governing permissions and
     21  * limitations under the License.
     22  *
     23  *----------------------------------------------------------------------------
     24  * Revision Control:
     25  *   $Revision: 818 $
     26  *   $Date: 2007-08-02 15:19:41 -0700 (Thu, 02 Aug 2007) $
     27  *----------------------------------------------------------------------------
     28 */
     29 
     30 #ifndef _EAS_WTENGINE_H
     31 #define _EAS_WTENGINE_H
     32 
     33 /* option sanity check */
     34 #if defined(_OPTIMIZED_MONO) && defined(_FILTER_ENABLED)
     35 #error "Incompatible build settings: _OPTIMIZED_MONO cannot be used with _FILTER_ENABLED"
     36 #endif
     37 
     38 #if defined(_OPTIMIZED_MONO) && (NUM_OUTPUT_CHANNELS != 1)
     39 #error "Incompatible build settings: _OPTIMIZED_MONO can only be used with NUM_OUTPUT_CHANNELS = 1"
     40 #endif
     41 
     42 #include "eas_wt_IPC_frame.h"
     43 
     44 /*----------------------------------------------------------------------------
     45  * defines
     46  *----------------------------------------------------------------------------
     47 */
     48 #define WT_NOISE_GENERATOR                  0xffffffff
     49 
     50 /*----------------------------------------------------------------------------
     51  * typedefs
     52  *----------------------------------------------------------------------------
     53 */
     54 
     55 /*----------------------------------------------------------------------------
     56  * S_WT_INT_FRAME
     57  *
     58  * This structure includes S_WT_FRAME plus the bus mixing
     59  * parameters for the internal voices.
     60  *----------------------------------------------------------------------------
     61 */
     62 typedef struct s_wt_int_frame_tag
     63 {
     64     S_WT_FRAME      frame;
     65     EAS_PCM         *pAudioBuffer;
     66     EAS_I32         *pMixBuffer;
     67     EAS_I32         numSamples;
     68     EAS_I32         prevGain;
     69 } S_WT_INT_FRAME;
     70 
     71 #if defined(_FILTER_ENABLED)
     72 /*----------------------------------------------------------------------------
     73  * S_FILTER_CONTROL data structure
     74  *----------------------------------------------------------------------------
     75 */
     76 typedef struct s_filter_control_tag
     77 {
     78     EAS_I16     z1;                             /* 1 sample delay state variable */
     79     EAS_I16     z2;                             /* 2 sample delay state variable */
     80 } S_FILTER_CONTROL;
     81 #endif
     82 
     83 /*------------------------------------
     84  * S_LFO_CONTROL data structure
     85  *------------------------------------
     86 */
     87 typedef struct s_lfo_control_tag
     88 {
     89     EAS_I16     lfoValue;           /* LFO current output value */
     90     EAS_I16     lfoPhase;           /* LFO current phase */
     91 } S_LFO_CONTROL;
     92 
     93 /* bit definitions for S_WT_VOICE:flags */
     94 #define WT_FLAGS_ADPCM_NIBBLE           1       /* high/low nibble flag */
     95 #define WT_FLAGS_ADPCM_READY            2       /* first 2 samples are decoded */
     96 #define WT_FLAGS_USE_ADPCM              4       /* sample is ADPCM encoded */
     97 
     98 /* eg1State and eg2State */
     99 typedef enum {
    100     eEnvelopeStateInit = 0,
    101     eEnvelopeStateDelay,
    102     eEnvelopeStateAttack,
    103     eEnvelopeStateHold,
    104     eEnvelopeStateDecay,
    105     eEnvelopeStateSustain,
    106     eEnvelopeStateRelease,
    107     eEnvelopeStateMuting,
    108     eEnvelopeStateMuted,
    109     eEnvelopeStateInvalid           /* should never be in this state! */
    110 } E_ENVELOPE_STATE;
    111 
    112 #define DEFAULT_EG1_STATE       eEnvelopeStateAttack
    113 #define DEFAULT_EG1_VALUE       0
    114 #define DEFAULT_EG1_INCREMENT   0
    115 #define DEFAULT_EG2_STATE       eEnvelopeStateAttack
    116 #define DEFAULT_EG2_VALUE       0
    117 #define DEFAULT_EG2_INCREMENT   0
    118 
    119 /*----------------------------------------------------------------------------
    120  * S_WT_VOICE
    121  *
    122  * This structure contains state data for the wavetable engine
    123  *----------------------------------------------------------------------------
    124 */
    125 typedef struct s_wt_voice_tag
    126 {
    127     EAS_U32             loopEnd;                /* points to last PCM sample (not 1 beyond last) */
    128     EAS_U32             loopStart;              /* points to first sample at start of loop */
    129     EAS_U32             phaseAccum;             /* current sample, integer portion of phase */
    130     EAS_U32             phaseFrac;              /* fractional portion of phase */
    131 
    132 #if (NUM_OUTPUT_CHANNELS == 2)
    133     EAS_I16             gainLeft;               /* current gain, left ch  */
    134     EAS_I16             gainRight;              /* current gain, right ch */
    135 #endif
    136 
    137 #if defined(_FILTER_ENABLED)
    138     S_FILTER_CONTROL    filter;                 /* low pass filter */
    139 #endif
    140 
    141     S_LFO_CONTROL       modLFO;                 /* modulator LFO */
    142 
    143 #ifdef DLS_SYNTHESIZER
    144     S_LFO_CONTROL       vibLFO;                 /* vibrato LFO */
    145 #endif
    146 
    147     /* envelope control */
    148     EAS_I16             eg1Value;
    149     EAS_I16             eg2Value;
    150     EAS_I16             eg1Increment;
    151     EAS_I16             eg2Increment;
    152     EAS_U8              eg1State;
    153     EAS_U8              eg2State;
    154 
    155     EAS_U16             artIndex;               /* index to articulation params */
    156 
    157 } S_WT_VOICE;
    158 
    159 /*----------------------------------------------------------------------------
    160  * prototypes
    161  *----------------------------------------------------------------------------
    162 */
    163 EAS_BOOL WT_CheckSampleEnd (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame, EAS_BOOL update);
    164 void WT_ProcessVoice (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame);
    165 
    166 #ifdef EAS_SPLIT_WT_SYNTH
    167 void WTE_ConfigVoice (EAS_I32 voiceNum, S_WT_CONFIG *pWTConfig, EAS_FRAME_BUFFER_HANDLE pFrameBuffer);
    168 void WTE_ProcessVoice (EAS_I32 voiceNum, S_WT_FRAME *pWTParams, EAS_FRAME_BUFFER_HANDLE pFrameBuffer);
    169 #endif
    170 
    171 #endif
    172