156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * File: 456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * eas_wtengine.h 556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Contents and purpose: 756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This file defines the interface for wavetable synthesis engine 856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Copyright Sonic Network Inc. 2004 107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * you may not use this file except in compliance with the License. 137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * You may obtain a copy of the License at 147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 157df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 187df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 197df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * See the License for the specific language governing permissions and 217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * limitations under the License. 2256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 2356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 2456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Revision Control: 2556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * $Revision: 818 $ 2656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * $Date: 2007-08-02 15:19:41 -0700 (Thu, 02 Aug 2007) $ 2756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 2856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 2956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifndef _EAS_WTENGINE_H 3156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define _EAS_WTENGINE_H 3256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* option sanity check */ 3456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if defined(_OPTIMIZED_MONO) && defined(_FILTER_ENABLED) 3556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#error "Incompatible build settings: _OPTIMIZED_MONO cannot be used with _FILTER_ENABLED" 3656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 3756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if defined(_OPTIMIZED_MONO) && (NUM_OUTPUT_CHANNELS != 1) 3956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#error "Incompatible build settings: _OPTIMIZED_MONO can only be used with NUM_OUTPUT_CHANNELS = 1" 4056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 4156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 4256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#include "eas_wt_IPC_frame.h" 4356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 4456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 4556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * defines 4656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 4756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 4856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WT_NOISE_GENERATOR 0xffffffff 4956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 5056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 5156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * typedefs 5256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 5356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 5456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 5556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 5656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * S_WT_INT_FRAME 5756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 5856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This structure includes S_WT_FRAME plus the bus mixing 5956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * parameters for the internal voices. 6056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 6156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 6256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparkstypedef struct s_wt_int_frame_tag 6356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{ 6456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_FRAME frame; 6556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_PCM *pAudioBuffer; 6656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 *pMixBuffer; 6756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 numSamples; 6856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 prevGain; 6956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks} S_WT_INT_FRAME; 7056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 7156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if defined(_FILTER_ENABLED) 7256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 7356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * S_FILTER_CONTROL data structure 7456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 7556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 7656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparkstypedef struct s_filter_control_tag 7756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{ 7856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 z1; /* 1 sample delay state variable */ 7956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 z2; /* 2 sample delay state variable */ 8056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks} S_FILTER_CONTROL; 8156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 8256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 8356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*------------------------------------ 8456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * S_LFO_CONTROL data structure 8556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *------------------------------------ 8656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 8756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparkstypedef struct s_lfo_control_tag 8856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{ 8956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 lfoValue; /* LFO current output value */ 9056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 lfoPhase; /* LFO current phase */ 9156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks} S_LFO_CONTROL; 9256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 9356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* bit definitions for S_WT_VOICE:flags */ 9456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WT_FLAGS_ADPCM_NIBBLE 1 /* high/low nibble flag */ 9556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WT_FLAGS_ADPCM_READY 2 /* first 2 samples are decoded */ 9656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define WT_FLAGS_USE_ADPCM 4 /* sample is ADPCM encoded */ 9756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 9856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/* eg1State and eg2State */ 9956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparkstypedef enum { 10056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateInit = 0, 10156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateDelay, 10256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateAttack, 10356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateHold, 10456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateDecay, 10556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateSustain, 10656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateRelease, 10756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateMuting, 10856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateMuted, 10956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks eEnvelopeStateInvalid /* should never be in this state! */ 11056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks} E_ENVELOPE_STATE; 11156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 11256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_EG1_STATE eEnvelopeStateAttack 11356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_EG1_VALUE 0 11456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_EG1_INCREMENT 0 11556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_EG2_STATE eEnvelopeStateAttack 11656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_EG2_VALUE 0 11756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#define DEFAULT_EG2_INCREMENT 0 11856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 11956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 12056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * S_WT_VOICE 12156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 12256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * This structure contains state data for the wavetable engine 12356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 12456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 12556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparkstypedef struct s_wt_voice_tag 12656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks{ 12756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U32 loopEnd; /* points to last PCM sample (not 1 beyond last) */ 12856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U32 loopStart; /* points to first sample at start of loop */ 12956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U32 phaseAccum; /* current sample, integer portion of phase */ 13056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U32 phaseFrac; /* fractional portion of phase */ 13156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 13256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2) 13356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 gainLeft; /* current gain, left ch */ 13456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 gainRight; /* current gain, right ch */ 13556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 13656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 13756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if defined(_FILTER_ENABLED) 13856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_FILTER_CONTROL filter; /* low pass filter */ 13956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 14056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 14156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_LFO_CONTROL modLFO; /* modulator LFO */ 14256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 14356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef DLS_SYNTHESIZER 14456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_LFO_CONTROL vibLFO; /* vibrato LFO */ 14556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 14656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 14756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* envelope control */ 14856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 eg1Value; 14956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 eg2Value; 15056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 eg1Increment; 15156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I16 eg2Increment; 15256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U8 eg1State; 15356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U8 eg2State; 15456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 15556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U16 artIndex; /* index to articulation params */ 15656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 15756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks} S_WT_VOICE; 15856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 15956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks/*---------------------------------------------------------------------------- 16056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * prototypes 16156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks *---------------------------------------------------------------------------- 16256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks*/ 16356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave SparksEAS_BOOL WT_CheckSampleEnd (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame, EAS_BOOL update); 16456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksvoid WT_ProcessVoice (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame); 16556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 16656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef EAS_SPLIT_WT_SYNTH 16756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksvoid WTE_ConfigVoice (EAS_I32 voiceNum, S_WT_CONFIG *pWTConfig, EAS_FRAME_BUFFER_HANDLE pFrameBuffer); 16856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksvoid WTE_ProcessVoice (EAS_I32 voiceNum, S_WT_FRAME *pWTParams, EAS_FRAME_BUFFER_HANDLE pFrameBuffer); 16956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 17056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 17156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 172