Home | History | Annotate | Download | only in lib_src
      1 /*----------------------------------------------------------------------------
      2  *
      3  * File:
      4  * eas_fmengine.h
      5  *
      6  * Contents and purpose:
      7  * Declarations, interfaces, and prototypes for FM synthesize low-level.
      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: 664 $
     26  *   $Date: 2007-04-25 13:11:22 -0700 (Wed, 25 Apr 2007) $
     27  *----------------------------------------------------------------------------
     28 */
     29 
     30 /* sentinel */
     31 #ifndef _FMENGINE_H
     32 #define _FMENGINE_H
     33 
     34 /* check for split architecture */
     35 #if defined (EAS_SPLIT_HYBRID_SYNTH) || defined(EAS_SPLIT_FM_SYNTH)
     36 #define FM_OFFBOARD
     37 #endif
     38 
     39 /* output level to mix buffer (3 = -24dB) */
     40 #define FM_GAIN_SHIFT 3
     41 #define FM_MONO_GAIN_SHIFT 9
     42 
     43 /* voice output level for stereo 15 = +6dB */
     44 #define FM_STEREO_PRE_GAIN_SHIFT 11
     45 #define FM_STEREO_POST_GAIN_SHIFT 10
     46 
     47 /* modulator input level shift (21 = -30dB) */
     48 #define FM_MODULATOR_INPUT_SHIFT 21
     49 
     50 /* feedback control level shift (7 = 0dB) */
     51 #define FM_FEEDBACK_SHIFT 7
     52 
     53 /* synth final output level */
     54 #define SYNTH_POST_GAIN_SHIFT 14
     55 
     56 /* LFO modulation to gain control */
     57 #define FM_LFO_GAIN_SHIFT 12
     58 
     59 /* sine table is always a power of 2 - saves cycles in inner loop */
     60 #define SINE_TABLE_SIZE_IN_BITS 11
     61 #define SINE_TABLE_SIZE 2048
     62 
     63 /* operator structure for FM engine */
     64 typedef struct
     65 {
     66     EAS_U32     phase;              /* current waveform phase */
     67     EAS_U16     gain;               /* current internal gain */
     68     EAS_U16     outputGain;         /* current output gain */
     69 } S_FM_ENG_OPER;
     70 
     71 typedef struct
     72 {
     73     S_FM_ENG_OPER   oper[4];        /* operator data */
     74     EAS_I16         op1Out;         /* op1 output for feedback loop */
     75     EAS_I16         op3Out;         /* op3 output for feedback loop */
     76     EAS_U16         voiceGain;      /* LFO + channel parameters */
     77 #if (NUM_OUTPUT_CHANNELS == 2)
     78     EAS_U16         gainLeft;       /* left gain multiplier */
     79     EAS_U16         gainRight;      /* right gain multiplier */
     80 #endif
     81     EAS_U8          flags;          /* mode bits and noise waveform flags */
     82     EAS_U8          feedback;       /* feedback for Op1 and Op3 */
     83 } S_FM_ENG_VOICE;
     84 
     85 typedef struct
     86 {
     87     EAS_U16         gain[4];        /* initial operator gain value */
     88     EAS_U16         outputGain[4];  /* initial operator output gain value */
     89     EAS_U16         voiceGain;      /* initial voice gain */
     90     EAS_U8          flags;          /* mode bits and noise waveform flags */
     91     EAS_U8          feedback;       /* feedback for Op1 and Op3 */
     92 #if (NUM_OUTPUT_CHANNELS == 2)
     93     EAS_I8          pan;            /* pan value +/-64 */
     94 #endif
     95 } S_FM_VOICE_CONFIG;
     96 
     97 typedef struct
     98 {
     99     EAS_U16         gain[4];        /* new operator gain value */
    100     EAS_I16         pitch[4];       /* new pitch value */
    101     EAS_U16         voiceGain;      /* new voice gain */
    102 } S_FM_VOICE_FRAME;
    103 
    104 /* bit definitions for S_FM_ENG_VOICE.flags */
    105 #define FLAG_FM_ENG_VOICE_OP1_NOISE     0x10    /* operator 1 source is PRNG */
    106 #define FLAG_FM_ENG_VOICE_OP2_NOISE     0x20    /* operator 2 source is PRNG */
    107 #define FLAG_FM_ENG_VOICE_OP3_NOISE     0x40    /* operator 3 source is PRNG */
    108 #define FLAG_FM_ENG_VOICE_OP4_NOISE     0x80    /* operator 4 source is PRNG */
    109 
    110 #ifdef FM_OFFBOARD
    111 extern EAS_BOOL FM_StartFrame (EAS_FRAME_BUFFER_HANDLE pFrameBuffer);
    112 extern EAS_BOOL FM_EndFrame (EAS_FRAME_BUFFER_HANDLE pFrameBuffe, EAS_I32 *pMixBuffer, EAS_I16 masterGain);
    113 #endif
    114 
    115 /* FM engine prototypes */
    116 extern void FM_ConfigVoice (EAS_I32 voiceNum, S_FM_VOICE_CONFIG *vCfg, EAS_FRAME_BUFFER_HANDLE pFrameBuffer);
    117 extern void FM_ProcessVoice (EAS_I32 voiceNum, S_FM_VOICE_FRAME *pFrame, EAS_I32 numSamplesToAdd, EAS_PCM *pTempBuffer, EAS_PCM *pBuffer, EAS_I32 *pMixBuffer, EAS_FRAME_BUFFER_HANDLE pFrameBuffer);
    118 
    119 #endif
    120 /* #ifndef _FMENGINE_H */
    121 
    122