![]() |
Mixxx
|
00001 /*************************************************************************** 00002 enginedelay.cpp - description 00003 ------------------- 00004 copyright : (C) 2002 by Tue and Ken Haste Andersen 00005 email : 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include "enginedelay.h" 00018 #include "controlpotmeter.h" 00019 00020 /*---------------------------------------------------------------- 00021 00022 ----------------------------------------------------------------*/ 00023 EngineDelay::EngineDelay(const char * group) 00024 { 00025 m_pDelayBuffer = new CSAMPLE[kiMaxDelay]; 00026 m_iDelayPos = 0; 00027 new ControlPotmeter(ConfigKey(group, "delay"), 0, kiMaxDelay); 00028 } 00029 00030 EngineDelay::~EngineDelay() 00031 { 00032 delete [] m_pDelayBuffer; 00033 } 00034 00035 void EngineDelay::process(const CSAMPLE * pIn, const CSAMPLE * pOut, const int iBufferSize) 00036 { 00037 int iDelaySourcePos = (m_iDelayPos+kiMaxDelay-m_iDelay)%kiMaxDelay; 00038 CSAMPLE * pOutput = (CSAMPLE *)pOut; 00039 00040 Q_ASSERT(iDelaySourcePos>=0); 00041 Q_ASSERT(iDelaySourcePos<=kiMaxDelay); 00042 00043 for (int i=0; i<iBufferSize; ++i) 00044 { 00045 // put sample into delay buffer: 00046 m_pDelayBuffer[m_iDelayPos] = pIn[i]; 00047 m_iDelayPos = (m_iDelayPos+1)%kiMaxDelay; 00048 00049 // Take "old" sample from delay buffer and mix it with the source buffer: 00050 pOutput[i] = 0.5*(m_pDelayBuffer[iDelaySourcePos] + pIn[i]); 00051 iDelaySourcePos = (iDelaySourcePos+1)%kiMaxDelay; 00052 } 00053 } 00054