/***************************************************************************
enginebuffer.cpp - description
-------------------
begin : Wed Feb 20 2002
copyright : (C) 2002 by Tue and Ken Haste Andersen
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <QtDebug>
#include "engine/enginebuffer.h"
#include "cachingreader.h"
#include "sampleutil.h"
#include "controlpushbutton.h"
#include "controlindicator.h"
#include "configobject.h"
#include "controlpotmeter.h"
#include "controllinpotmeter.h"
#include "engine/enginechannel.h"
#include "engine/enginebufferscalest.h"
#include "engine/enginebufferscalerubberband.h"
#include "engine/enginebufferscalelinear.h"
#include "engine/enginebufferscaledummy.h"
#include "mathstuff.h"
#include "engine/sync/enginesync.h"
#include "engine/engineworkerscheduler.h"
#include "engine/readaheadmanager.h"
#include "engine/enginecontrol.h"
#include "engine/loopingcontrol.h"
#include "engine/ratecontrol.h"
#include "engine/bpmcontrol.h"
#include "engine/keycontrol.h"
#include "engine/sync/synccontrol.h"
#include "engine/quantizecontrol.h"
#include "visualplayposition.h"
#include "engine/cuecontrol.h"
#include "engine/clockcontrol.h"
#include "engine/enginemaster.h"
#include "util/timer.h"
#include "track/keyutils.h"
#include "controlobjectslave.h"
#include "util/compatibility.h"
#ifdef __VINYLCONTROL__
#include "engine/vinylcontrolcontrol.h"
#endif
#include "trackinfoobject.h"
const double kMaxPlayposRange = 1.14;
const double kMinPlayposRange = -0.14;
EngineBuffer::EngineBuffer(const char* _group, ConfigObject<ConfigValue>* _config,
EngineChannel* pChannel, EngineMaster* pMixingEngine)
: m_engineLock(QMutex::Recursive),
m_group(_group),
m_pConfig(_config),
m_pLoopingControl(NULL),
m_pSyncControl(NULL),
m_pVinylControlControl(NULL),
m_pRateControl(NULL),
m_pBpmControl(NULL),
m_pKeyControl(NULL),
m_pReadAheadManager(NULL),
m_pReader(NULL),
m_filepos_play(0.),
m_speed_old(0),
m_pitch_old(0),
m_baserate_old(0),
m_rate_old(0.),
m_file_length_old(-1),
m_file_srate_old(0),
m_iSamplesCalculated(0),
m_iUiSlowTick(0),
m_pRepeat(NULL),
m_startButton(NULL),
m_endButton(NULL),
m_pScale(NULL),
m_pScaleLinear(NULL),
m_pScaleST(NULL),
m_pScaleRB(NULL),
m_bScalerChanged(false),
m_bScalerOverride(false),
m_iSeekQueued(NO_SEEK),
m_bLastBufferPaused(true),
m_iTrackLoading(0),
m_bPlayAfterLoading(false),
m_fRampValue(0.0),
m_iRampState(ENGINE_RAMP_NONE),
m_pDitherBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)),
m_iDitherBufferReadIndex(0),
m_pCrossFadeBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)),
m_iCrossFadeSamples(0),
m_iLastBufferSize(0) {
// Generate dither values. When engine samples used to be within [SHRT_MIN,
// SHRT_MAX] dithering values were in the range [-0.5, 0.5]. Now that we
// normalize engine samples to the range [-1.0, 1.0] we divide by SHRT_MAX
// to preserve the previous behavior.
for (int i = 0; i < MAX_BUFFER_LEN; ++i) {
m_pDitherBuffer[i] = (static_cast<CSAMPLE>(rand() % RAND_MAX) / RAND_MAX - 0.5) / SHRT_MAX;
}
// zero out crossfade buffer
SampleUtil::applyGain(m_pCrossFadeBuffer, 0.0, MAX_BUFFER_LEN);
m_fLastSampleValue[0] = 0;
m_fLastSampleValue[1] = 0;
m_pReader = new CachingReader