1 /********************************************************************** 2 3 Audacity: A Digital Audio Editor 4 5 Fade.cpp 6 7 Robert Leidle 8 9 *******************************************************************//** 10 11 \class EffectFade 12 \brief An Effect that reduces the volume to zero over achosen interval. 13 14 *//*******************************************************************/ 15 16 17 #include "Fade.h" 18 19 #include <wx/intl.h> 20 21 #include "LoadEffects.h" 22 23 const ComponentInterfaceSymbol EffectFadeIn::Symbol 24 { XO("Fade In") }; 25 26 namespace{ BuiltinEffectsModule::Registration< EffectFadeIn > reg; } 27 28 const ComponentInterfaceSymbol EffectFadeOut::Symbol 29 { XO("Fade Out") }; 30 31 namespace{ BuiltinEffectsModule::Registration< EffectFadeOut > reg2; } 32 EffectFade(bool fadeIn)33EffectFade::EffectFade(bool fadeIn) 34 { 35 mFadeIn = fadeIn; 36 } 37 ~EffectFade()38EffectFade::~EffectFade() 39 { 40 } 41 42 // ComponentInterface implementation 43 GetSymbol()44ComponentInterfaceSymbol EffectFade::GetSymbol() 45 { 46 return mFadeIn 47 ? EffectFadeIn::Symbol 48 : EffectFadeOut::Symbol; 49 } 50 GetDescription()51TranslatableString EffectFade::GetDescription() 52 { 53 return mFadeIn 54 ? XO("Applies a linear fade-in to the selected audio") 55 : XO("Applies a linear fade-out to the selected audio"); 56 } 57 58 // EffectDefinitionInterface implementation 59 GetType()60EffectType EffectFade::GetType() 61 { 62 return EffectTypeProcess; 63 } 64 IsInteractive()65bool EffectFade::IsInteractive() 66 { 67 return false; 68 } 69 70 // EffectClientInterface implementation 71 GetAudioInCount()72unsigned EffectFade::GetAudioInCount() 73 { 74 return 1; 75 } 76 GetAudioOutCount()77unsigned EffectFade::GetAudioOutCount() 78 { 79 return 1; 80 } 81 ProcessInitialize(sampleCount WXUNUSED (totalLen),ChannelNames WXUNUSED (chanMap))82bool EffectFade::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelNames WXUNUSED(chanMap)) 83 { 84 mSample = 0; 85 86 return true; 87 } 88 ProcessBlock(float ** inBlock,float ** outBlock,size_t blockLen)89size_t EffectFade::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) 90 { 91 float *ibuf = inBlock[0]; 92 float *obuf = outBlock[0]; 93 94 if (mFadeIn) 95 { 96 for (decltype(blockLen) i = 0; i < blockLen; i++) 97 { 98 obuf[i] = 99 (ibuf[i] * ( mSample++ ).as_float()) / 100 mSampleCnt.as_float(); 101 } 102 } 103 else 104 { 105 for (decltype(blockLen) i = 0; i < blockLen; i++) 106 { 107 obuf[i] = (ibuf[i] * 108 ( mSampleCnt - 1 - mSample++ ).as_float()) / 109 mSampleCnt.as_float(); 110 } 111 } 112 113 return blockLen; 114 } 115