Google Git
Sign inandroid / platform / external / sonivox / 2766181404486d7dbc3e501fa8f6bbb32f6d6ea6 / . / arm-wt-22k / lib_src / eas_wtengine.cblob: b1ee749cc8bf8e29b1aa8f903c6f976960baba09 [file] [log] [blame]/---------------------------------------------------------------------------- * * File: * eas_wtengine.c * * Contents and purpose: * This file contains the critical synthesizer components that need to * be optimized for best performance. * * Copyright Sonic Network Inc. 2004-2005 * Licensed under the Apache License, Version 2.0 (the “License”); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an “AS IS” BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ---------------------------------------------------------------------------- * Revision Control: * $Revision: 844 $ * $Date: 2007-08-23 14:33:32 -0700 (Thu, 23 Aug 2007) $ ----------------------------------------------------------------------------//------------------------------------ * includes ------------------------------------/#include “log/log.h”#include <cutils/log.h>#include “eas_types.h”#include “eas_math.h”#include “eas_audioconst.h”#include “eas_sndlib.h”#include “eas_wtengine.h”#include “eas_mixer.h”/---------------------------------------------------------------------------- * prototypes ----------------------------------------------------------------------------/extern void WT_NoiseGenerator (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame);extern void WT_VoiceGain (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame);#if defined(_OPTIMIZED_MONO)extern void WT_InterpolateMono (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame);#elseextern void WT_InterpolateNoLoop (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame);extern void WT_Interpolate (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME pWTIntFrame);#endif#if defined(_FILTER_ENABLED)extern void WT_VoiceFilter (S_FILTER_CONTROLpFilter, S_WT_INT_FRAME pWTIntFrame);#endif// The PRNG in WT_NoiseGenerator relies on modulo math#undef NO_INT_OVERFLOW_CHECKS#define NO_INT_OVERFLOW_CHECKS attribute((no_sanitize(“integer”)))#if defined(_OPTIMIZED_MONO) || !defined(NATIVE_EAS_KERNEL) || defined(_16_BIT_SAMPLES)/---------------------------------------------------------------------------- * WT_VoiceGain *---------------------------------------------------------------------------- * Purpose: * Output gain for individual voice * * Inputs: * * Outputs: * ----------------------------------------------------------------------------//*lint -esym(715, pWTVoice) reserved for future use */void WT_VoiceGain (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame){ EAS_I32 *pMixBuffer; EAS_PCM pInputBuffer; EAS_I32 gain; EAS_I32 gainIncrement; EAS_I32 tmp0; EAS_I32 tmp1; EAS_I32 tmp2; EAS_I32 numSamples;#if (NUM_OUTPUT_CHANNELS == 2) EAS_I32 gainLeft, gainRight;#endif / initialize some local variables / numSamples = pWTIntFrame->numSamples; if (numSamples <= 0) { ALOGE(“b/26366256”); android_errorWriteLog(0x534e4554, “26366256”); return; } pMixBuffer = pWTIntFrame->pMixBuffer; pInputBuffer = pWTIntFrame->pAudioBuffer; gainIncrement = (pWTIntFrame->frame.gainTarget - pWTIntFrame->prevGain) * (1 << (16 - SYNTH_UPDATE_PERIOD_IN_BITS)); if (gainIncrement < 0) gainIncrement++; gain = pWTIntFrame->prevGain * (1 << 16);#if (NUM_OUTPUT_CHANNELS == 2) gainLeft = pWTVoice->gainLeft; gainRight = pWTVoice->gainRight;#endif while (numSamples–) { / incremental gain step to prevent zipper noise */ tmp0 = pInputBuffer++; gain += gainIncrement; /lint -e{704} / tmp2 = gain >> 16; / scale sample by gain */ tmp2 = tmp0; / stereo output /#if (NUM_OUTPUT_CHANNELS == 2) /lint -e{704} / tmp2 = tmp2 >> 14; / get the current sample in the final mix buffer */ tmp1 = pMixBuffer; / left channel */ tmp0 = tmp2 * gainLeft; /lint -e{704} / tmp0 = tmp0 >> NUM_MIXER_GUARD_BITS; tmp1 += tmp0; pMixBuffer++ = tmp1; / get the current sample in the final mix buffer */ tmp1 = pMixBuffer; / right channel */ tmp0 = tmp2 * gainRight; /lint -e{704} / tmp0 = tmp0 >> NUM_MIXER_GUARD_BITS; tmp1 += tmp0; pMixBuffer++ = tmp1; / mono output /#else / get the current sample in the final mix buffer */ tmp1 = *pMixBuffer; /lint -e{704} / tmp2 = tmp2 >> (NUM_MIXER_GUARD_BITS - 1); tmp1 += tmp2; pMixBuffer++ = tmp1;#endif }}#endif#if !defined(NATIVE_EAS_KERNEL) || defined(_16_BIT_SAMPLES)/---------------------------------------------------------------------------- * WT_Interpolate *---------------------------------------------------------------------------- * Purpose: * Interpolation engine for wavetable synth * * Inputs: * * Outputs: * ----------------------------------------------------------------------------/void WT_Interpolate (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame){ EAS_PCM *pOutputBuffer; EAS_I32 phaseInc; EAS_I32 phaseFrac; EAS_I32 acc0; const EAS_SAMPLE pSamples; const EAS_SAMPLE loopEnd; EAS_I32 samp1; EAS_I32 samp2; EAS_I32 numSamples; / initialize some local variables / numSamples = pWTIntFrame->numSamples; if (numSamples <= 0) { ALOGE(“b/26366256”); android_errorWriteLog(0x534e4554, “26366256”); return; } pOutputBuffer = pWTIntFrame->pAudioBuffer; loopEnd = (const EAS_SAMPLE) pWTVoice->loopEnd + 1; pSamples = (const EAS_SAMPLE) pWTVoice->phaseAccum; /*lint -e{713} truncation is OK / phaseFrac = pWTVoice->phaseFrac & PHASE_FRAC_MASK; phaseInc = pWTIntFrame->frame.phaseIncrement; / fetch adjacent samples /#if defined(_8_BIT_SAMPLES) /lint -e{701} / samp1 = pSamples[0] << 8; /lint -e{701} / samp2 = pSamples[1] << 8;#else samp1 = pSamples[0]; samp2 = pSamples[1];#endif while (numSamples–) { EAS_I32 nextSamplePhaseInc; / linear interpolation / acc0 = samp2 - samp1; acc0 = acc0 * phaseFrac; /lint -e{704} / acc0 = samp1 + (acc0 >> NUM_PHASE_FRAC_BITS); / save new output sample in buffer / /lint -e{704} / pOutputBuffer++ = (EAS_I16)(acc0 >> 2); / increment phase / phaseFrac += phaseInc; /lint -e{704} / nextSamplePhaseInc = phaseFrac >> NUM_PHASE_FRAC_BITS; / next sample / if (nextSamplePhaseInc > 0) { / advance sample pointer / pSamples += nextSamplePhaseInc; phaseFrac = phaseFrac & PHASE_FRAC_MASK; / decrementing pSamples by entire buffer length until second pSample is within / / loopEnd / while (&pSamples[1] >= loopEnd) { pSamples -= (loopEnd - (const EAS_SAMPLE)pWTVoice->loopStart); } / fetch new samples /#if defined(_8_BIT_SAMPLES) /lint -e{701} / samp1 = pSamples[0] << 8; /lint -e{701} / samp2 = pSamples[1] << 8;#else samp1 = pSamples[0]; samp2 = pSamples[1];#endif } } / save pointer and phase / pWTVoice->phaseAccum = (EAS_U32) pSamples; pWTVoice->phaseFrac = (EAS_U32) phaseFrac;}#endif#if !defined(NATIVE_EAS_KERNEL) || defined(_16_BIT_SAMPLES)/---------------------------------------------------------------------------- * WT_InterpolateNoLoop *---------------------------------------------------------------------------- * Purpose: * Interpolation engine for wavetable synth * * Inputs: * * Outputs: * ----------------------------------------------------------------------------/void WT_InterpolateNoLoop (S_WT_VOICE *pWTVoice, S_WT_INT_FRAME *pWTIntFrame){ EAS_PCM pOutputBuffer; EAS_I32 phaseInc; EAS_I32 phaseFrac; EAS_I32 acc0; const EAS_SAMPLE pSamples; const EAS_SAMPLE bufferEndP1; EAS_I32 samp1; EAS_I32 samp2; EAS_I32 numSamples; / initialize some local variables / numSamples = pWTIntFrame->numSamples; if (numSamples <= 0) { ALOGE(“b/26366256”); android_errorWriteLog(0x534e4554, “26366256”); return; } pOutputBuffer = pWTIntFrame->pAudioBuffer; phaseInc = pWTIntFrame->frame.phaseIncrement; bufferEndP1 = (const EAS_SAMPLE) pWTVoice->loopEnd + 1; pSamples = (const EAS_SAMPLE) pWTVoice->phaseAccum; phaseFrac = (EAS_I32)(pWTVoice->phaseFrac & PHASE_FRAC_MASK); / fetch adjacent samples /#if defined(_8_BIT_SAMPLES) /lint -e{701} / samp1 = pSamples[0] << 8; /lint -e{701} / samp2 = pSamples[1] << 8;#else samp1 = pSamples[0]; samp2 = pSamples[1];#endif while (numSamples–) { EAS_I32 nextSamplePhaseInc; / linear interpolation / acc0 = samp2 - samp1; acc0 = acc0 * phaseFrac; /lint -e{704} / acc0 = samp1 + (acc0 >> NUM_PHASE_FRAC_BITS); / save new output sample in buffer */ /lint -e{704} / pOutputBuffer++ = (EAS_I16)(acc0 >> 2); / increment phase / phaseFrac += phaseInc; /lint -e{704} / nextSamplePhaseInc = phaseFrac >> NUM_PHASE_FRAC_BITS; / next sample / if (nextSamplePhaseInc > 0) { / check for loop end / if ( &pSamples[nextSamplePhaseInc+1] >= bufferEndP1) { break; } / advance sample pointer / pSamples += nextSamplePhaseInc; phaseFrac = (EAS_I32)((EAS_U32)phaseFrac & PHASE_FRAC_MASK); / fetch new samples /#if defined(_8_BIT_SAMPLES) /lint -e{701} / samp1 = pSamples[0] << 8; /lint -e{701} / samp2 = pSamples[1] << 8;#else samp1 = pSamples[0]; samp2 = pSamples[1];#endif } } / save pointer and phase / pWTVoice->phaseAccum = (EAS_U32) pSamples; pWTVoice->phaseFrac = (EAS_U32) phaseFrac;}#endif#if defined(_FILTER_ENABLED) && !defined(NATIVE_EAS_KERNEL)/---------------------------------------------------------------------------- * WT_VoiceFilter *---------------------------------------------------------------------------- * Purpose: * Implements a 2-pole filter * * Inputs: * * Outputs: * ----------------------------------------------------------------------------/void WT_VoiceFilter (S_FILTER_CONTROL *pFilter, S_WT_INT_FRAME *pWTIntFrame){ EAS_PCM pAudioBuffer; EAS_I32 k; EAS_I32 b1; EAS_I32 b2; EAS_I32 z1; EAS_I32 z2; EAS_I32 acc0; EAS_I32 acc1; EAS_I32 numSamples; / initialize some local variables */ numSamples = pWTIntFrame->numSamples; if (numSamples <= 0) { ALOGE(“b/26366256”); android_errorWriteLog(0x534e4554, “26366256”); return; } pAudioBuffer = pWTIntFrame->pAudioBuffer; z1 = pFilter->z1; z2 = pFilter->z2; b1 = -pWTIntFrame->frame.b1; /*lint -e{702} */ b2 = -pWTIntFrame->frame.b2 >> 1; /*lint -e{702} / k = pWTIntFrame->frame.k >> 1; while (numSamples–) { / do filter calculations */ acc0 = *pAudioBuffer; acc1 = z1 * b1; acc1 += z2 * b2; acc0 = acc1 + k * acc0; z2 = z1; /*lint -e{702} */ z1 = acc0 >> 14; pAudioBuffer++ = (EAS_I16) z1; } / save delay values / pFilter->z1 = (EAS_I16) z1; pFilter->z2 = (EAS_I16) z2;}#endif/---------------------------------------------------------------------------- * WT_NoiseGenerator *---------------------------------------------------------------------------- * Purpose: * Generate pseudo-w
相关文章
- 10-28刘二大人pytorch入门-笔记
- 10-28刘二Pytorch第二章
- 10-28Polar Chain边缘计算云 引爆人人挖矿红利 ——专访Ploar Chain 发起人刘云鹏
- 10-28mybatis从入门到精通(刘增辉)
- 10-28综述文章梳理_刘 et al_2021_面向工业控制系统的入侵检测技术综述
- 10-2820165101刘天野 2018-2019-2《网络对抗技术》Exp7 网络欺诈防范
- 10-282019-2020-2 网络对抗技术 20174303刘金晖 Exp7 网络欺诈防范
- 10-2820182217刘洪宇_Exp7 网络欺诈防范
- 10-28冲量在线创始人刘尧:以信创软硬件结合场景为突破口“占山为王”
- 10-28计应191西 一组 刘孟琦