17df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 27df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 37df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * File: 47df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * eas_wtsynth.c 57df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 67df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Contents and purpose: 77df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Implements the synthesizer functions. 87df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 97df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 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. 227df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 237df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 247df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Revision Control: 257df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * $Revision: 795 $ 267df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * $Date: 2007-08-01 00:14:45 -0700 (Wed, 01 Aug 2007) $ 277df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 287df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 297df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 307df30109963092559d3760c0661a020f9daf1030The Android Open Source Project// includes 317df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_data.h" 327df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_report.h" 337df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_host.h" 347df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_math.h" 357df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_synth_protos.h" 367df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_wtsynth.h" 377df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_pan.h" 387df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 397df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef DLS_SYNTHESIZER 407df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_dlssynth.h" 417df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 437df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _METRICS_ENABLED 447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#include "eas_perf.h" 457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 467df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/* local prototypes */ 487df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_RESULT WT_Initialize(S_VOICE_MGR *pVoiceMgr); 497df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_ReleaseVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum); 507df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_MuteVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum); 517df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_SustainPedal (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, S_SYNTH_CHANNEL *pChannel, EAS_I32 voiceNum); 527df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_RESULT WT_StartVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum, EAS_U16 regionIndex); 537df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_BOOL WT_UpdateVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum, EAS_I32 *pMixBuffer, EAS_I32 numSamples); 547df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateChannel (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, EAS_U8 channel); 557df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_I32 WT_UpdatePhaseInc (S_WT_VOICE *pWTVoice, const S_ARTICULATION *pArt, S_SYNTH_CHANNEL *pChannel, EAS_I32 pitchCents); 567df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_I32 WT_UpdateGain (S_SYNTH_VOICE *pVoice, S_WT_VOICE *pWTVoice, const S_ARTICULATION *pArt, S_SYNTH_CHANNEL *pChannel, EAS_I32 gain); 577df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateEG1 (S_WT_VOICE *pWTVoice, const S_ENVELOPE *pEnv); 587df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateEG2 (S_WT_VOICE *pWTVoice, const S_ENVELOPE *pEnv); 597df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef EAS_SPLIT_WT_SYNTH 617df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern EAS_BOOL WTE_StartFrame (EAS_FRAME_BUFFER_HANDLE pFrameBuffer); 627df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern EAS_BOOL WTE_EndFrame (EAS_FRAME_BUFFER_HANDLE pFrameBuffer, EAS_I32 *pMixBuffer, EAS_I16 masterGain); 637df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 647df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 657df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _FILTER_ENABLED 667df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateFilter (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pIntFrame, const S_ARTICULATION *pArt); 677df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 687df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 697df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _STATS 707df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern double statsPhaseIncrement; 717df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern double statsMaxPhaseIncrement; 727df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern long statsPhaseSampleCount; 737df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern double statsSampleSize; 747df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectextern long statsSampleCount; 757df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 767df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 777df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 787df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Synthesizer interface 797df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 807df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 817df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 8256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksconst S_SYNTH_INTERFACE wtSynth = 837df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 8456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_Initialize, 8556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_StartVoice, 8656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateVoice, 8756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_ReleaseVoice, 8856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_MuteVoice, 8956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_SustainPedal, 9056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateChannel 917df30109963092559d3760c0661a020f9daf1030The Android Open Source Project}; 927df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 937df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef EAS_SPLIT_WT_SYNTH 947df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectconst S_FRAME_INTERFACE wtFrameInterface = 957df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 9656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WTE_StartFrame, 9756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WTE_EndFrame 987df30109963092559d3760c0661a020f9daf1030The Android Open Source Project}; 997df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 1007df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1017df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 1027df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_Initialize() 1037df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 1047df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Purpose: 1057df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 1067df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Inputs: 1077df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - pointer to voice to initialize 1087df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 1097df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 1107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 1117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 1127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 1137df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_RESULT WT_Initialize (S_VOICE_MGR *pVoiceMgr) 1147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 11556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_INT i; 1167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 11756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks for (i = 0; i < NUM_WT_VOICES; i++) 11856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 1197df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 12056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].artIndex = DEFAULT_ARTICULATION_INDEX; 1217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 12256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].eg1State = DEFAULT_EG1_STATE; 12356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].eg1Value = DEFAULT_EG1_VALUE; 12456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].eg1Increment = DEFAULT_EG1_INCREMENT; 1257df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 12656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].eg2State = DEFAULT_EG2_STATE; 12756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].eg2Value = DEFAULT_EG2_VALUE; 12856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].eg2Increment = DEFAULT_EG2_INCREMENT; 1297df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 13056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* left and right gain values are needed only if stereo output */ 13156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#if (NUM_OUTPUT_CHANNELS == 2) 13256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].gainLeft = DEFAULT_VOICE_GAIN; 13356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].gainRight = DEFAULT_VOICE_GAIN; 1347df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 1357df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 13656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].phaseFrac = DEFAULT_PHASE_FRAC; 13756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].phaseAccum = DEFAULT_PHASE_INT; 1387df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1397df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _FILTER_ENABLED 14056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].filter.z1 = DEFAULT_FILTER_ZERO; 14156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoiceMgr->wtVoices[i].filter.z2 = DEFAULT_FILTER_ZERO; 1427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 14356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 1447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 14556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return EAS_TRUE; 1467df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 1477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1487df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 1497df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_ReleaseVoice() 1507df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 1517df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Purpose: 1527df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * The selected voice is being released. 1537df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 1547df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Inputs: 1557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to S_EAS_DATA 1567df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - pointer to voice to release 1577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 1587df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 1597df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * None 1607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 1617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 1627df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*lint -esym(715, pVoice) used in some implementations */ 1637df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_ReleaseVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum) 1647df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 16556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_VOICE *pWTVoice; 16656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks const S_ARTICULATION *pArticulation; 16756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1687df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef DLS_SYNTHESIZER 16956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pVoice->regionIndex & FLAG_RGN_IDX_DLS_SYNTH) 17056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 17156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks DLS_ReleaseVoice(pVoiceMgr, pSynth, pVoice, voiceNum); 17256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 17356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 1747df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 1757df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 17656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice = &pVoiceMgr->wtVoices[voiceNum]; 17756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pArticulation = &pSynth->pEAS->pArticulations[pWTVoice->artIndex]; 17856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1797df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* release EG1 */ 1807df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pWTVoice->eg1State = eEnvelopeStateRelease; 1817df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pWTVoice->eg1Increment = pArticulation->eg1.releaseTime; 1827df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1837df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* 1847df30109963092559d3760c0661a020f9daf1030The Android Open Source Project The spec says we should release EG2, but doing so with the current 1857df30109963092559d3760c0661a020f9daf1030The Android Open Source Project voicing is causing clicks. This fix will need to be coordinated with 1867df30109963092559d3760c0661a020f9daf1030The Android Open Source Project a new sound library release 1877df30109963092559d3760c0661a020f9daf1030The Android Open Source Project */ 1887df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1897df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* release EG2 */ 1907df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pWTVoice->eg2State = eEnvelopeStateRelease; 1917df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pWTVoice->eg2Increment = pArticulation->eg2.releaseTime; 1927df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 1937df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1947df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 1957df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_MuteVoice() 1967df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 1977df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Purpose: 1987df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * The selected voice is being muted. 1997df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 2007df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Inputs: 2017df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - pointer to voice to release 2027df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 2037df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 2047df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * None 2057df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 2067df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 2077df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*lint -esym(715, pSynth) used in some implementations */ 2087df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_MuteVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum) 2097df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 2107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 2117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef DLS_SYNTHESIZER 21256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pVoice->regionIndex & FLAG_RGN_IDX_DLS_SYNTH) 21356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 21456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks DLS_MuteVoice(pVoiceMgr, pSynth, pVoice, voiceNum); 21556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 21656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 2177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 2187df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 21956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* clear deferred action flags */ 22056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->voiceFlags &= 22156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks ~(VOICE_FLAG_DEFER_MIDI_NOTE_OFF | 22256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks VOICE_FLAG_SUSTAIN_PEDAL_DEFER_NOTE_OFF | 22356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks VOICE_FLAG_DEFER_MUTE); 22456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 22556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* set the envelope state */ 2267df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pVoiceMgr->wtVoices[voiceNum].eg1State = eEnvelopeStateMuted; 2277df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pVoiceMgr->wtVoices[voiceNum].eg2State = eEnvelopeStateMuted; 2287df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 2297df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 2307df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 2317df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_SustainPedal() 2327df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 2337df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Purpose: 2347df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * The selected voice is held due to sustain pedal 2357df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 2367df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Inputs: 2377df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - pointer to voice to sustain 2387df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 2397df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 2407df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * None 2417df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 2427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 2437df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*lint -esym(715, pChannel) used in some implementations */ 2447df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_SustainPedal (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, S_SYNTH_CHANNEL *pChannel, EAS_I32 voiceNum) 2457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 24656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_VOICE *pWTVoice; 2477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 2487df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef DLS_SYNTHESIZER 24956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pVoice->regionIndex & FLAG_RGN_IDX_DLS_SYNTH) 25056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 25156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks DLS_SustainPedal(pVoiceMgr, pSynth, pVoice, pChannel, voiceNum); 25256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 25356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 2547df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 2557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 25656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* don't catch the voice if below the sustain level */ 25756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice = &pVoiceMgr->wtVoices[voiceNum]; 25856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pWTVoice->eg1Value < pSynth->pEAS->pArticulations[pWTVoice->artIndex].eg1.sustainLevel) 25956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 26056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* sustain flag is set, damper pedal is on */ 2627df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* defer releasing this note until the damper pedal is off */ 2637df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pWTVoice->eg1State = eEnvelopeStateDecay; 26456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->voiceState = eVoiceStatePlay; 2657df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 2667df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* 2677df30109963092559d3760c0661a020f9daf1030The Android Open Source Project because sustain pedal is on, this voice 2687df30109963092559d3760c0661a020f9daf1030The Android Open Source Project should defer releasing its note 2697df30109963092559d3760c0661a020f9daf1030The Android Open Source Project */ 2707df30109963092559d3760c0661a020f9daf1030The Android Open Source Project pVoice->voiceFlags |= VOICE_FLAG_SUSTAIN_PEDAL_DEFER_NOTE_OFF; 2717df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 2727df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _DEBUG_SYNTH 2737df30109963092559d3760c0661a020f9daf1030The Android Open Source Project { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WT_SustainPedal: defer note off because sustain pedal is on\n"); */ } 2747df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 2757df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 2767df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 2777df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 2787df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_StartVoice() 2797df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 28056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 2817df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Assign the region for the given instrument using the midi key number 28256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * and the RPN2 (coarse tuning) value. By using RPN2 as part of the 2837df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * region selection process, we reduce the amount a given sample has 2847df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * to be transposed by selecting the closest recorded root instead. 2857df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 2867df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * This routine is the second half of SynthAssignRegion(). 2877df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * If the region was successfully found by SynthFindRegionIndex(), 2887df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * then assign the region's parameters to the voice. 2897df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 2907df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Setup and initialize the following voice parameters: 2917df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * m_nRegionIndex 2927df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 29356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 2947df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - ptr to the voice we have assigned for this channel 2957df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * nRegionIndex - index of the region 2967df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 29756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 2987df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 2997df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * success - could find and assign the region for this voice's note otherwise 30056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * failure - could not find nor assign the region for this voice's note 3017df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 3027df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 3037df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * psSynthObject->m_sVoice[].m_nRegionIndex is assigned 3047df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * psSynthObject->m_sVoice[] parameters are assigned 3057df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 3067df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 3077df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_RESULT WT_StartVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum, EAS_U16 regionIndex) 3087df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 30956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_VOICE *pWTVoice; 31056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks const S_WT_REGION *pRegion; 31156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks const S_ARTICULATION *pArt; 31256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_SYNTH_CHANNEL *pChannel; 31356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#if (NUM_OUTPUT_CHANNELS == 2) 31556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_INT pan; 3167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 3177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 3187df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef EAS_SPLIT_WT_SYNTH 31956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_CONFIG wtConfig; 3207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 3217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 32256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* no samples have been synthesized for this note yet */ 32356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->regionIndex = regionIndex; 32456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->voiceFlags = VOICE_FLAG_NO_SAMPLES_SYNTHESIZED_YET; 32556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 32656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* get the articulation index for this region */ 32756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice = &pVoiceMgr->wtVoices[voiceNum]; 32856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel = &pSynth->channels[pVoice->channel & 15]; 3297df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 33056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* update static channel parameters */ 33156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pChannel->channelFlags & CHANNEL_FLAG_UPDATE_CHANNEL_PARAMETERS) 33256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateChannel(pVoiceMgr, pSynth, pVoice->channel & 15); 3337df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 3347df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef DLS_SYNTHESIZER 33556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pVoice->regionIndex & FLAG_RGN_IDX_DLS_SYNTH) 33656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return DLS_StartVoice(pVoiceMgr, pSynth, pVoice, voiceNum, regionIndex); 3377df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 3387df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 33956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pRegion = &(pSynth->pEAS->pWTRegions[regionIndex]); 34056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->artIndex = pRegion->artIndex; 3417df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 3427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _DEBUG_SYNTH 34356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WT_StartVoice: Voice %ld; Region %d\n", (EAS_I32) (pVoice - pVoiceMgr->voices), regionIndex); */ } 3447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 3457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 34656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pArt = &pSynth->pEAS->pArticulations[pWTVoice->artIndex]; 3477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 34856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* MIDI note on puts this voice into attack state */ 34956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1State = eEnvelopeStateAttack; 35056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1Value = 0; 35156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1Increment = pArt->eg1.attackTime; 35256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2State = eEnvelopeStateAttack; 35356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2Value = 0; 35456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2Increment = pArt->eg2.attackTime; 3557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 35656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* init the LFO */ 35756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->modLFO.lfoValue = 0; 35856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->modLFO.lfoPhase = -pArt->lfoDelay; 3597df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 36056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->gain = 0; 3617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 3627df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#if (NUM_OUTPUT_CHANNELS == 2) 36356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* 36456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks Get the Midi CC10 pan value for this voice's channel 36556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks convert the pan value to an "angle" representation suitable for 36656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks our sin, cos calculator. This representation is NOT necessarily the same 36756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks as the transform in the GM manuals because of our sin, cos calculator. 36856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks "angle" = (CC10 - 64)/128 36956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 37056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pan = (EAS_INT) pSynth->channels[pVoice->channel & 15].pan - 64; 37156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pan += pArt->pan; 37256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_CalcPanControl(pan, &pWTVoice->gainLeft, &pWTVoice->gainRight); 37356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 37456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 37556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _FILTER_ENABLED 37656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* clear out the filter states */ 37756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->filter.z1 = 0; 37856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->filter.z2 = 0; 3797df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 3807df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 38156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* if this wave is to be generated using noise generator */ 38256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pRegion->region.keyGroupAndFlags & REGION_FLAG_USE_WAVE_GENERATOR) 38356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 38456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->phaseAccum = 4574296; 38556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->loopStart = WT_NOISE_GENERATOR; 38656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->loopEnd = 4574295; 38756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 38856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 38956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* normal sample */ 39056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 39156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 39256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3937df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef EAS_SPLIT_WT_SYNTH 39456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (voiceNum < NUM_PRIMARY_VOICES) 39556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->phaseAccum = (EAS_U32) pSynth->pEAS->pSamples + pSynth->pEAS->pSampleOffsets[pRegion->waveIndex]; 39656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 39756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->phaseAccum = pSynth->pEAS->pSampleOffsets[pRegion->waveIndex]; 3987df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#else 39956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->phaseAccum = (EAS_U32) pSynth->pEAS->pSamples + pSynth->pEAS->pSampleOffsets[pRegion->waveIndex]; 4007df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 4017df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 40256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pRegion->region.keyGroupAndFlags & REGION_FLAG_IS_LOOPED) 40356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 40456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->loopStart = pWTVoice->phaseAccum + pRegion->loopStart; 40556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->loopEnd = pWTVoice->phaseAccum + pRegion->loopEnd - 1; 40656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 40756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 40856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->loopStart = pWTVoice->loopEnd = pWTVoice->phaseAccum + pSynth->pEAS->pSampleLen[pRegion->waveIndex] - 1; 40956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 4107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 4117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef EAS_SPLIT_WT_SYNTH 41256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* configure off-chip voices */ 41356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (voiceNum >= NUM_PRIMARY_VOICES) 41456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 41556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks wtConfig.phaseAccum = pWTVoice->phaseAccum; 41656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks wtConfig.loopStart = pWTVoice->loopStart; 41756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks wtConfig.loopEnd = pWTVoice->loopEnd; 41856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks wtConfig.gain = pVoice->gain; 41956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 4207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#if (NUM_OUTPUT_CHANNELS == 2) 42156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks wtConfig.gainLeft = pWTVoice->gainLeft; 42256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks wtConfig.gainRight = pWTVoice->gainRight; 4237df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 4247df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 42556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WTE_ConfigVoice(voiceNum - NUM_PRIMARY_VOICES, &wtConfig, pVoiceMgr->pFrameBuffer); 42656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 4277df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 4287df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 42956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return EAS_SUCCESS; 4307df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 4317df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 4327df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 4337df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_CheckSampleEnd 4347df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 43556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 4367df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Check for end of sample and calculate number of samples to synthesize 43756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 43856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 43956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 4407df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 4417df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 4427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Notes: 4437df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 4447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 4457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 4467df30109963092559d3760c0661a020f9daf1030The Android Open Source ProjectEAS_BOOL WT_CheckSampleEnd (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame, EAS_BOOL update) 4477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 44856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U32 endPhaseAccum; 44956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_U32 endPhaseFrac; 45056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 numSamples; 45156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_BOOL done = EAS_FALSE; 45256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 45356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* check to see if we hit the end of the waveform this time */ 45456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /*lint -e{703} use shift for performance */ 45556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks endPhaseFrac = pWTVoice->phaseFrac + (pWTIntFrame->frame.phaseIncrement << SYNTH_UPDATE_PERIOD_IN_BITS); 45656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks endPhaseAccum = pWTVoice->phaseAccum + GET_PHASE_INT_PART(endPhaseFrac); 45756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (endPhaseAccum >= pWTVoice->loopEnd) 45856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 45956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate how far current ptr is from end */ 46056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks numSamples = (EAS_I32) (pWTVoice->loopEnd - pWTVoice->phaseAccum); 46156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 46256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* now account for the fractional portion */ 46356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /*lint -e{703} use shift for performance */ 46456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks numSamples = (EAS_I32) ((numSamples << NUM_PHASE_FRAC_BITS) - pWTVoice->phaseFrac); 46556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pWTIntFrame->frame.phaseIncrement) { 46656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTIntFrame->numSamples = 1 + (numSamples / pWTIntFrame->frame.phaseIncrement); 46756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } else { 46856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTIntFrame->numSamples = numSamples; 46956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 47056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 47156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* sound will be done this frame */ 47256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks done = EAS_TRUE; 47356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 47456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 47556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* update data for off-chip synth */ 47656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (update) 47756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 47856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->phaseFrac = endPhaseFrac; 47956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->phaseAccum = endPhaseAccum; 48056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 48156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 48256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return done; 4837df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 4847df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 4857df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 4867df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateVoice() 4877df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 48856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 4897df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Synthesize a block of samples for the given voice. 4907df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Use linear interpolation. 4917df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 49256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 4937df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 49456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 4957df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 4967df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * number of samples actually written to buffer 4977df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 4987df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 4997df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - samples are added to the presently free buffer 5007df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 5017df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 5027df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 5037df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_BOOL WT_UpdateVoice (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, S_SYNTH_VOICE *pVoice, EAS_I32 voiceNum, EAS_I32 *pMixBuffer, EAS_I32 numSamples) 5047df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 50556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_VOICE *pWTVoice; 50656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_WT_INT_FRAME intFrame; 50756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_SYNTH_CHANNEL *pChannel; 50856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks const S_WT_REGION *pWTRegion; 50956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks const S_ARTICULATION *pArt; 51056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 temp; 51156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_BOOL done; 5127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 5137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef DLS_SYNTHESIZER 51456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pVoice->regionIndex & FLAG_RGN_IDX_DLS_SYNTH) 51556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return DLS_UpdateVoice(pVoiceMgr, pSynth, pVoice, voiceNum, pMixBuffer, numSamples); 51656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#endif 5177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 51856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* establish pointers to critical data */ 51956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice = &pVoiceMgr->wtVoices[voiceNum]; 52056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTRegion = &pSynth->pEAS->pWTRegions[pVoice->regionIndex & REGION_INDEX_MASK]; 52156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pArt = &pSynth->pEAS->pArticulations[pWTVoice->artIndex]; 52256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel = &pSynth->channels[pVoice->channel & 15]; 52356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.prevGain = pVoice->gain; 5247df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 52556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* update the envelopes */ 52656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateEG1(pWTVoice, &pArt->eg1); 52756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateEG2(pWTVoice, &pArt->eg2); 5287df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 52956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* update the LFO */ 53056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateLFO(&pWTVoice->modLFO, pArt->lfoFreq); 5317df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 5327df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _FILTER_ENABLED 53356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate filter if library uses filter */ 53456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pSynth->pEAS->libAttr & LIB_FORMAT_FILTER_ENABLED) 53556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_UpdateFilter(pWTVoice, &intFrame, pArt); 53656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 53756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.frame.k = 0; 5387df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 5397df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 54056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* update the gain */ 54156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.frame.gainTarget = WT_UpdateGain(pVoice, pWTVoice, pArt, pChannel, pWTRegion->gain); 5427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 54356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate base pitch*/ 54456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pChannel->staticPitch + pWTRegion->tuning; 5457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 54656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* include global transpose */ 54756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pChannel->channelFlags & CHANNEL_FLAG_RHYTHM_CHANNEL) 54856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp += pVoice->note * 100; 54956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 55056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp += (pVoice->note + pSynth->globalTranspose) * 100; 55156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.frame.phaseIncrement = WT_UpdatePhaseInc(pWTVoice, pArt, pChannel, temp); 5527df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 55356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* call into engine to generate samples */ 55456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.pAudioBuffer = pVoiceMgr->voiceBuffer; 55556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.pMixBuffer = pMixBuffer; 55656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks intFrame.numSamples = numSamples; 5577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 55856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* check for end of sample */ 55956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if ((pWTVoice->loopStart != WT_NOISE_GENERATOR) && (pWTVoice->loopStart == pWTVoice->loopEnd)) 56056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks done = WT_CheckSampleEnd(pWTVoice, &intFrame, (EAS_BOOL) (voiceNum >= NUM_PRIMARY_VOICES)); 56156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 56256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks done = EAS_FALSE; 5637df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 56456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (intFrame.numSamples < 0) intFrame.numSamples = 0; 5657df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 5667df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef EAS_SPLIT_WT_SYNTH 56756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (voiceNum < NUM_PRIMARY_VOICES) 56856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 56956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifndef _SPLIT_WT_TEST_HARNESS 57056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_ProcessVoice(pWTVoice, &intFrame); 5717df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 57256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 57356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 57456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WTE_ProcessVoice(voiceNum - NUM_PRIMARY_VOICES, &intFrame.frame, pVoiceMgr->pFrameBuffer); 5757df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#else 57656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_ProcessVoice(pWTVoice, &intFrame); 5777df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 5787df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 57956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* clear flag */ 58056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->voiceFlags &= ~VOICE_FLAG_NO_SAMPLES_SYNTHESIZED_YET; 5817df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 5827df30109963092559d3760c0661a020f9daf1030The Android Open Source Project /* if voice has finished, set flag for voice manager */ 58356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if ((pVoice->voiceState != eVoiceStateStolen) && (pWTVoice->eg1State == eEnvelopeStateMuted)) 58456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks done = EAS_TRUE; 5857df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 58656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* if the update interval has elapsed, then force the current gain to the next 58756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * gain since we never actually reach the next gain when ramping -- we just get 58856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * very close to the target gain. 58956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 59056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pVoice->gain = (EAS_I16) intFrame.frame.gainTarget; 5917df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 59256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return done; 59356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks} 5947df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 5957df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 5967df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdatePhaseInc() 5977df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 59856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 5997df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Calculate the phase increment 6007df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 60156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 6027df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - pointer to the voice being updated 6037df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * psRegion - pointer to the region 6047df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * psArticulation - pointer to the articulation 6057df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * nChannelPitchForThisVoice - the portion of the pitch that is fixed for this 60656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * voice during the duration of this synthesis 6077df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 6087df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 6097df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 6107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 6117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 6127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * set the phase increment for this voice 6137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 6147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 6157df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_I32 WT_UpdatePhaseInc (S_WT_VOICE *pWTVoice, const S_ARTICULATION *pArt, S_SYNTH_CHANNEL *pChannel, EAS_I32 pitchCents) 6167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 61756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 temp; 61856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 61956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /*pitchCents due to CC1 = LFO * (CC1 / 128) * DEFAULT_LFO_MOD_WHEEL_TO_PITCH_CENTS */ 62056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(DEFAULT_LFO_MOD_WHEEL_TO_PITCH_CENTS, 62156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks ((pChannel->modWheel) << (NUM_EG1_FRAC_BITS -7))); 62256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 62356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* pitchCents due to channel pressure = LFO * (channel pressure / 128) * DEFAULT_LFO_CHANNEL_PRESSURE_TO_PITCH_CENTS */ 62456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp += MULT_EG1_EG1(DEFAULT_LFO_CHANNEL_PRESSURE_TO_PITCH_CENTS, 62556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks ((pChannel->channelPressure) << (NUM_EG1_FRAC_BITS -7))); 62656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 62756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* now multiply the (channel pressure + CC1) pitch values by the LFO value */ 62856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(pWTVoice->modLFO.lfoValue, temp); 62956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 63056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* 63156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks add in the LFO pitch due to 63256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks channel pressure and CC1 along with 63356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks the LFO pitch, the EG2 pitch, and the 63456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks "static" pitch for this voice on this channel 63556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 63656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp += pitchCents + 63756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks (MULT_EG1_EG1(pWTVoice->eg2Value, pArt->eg2ToPitch)) + 63856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks (MULT_EG1_EG1(pWTVoice->modLFO.lfoValue, pArt->lfoToPitch)); 63956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 64056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* convert from cents to linear phase increment */ 64156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return EAS_Calculate2toX(temp); 6427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 6437df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 6447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 6457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateChannel() 6467df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 64756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 6487df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Calculate and assign static channel parameters 6497df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * These values only need to be updated if one of the controller values 6507df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * for this channel changes 6517df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 65256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 6537df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * nChannel - channel to update 6547df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 65556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 6567df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 6577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 6587df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 6597df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - the given channel's static gain and static pitch are updated 6607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 6617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 6627df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*lint -esym(715, pVoiceMgr) reserved for future use */ 6637df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateChannel (S_VOICE_MGR *pVoiceMgr, S_SYNTH *pSynth, EAS_U8 channel) 6647df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 66556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 staticGain; 66656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 pitchBend; 66756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks S_SYNTH_CHANNEL *pChannel; 66856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 66956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel = &pSynth->channels[channel]; 67056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 67156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* 67256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks nChannelGain = (CC7 * CC11)^2 * master volume 67356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks where CC7 == 100 by default, CC11 == 127, master volume == 32767 67456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 67556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks staticGain = MULT_EG1_EG1((pChannel->volume) << (NUM_EG1_FRAC_BITS - 7), 67656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks (pChannel->expression) << (NUM_EG1_FRAC_BITS - 7)); 67756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 67856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* staticGain has to be squared */ 67956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks staticGain = MULT_EG1_EG1(staticGain, staticGain); 68056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 68156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel->staticGain = (EAS_I16) MULT_EG1_EG1(staticGain, pSynth->masterVolume); 68256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 68356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* 68456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks calculate pitch bend: RPN0 * ((2*pitch wheel)/16384 -1) 68556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks However, if we use the EG1 macros, remember that EG1 has a full 68656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks scale value of 32768 (instead of 16384). So instead of multiplying 68756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks by 2, multiply by 4 (left shift by 2), and subtract by 32768 instead 68856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks of 16384. This utilizes the fact that the EG1 macro places a binary 68956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks point 15 places to the left instead of 14 places. 69056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 69156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /*lint -e{703} <avoid multiply for performance>*/ 69256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pitchBend = 69356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks (((EAS_I32)(pChannel->pitchBend) << 2) 69456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks - 32768); 69556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 69656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel->staticPitch = 69756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks MULT_EG1_EG1(pitchBend, pChannel->pitchBendSensitivity); 69856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 69956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* if this is not a drum channel, then add in the per-channel tuning */ 70056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (!(pChannel->channelFlags & CHANNEL_FLAG_RHYTHM_CHANNEL)) 70156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel->staticPitch += pChannel->finePitch + (pChannel->coarsePitch * 100); 70256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 70356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* clear update flag */ 70456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pChannel->channelFlags &= ~CHANNEL_FLAG_UPDATE_CHANNEL_PARAMETERS; 70556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 7067df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 7077df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 7087df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 7097df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateGain() 7107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 71156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 7127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Calculate and assign static voice parameters as part of WT_UpdateVoice() 7137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 71456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 71556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pVoice - ptr to the synth voice that we want to synthesize 7167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 71756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * 7187df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 7197df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 7207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 7217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - various voice parameters are calculated and assigned 7227df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 7237df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 7247df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 7257df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic EAS_I32 WT_UpdateGain (S_SYNTH_VOICE *pVoice, S_WT_VOICE *pWTVoice, const S_ARTICULATION *pArt, S_SYNTH_CHANNEL *pChannel, EAS_I32 gain) 7267df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 72756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 lfoGain; 72856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 temp; 72956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 73056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* 73156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks If this voice was stolen, then the velocity is actually 73256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks for the new note, not the note that we are currently ramping down. 73356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks So we really shouldn't use this velocity. However, that would require 73456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks more memory to store the velocity value, and the improvement may 73556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks not be sufficient to warrant the added memory. 73656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 73756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* velocity is fixed at note start for a given voice and must be squared */ 73856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = (pVoice->velocity) << (NUM_EG1_FRAC_BITS - 7); 73956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(temp, temp); 74056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 74156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* region gain is fixed as part of the articulation */ 74256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(temp, gain); 74356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 74456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* include the channel gain */ 74556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(temp, pChannel->staticGain); 74656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 74756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate LFO gain using an approximation for 10^x */ 74856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks lfoGain = MULT_EG1_EG1(pWTVoice->modLFO.lfoValue, pArt->lfoToGain); 74956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks lfoGain = MULT_EG1_EG1(lfoGain, LFO_GAIN_TO_CENTS); 75056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 75156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* convert from a dB-like value to linear gain */ 75256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks lfoGain = EAS_Calculate2toX(lfoGain); 75356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(temp, lfoGain); 75456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 75556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate the voice's gain */ 75656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = (EAS_I16)MULT_EG1_EG1(temp, pWTVoice->eg1Value); 75756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 75856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return temp; 7597df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 7607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 7617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 7627df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateEG1() 7637df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 76456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 7657df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Calculate the EG1 envelope for the given voice (but do not update any 7667df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * state) 7677df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 76856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 7697df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pVoice - ptr to the voice whose envelope we want to update 7707df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * nVoice - this voice's number - used only for debug 7717df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 7727df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 7737df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 7747df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * nValue - the envelope value 7757df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 7767df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 7777df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - updates EG1 state value for the given voice 7787df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 7797df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 7807df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateEG1 (S_WT_VOICE *pWTVoice, const S_ENVELOPE *pEnv) 7817df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 78256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 temp; 78356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 78456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks switch (pWTVoice->eg1State) 78556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 78656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateAttack: 78756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pWTVoice->eg1Value + pWTVoice->eg1Increment; 78856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 78956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* check if we have reached peak amplitude */ 79056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp >= SYNTH_FULL_SCALE_EG1_GAIN) 79156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 79256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* limit the volume */ 79356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = SYNTH_FULL_SCALE_EG1_GAIN; 79456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 79556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* prepare to move to decay state */ 79656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1State = eEnvelopeStateDecay; 79756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1Increment = pEnv->decayTime; 79856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 79956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 80056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 80156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 80256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* exponential decay */ 80356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateDecay: 80456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(pWTVoice->eg1Value, pWTVoice->eg1Increment); 80556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 80656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* check if we have reached sustain level */ 80756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp <= pEnv->sustainLevel) 80856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 80956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* enforce the sustain level */ 81056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pEnv->sustainLevel; 81156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 81256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* if sustain level is zero, skip sustain & release the voice */ 81356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp > 0) 81456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1State = eEnvelopeStateSustain; 81556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 81656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* move to sustain state */ 81756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else 81856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1State = eEnvelopeStateMuted; 81956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 82056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 82156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 82256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 82356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateSustain: 82456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 82556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 82656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateRelease: 82756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_EG1_EG1(pWTVoice->eg1Value, pWTVoice->eg1Increment); 82856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 82956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* if we hit zero, this voice isn't contributing any audio */ 83056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp <= 0) 83156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 83256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = 0; 83356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1State = eEnvelopeStateMuted; 83456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 83556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 83656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 83756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* voice is muted, set target to zero */ 83856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateMuted: 83956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = 0; 84056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 84156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 84256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateInvalid: 84356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks default: 84456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = 0; 84556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _DEBUG_SYNTH 84656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WT_UpdateEG1: error, %d is an unrecognized state\n", 84756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1State); */ } 8487df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 84956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 8507df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 85156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 8527df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 85356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg1Value = (EAS_I16) temp; 8547df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 8557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 8567df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 8577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateEG2() 8587df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 85956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 8607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Update the EG2 envelope for the given voice 8617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 86256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 86356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pVoice - ptr to the voice whose envelope we want to update 8647df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 8657df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 8667df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 8677df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 8687df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 8697df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - updates EG2 values for the given voice 8707df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 8717df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 8727df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 8737df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateEG2 (S_WT_VOICE *pWTVoice, const S_ENVELOPE *pEnv) 8747df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 87556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 temp; 87656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 87756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks switch (pWTVoice->eg2State) 87856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 87956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateAttack: 88056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pWTVoice->eg2Value + pWTVoice->eg2Increment; 88156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 88256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* check if we have reached peak amplitude */ 88356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp >= SYNTH_FULL_SCALE_EG1_GAIN) 88456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 88556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* limit the volume */ 88656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = SYNTH_FULL_SCALE_EG1_GAIN; 88756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 88856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* prepare to move to decay state */ 88956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2State = eEnvelopeStateDecay; 89056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 89156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2Increment = pEnv->decayTime; 89256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 89356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 89456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 89556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 89656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* implement linear pitch decay in cents */ 89756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateDecay: 89856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pWTVoice->eg2Value -pWTVoice->eg2Increment; 89956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 90056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* check if we have reached sustain level */ 90156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp <= pEnv->sustainLevel) 90256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 90356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* enforce the sustain level */ 90456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pEnv->sustainLevel; 90556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 90656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* prepare to move to sustain state */ 90756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2State = eEnvelopeStateSustain; 90856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 90956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 91056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 91156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateSustain: 91256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 91356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 91456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateRelease: 91556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = pWTVoice->eg2Value - pWTVoice->eg2Increment; 91656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 91756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (temp <= 0) 91856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 91956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = 0; 92056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2State = eEnvelopeStateMuted; 92156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 92256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 92356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 92456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 92556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* voice is muted, set target to zero */ 92656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateMuted: 92756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = 0; 92856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 92956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 93056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks case eEnvelopeStateInvalid: 93156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks default: 93256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = 0; 93356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks#ifdef _DEBUG_SYNTH 93456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { /* dpp: EAS_ReportEx(_EAS_SEVERITY_INFO, "WT_UpdateEG2: error, %d is an unrecognized state\n", 93556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2State); */ } 9367df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 93756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks break; 93856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 93956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 94056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pWTVoice->eg2Value = (EAS_I16) temp; 9417df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 9427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 9437df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 9447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateLFO () 9457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 94656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 9477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Calculate the LFO for the given voice 9487df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 94956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 95056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pLFO - ptr to the LFO data 95156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * phaseInc - phase increment 9527df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 9537df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 9547df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 9557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 9567df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - updates LFO values for the given voice 9577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 9587df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 9597df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectvoid WT_UpdateLFO (S_LFO_CONTROL *pLFO, EAS_I16 phaseInc) 9607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 9617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 96256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* To save memory, if m_nPhaseValue is negative, we are in the 96356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * delay phase, and m_nPhaseValue represents the time left 96456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * in the delay. 96556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 96656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pLFO->lfoPhase < 0) 96756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 96856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pLFO->lfoPhase++; 96956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 97056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 97156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 97256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate LFO output from phase value */ 97356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /*lint -e{701} Use shift for performance */ 97456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pLFO->lfoValue = (EAS_I16) (pLFO->lfoPhase << 2); 97556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /*lint -e{502} <shortcut to turn sawtooth into triangle wave> */ 97656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if ((pLFO->lfoPhase > 0x1fff) && (pLFO->lfoPhase < 0x6000)) 97756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pLFO->lfoValue = ~pLFO->lfoValue; 97856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 97956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* update LFO phase */ 98056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pLFO->lfoPhase = (pLFO->lfoPhase + phaseInc) & 0x7fff; 9817df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 9827df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 9837df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#ifdef _FILTER_ENABLED 9847df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 9857df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_UpdateFilter() 9867df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 98756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 9887df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Update the Filter parameters 9897df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 99056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 99156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pVoice - ptr to the voice whose filter we want to update 9927df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 9937df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 9947df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 9957df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 9967df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 9977df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - updates Filter values for the given voice 9987df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 9997df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 10007df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic void WT_UpdateFilter (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pIntFrame, const S_ARTICULATION *pArt) 10017df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 100256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 cutoff; 10037df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 100456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* no need to calculate filter coefficients if it is bypassed */ 100556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (pArt->filterCutoff == DEFAULT_EAS_FILTER_CUTOFF_FREQUENCY) 100656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks { 100756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pIntFrame->frame.k = 0; 100856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks return; 100956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks } 10107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 101156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* determine the dynamic cutoff frequency */ 101256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks cutoff = MULT_EG1_EG1(pWTVoice->eg2Value, pArt->eg2ToFc); 101356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks cutoff += pArt->filterCutoff; 10147df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 101556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* subtract the A5 offset and the sampling frequency */ 101656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks cutoff -= FILTER_CUTOFF_FREQ_ADJUST + A5_PITCH_OFFSET_IN_CENTS; 10177df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 101856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* limit the cutoff frequency */ 101956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks if (cutoff > FILTER_CUTOFF_MAX_PITCH_CENTS) 102056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks cutoff = FILTER_CUTOFF_MAX_PITCH_CENTS; 102156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks else if (cutoff < FILTER_CUTOFF_MIN_PITCH_CENTS) 102256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks cutoff = FILTER_CUTOFF_MIN_PITCH_CENTS; 10237df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 102456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks WT_SetFilterCoeffs(pIntFrame, cutoff, pArt->filterQ); 10257df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 10267df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 10277df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 10287df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#if defined(_FILTER_ENABLED) || defined(DLS_SYNTHESIZER) 10297df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 10307df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * coef 10317df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 10327df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Table of filter coefficients for low-pass filter 10337df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 10347df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10357df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * polynomial coefficients are based on 8kHz sampling frequency 10367df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * filter coef b2 = k2 = k2g0*k^0 + k2g1*k^1*(2^x) + k2g2*k^2*(2^x) 10377df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10387df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *where k2g0, k2g1, k2g2 are from the truncated power series expansion on theta 10397df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *(k*2^x = theta, but we incorporate the k along with the k2g0, k2g1, k2g2) 10407df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *note: this is a power series in 2^x, not k*2^x 10417df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *where k = (2*pi*440)/8kHz == convert octaves to radians 10427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10437df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * so actually, the following coefs listed as k2g0, k2g1, k2g2 are really 10447df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * k2g0*k^0 = k2g0 10457df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * k2g1*k^1 10467df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * k2g2*k^2 10477df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10487df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10497df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * filter coef n1 = numerator = n1g0*k^0 + n1g1*k^1*(2^x) + n1g2*k^2*(2^x) + n1g3*k^3*(2^x) 10507df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10517df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *where n1g0, n1g1, n1g2, n1g3 are from the truncated power series expansion on theta 10527df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *(k*2^x = theta, but we incorporate the k along with the n1g0, n1g1, n1g2, n2g3) 10537df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *note: this is a power series in 2^x, not k*2^x 10547df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *where k = (2*pi*440)/8kHz == convert octaves to radians 10557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *we also include the optimization factor of 0.81 10567df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 10577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * so actually, the following coefs listed as n1g0, n1g1, n1g2, n2g3 are really 10587df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * n1g0*k^0 = n1g0 10597df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * n1g1*k^1 10607df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * n1g2*k^2 10617df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * n1g3*k^3 10627df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 106356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * NOTE that n1g0 == n1g1 == 0, always, so we only need to store n1g2 and n1g3 10647df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 10657df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 10667df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 10677df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic const EAS_I16 nk1g0 = -32768; 10687df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic const EAS_I16 nk1g2 = 1580; 10697df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectstatic const EAS_I16 k2g0 = 32767; 10707df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 107156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const EAS_I16 k2g1[] = 10727df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 107356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -11324, /* k2g1[0] = -0.3455751918948761 */ 107456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -10387, /* k2g1[1] = -0.3169878073928751 */ 107556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -9528, /* k2g1[2] = -0.29076528753345476 */ 107656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -8740, /* k2g1[3] = -0.2667120011011279 */ 107756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -8017, /* k2g1[4] = -0.24464850028971705 */ 107856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -7353, /* k2g1[5] = -0.22441018194495696 */ 107956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -6745, /* k2g1[6] = -0.20584605955455101 */ 108056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -6187, /* k2g1[7] = -0.18881763682420102 */ 108156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -5675, /* k2g1[8] = -0.1731978744360067 */ 108256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -5206, /* k2g1[9] = -0.15887024228080968 */ 108356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -4775, /* k2g1[10] = -0.14572785009373057 */ 108456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -4380, /* k2g1[11] = -0.13367265000706827 */ 108556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -4018, /* k2g1[12] = -0.1226147050712642 */ 108656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -3685, /* k2g1[13] = -0.11247151828678581 */ 108756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -3381, /* k2g1[14] = -0.10316741714122014 */ 108856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -3101, /* k2g1[15] = -0.0946329890599603 */ 108956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -2844, /* k2g1[16] = -0.08680456355870586 */ 109056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -2609, /* k2g1[17] = -0.07962373723441349 */ 109156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -2393, /* k2g1[18] = -0.07303693805092666 */ 109256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -2195, /* k2g1[19] = -0.06699502566866912 */ 109356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -2014, /* k2g1[20] = -0.06145292483669077 */ 109456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1847, /* k2g1[21] = -0.056369289112013346 */ 109556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1694, /* k2g1[22] = -0.05170619239747895 */ 109656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1554, /* k2g1[23] = -0.04742884599684141 */ 109756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1426, /* k2g1[24] = -0.043505339076210514 */ 109856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1308, /* k2g1[25] = -0.03990640059558053 */ 109956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1199, /* k2g1[26] = -0.03660518093435039 */ 110056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1100, /* k2g1[27] = -0.03357705158166837 */ 110156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -1009, /* k2g1[28] = -0.030799421397205727 */ 110256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -926, /* k2g1[29] = -0.028251568071585884 */ 110356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -849 /* k2g1[30] = -0.025914483529091967 */ 11047df30109963092559d3760c0661a020f9daf1030The Android Open Source Project}; 11057df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 110656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const EAS_I16 k2g2[] = 11077df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 110856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1957, /* k2g2[0] = 0.059711106626580836 */ 110956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1646, /* k2g2[1] = 0.05024063501786333 */ 111056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1385, /* k2g2[2] = 0.042272226217199664 */ 111156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1165, /* k2g2[3] = 0.03556764576567844 */ 111256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 981, /* k2g2[4] = 0.029926444346999134 */ 111356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 825, /* k2g2[5] = 0.025179964880280382 */ 111456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 694, /* k2g2[6] = 0.02118630011706455 */ 111556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 584, /* k2g2[7] = 0.01782604998793514 */ 111656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 491, /* k2g2[8] = 0.014998751854573014 */ 111756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 414, /* k2g2[9] = 0.012619876941179595 */ 111856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 348, /* k2g2[10] = 0.010618303146468736 */ 111956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 293, /* k2g2[11] = 0.008934188679954682 */ 112056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 246, /* k2g2[12] = 0.007517182949855368 */ 112156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 207, /* k2g2[13] = 0.006324921212866403 */ 112256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 174, /* k2g2[14] = 0.005321757979794424 */ 112356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 147, /* k2g2[15] = 0.004477701309210577 */ 112456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 123, /* k2g2[16] = 0.00376751612730811 */ 112556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 104, /* k2g2[17] = 0.0031699697655869644 */ 112656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 87, /* k2g2[18] = 0.00266719715992703 */ 112756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 74, /* k2g2[19] = 0.0022441667321724647 */ 112856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 62, /* k2g2[20] = 0.0018882309854916855 */ 112956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 52, /* k2g2[21] = 0.0015887483774966232 */ 113056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 44, /* k2g2[22] = 0.0013367651661223448 */ 113156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 37, /* k2g2[23] = 0.0011247477162958733 */ 113256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 31, /* k2g2[24] = 0.0009463572640678758 */ 113356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 26, /* k2g2[25] = 0.0007962604042473498 */ 113456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 22, /* k2g2[26] = 0.0006699696356181593 */ 113556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 18, /* k2g2[27] = 0.0005637091964589207 */ 113656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 16, /* k2g2[28] = 0.00047430217920125243 */ 113756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 13, /* k2g2[29] = 0.00039907554925166274 */ 113856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 11 /* k2g2[30] = 0.00033578022828973666 */ 11397df30109963092559d3760c0661a020f9daf1030The Android Open Source Project}; 11407df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 114156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const EAS_I16 n1g2[] = 11427df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 114356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3170, /* n1g2[0] = 0.0967319927350769 */ 114456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 3036, /* n1g2[1] = 0.0926446051254155 */ 114556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2908, /* n1g2[2] = 0.08872992911818503 */ 114656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2785, /* n1g2[3] = 0.08498066682523227 */ 114756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2667, /* n1g2[4] = 0.08138982872895201 */ 114856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2554, /* n1g2[5] = 0.07795072065216213 */ 114956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2446, /* n1g2[6] = 0.0746569312785634 */ 115056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2343, /* n1g2[7] = 0.07150232020051943 */ 115156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2244, /* n1g2[8] = 0.06848100647187474 */ 115256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2149, /* n1g2[9] = 0.06558735764447099 */ 115356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 2058, /* n1g2[10] = 0.06281597926792246 */ 115456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1971, /* n1g2[11] = 0.06016170483307614 */ 115556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1888, /* n1g2[12] = 0.05761958614040857 */ 115656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1808, /* n1g2[13] = 0.05518488407540374 */ 115756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1732, /* n1g2[14] = 0.052853059773715245 */ 115856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1659, /* n1g2[15] = 0.05061976615964251 */ 115956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1589, /* n1g2[16] = 0.04848083984214659 */ 116056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1521, /* n1g2[17] = 0.046432293353298 */ 116156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1457, /* n1g2[18] = 0.04447030771468711 */ 116256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1396, /* n1g2[19] = 0.04259122531793907 */ 116356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1337, /* n1g2[20] = 0.040791543106060944 */ 116456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1280, /* n1g2[21] = 0.03906790604290942 */ 116556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1226, /* n1g2[22] = 0.037417100858604564 */ 116656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1174, /* n1g2[23] = 0.035836050059229754 */ 116756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1125, /* n1g2[24] = 0.03432180618965023 */ 116856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1077, /* n1g2[25] = 0.03287154633875494 */ 116956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 1032, /* n1g2[26] = 0.03148256687687814 */ 117056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 988, /* n1g2[27] = 0.030152278415589925 */ 117156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 946, /* n1g2[28] = 0.028878200980459685 */ 117256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 906, /* n1g2[29] = 0.02765795938779331 */ 117356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 868 /* n1g2[30] = 0.02648927881672521 */ 11747df30109963092559d3760c0661a020f9daf1030The Android Open Source Project}; 11757df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 117656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparksstatic const EAS_I16 n1g3[] = 11777df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 117856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -548, /* n1g3[0] = -0.016714088475899017 */ 117956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -481, /* n1g3[1] = -0.014683605122742116 */ 118056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -423, /* n1g3[2] = -0.012899791676436092 */ 118156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -371, /* n1g3[3] = -0.01133268185193299 */ 118256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -326, /* n1g3[4] = -0.00995594976868754 */ 118356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -287, /* n1g3[5] = -0.008746467702146129 */ 118456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -252, /* n1g3[6] = -0.00768391756106361 */ 118556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -221, /* n1g3[7] = -0.006750449563854721 */ 118656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -194, /* n1g3[8] = -0.005930382380083576 */ 118756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -171, /* n1g3[9] = -0.005209939699767622 */ 118856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -150, /* n1g3[10] = -0.004577018805123356 */ 118956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -132, /* n1g3[11] = -0.004020987256990177 */ 119056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -116, /* n1g3[12] = -0.003532504280467257 */ 119156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -102, /* n1g3[13] = -0.00310336384922047 */ 119256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -89, /* n1g3[14] = -0.002726356832432369 */ 119356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -78, /* n1g3[15] = -0.002395149888601605 */ 119456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -69, /* n1g3[16] = -0.0021041790717285314 */ 119556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -61, /* n1g3[17] = -0.0018485563625771063 */ 119656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -53, /* n1g3[18] = -0.001623987554831628 */ 119756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -47, /* n1g3[19] = -0.0014267001167177025 */ 119856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -41, /* n1g3[20] = -0.0012533798162347005 */ 119956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -36, /* n1g3[21] = -0.0011011150453668693 */ 120056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -32, /* n1g3[22] = -0.0009673479079754438 */ 120156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -28, /* n1g3[23] = -0.0008498312496971563 */ 120256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -24, /* n1g3[24] = -0.0007465909079943587 */ 120356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -21, /* n1g3[25] = -0.0006558925481952733 */ 120456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -19, /* n1g3[26] = -0.0005762125284029567 */ 120556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -17, /* n1g3[27] = -0.0005062123038325457 */ 120656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -15, /* n1g3[28] = -0.0004447159405951901 */ 120756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -13, /* n1g3[29] = -0.00039069036118270117 */ 120856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks -11 /* n1g3[30] = -0.00034322798979677605 */ 12097df30109963092559d3760c0661a020f9daf1030The Android Open Source Project}; 12107df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 12117df30109963092559d3760c0661a020f9daf1030The Android Open Source Project/*---------------------------------------------------------------------------- 12127df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * WT_SetFilterCoeffs() 12137df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 121456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Purpose: 12157df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Update the Filter parameters 12167df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 121756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * Inputs: 121856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks * pVoice - ptr to the voice whose filter we want to update 12197df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * pEASData - pointer to overall EAS data structure 12207df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 12217df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Outputs: 12227df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * 12237df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * Side Effects: 12247df30109963092559d3760c0661a020f9daf1030The Android Open Source Project * - updates Filter values for the given voice 12257df30109963092559d3760c0661a020f9daf1030The Android Open Source Project *---------------------------------------------------------------------------- 12267df30109963092559d3760c0661a020f9daf1030The Android Open Source Project*/ 12277df30109963092559d3760c0661a020f9daf1030The Android Open Source Projectvoid WT_SetFilterCoeffs (S_WT_INT_FRAME *pIntFrame, EAS_I32 cutoff, EAS_I32 resonance) 12287df30109963092559d3760c0661a020f9daf1030The Android Open Source Project{ 122956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks EAS_I32 temp; 123056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 123156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* 123256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks Convert the cutoff, which has had A5 subtracted, using the 2^x approx 123356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks Note, this cutoff is related to theta cutoff by 123456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks theta = k * 2^x 123556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks We use 2^x and incorporate k in the power series coefs instead 123656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks */ 123756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks cutoff = EAS_Calculate2toX(cutoff); 123856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 123956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate b2 coef */ 124056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = k2g1[resonance] + MULT_AUDIO_COEF(cutoff, k2g2[resonance]); 124156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = k2g0 + MULT_AUDIO_COEF(cutoff, temp); 124256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pIntFrame->frame.b2 = temp; 124356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 124456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate b1 coef */ 124556c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_AUDIO_COEF(cutoff, nk1g2); 124656c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = nk1g0 + MULT_AUDIO_COEF(cutoff, temp); 124756c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp += MULT_AUDIO_COEF(temp, pIntFrame->frame.b2); 124856c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pIntFrame->frame.b1 = temp >> 1; 124956c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks 125056c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks /* calculate K coef */ 125156c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = n1g2[resonance] + MULT_AUDIO_COEF(cutoff, n1g3[resonance]); 125256c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_AUDIO_COEF(cutoff, temp); 125356c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks temp = MULT_AUDIO_COEF(cutoff, temp); 125456c99cd2c2c1e6ab038dac5fced5b92ccf11ff6cDave Sparks pIntFrame->frame.k = temp; 12557df30109963092559d3760c0661a020f9daf1030The Android Open Source Project} 12567df30109963092559d3760c0661a020f9daf1030The Android Open Source Project#endif 12577df30109963092559d3760c0661a020f9daf1030The Android Open Source Project 1258