Skip to content

Commit

Permalink
Remove confusing single letter vars
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Apr 18, 2024
1 parent 2f0518d commit 9b70576
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
50 changes: 25 additions & 25 deletions src/engine/bufferscalers/enginebufferscalelinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ double EngineBufferScaleLinear::scaleBuffer(
SINT iNextSample = getOutputSignal().frames2samples(static_cast<SINT>(ceil(m_dNextFrame)));
int chCount = getOutputSignal().getChannelCount();
if (iNextSample + chCount <= m_bufferIntSize) {
for (int c = 0; c < chCount; c++) {
m_floorSampleOld[c] = m_bufferInt[iNextSample + c];
for (int chIdx = 0; chIdx < chCount; chIdx++) {
m_floorSampleOld[chIdx] = m_bufferInt[iNextSample + chIdx];
}
}

Expand Down Expand Up @@ -177,8 +177,8 @@ SINT EngineBufferScaleLinear::do_copy(CSAMPLE* buf, SINT buf_size) {
m_dNextFrame = 0;
int chCount = getOutputSignal().getChannelCount();
if (read_samples > chCount - 1) {
for (int c = 0; c < chCount; c++) {
m_floorSampleOld[c] = buf[read_samples - chCount + c];
for (int chIdx = 0; chIdx < chCount; chIdx++) {
m_floorSampleOld[chIdx] = buf[read_samples - chCount + chIdx];
}
}
return read_samples;
Expand Down Expand Up @@ -229,11 +229,11 @@ double EngineBufferScaleLinear::do_scale(CSAMPLE* buf, SINT buf_size) {
m_dNextFrame - floor(m_dNextFrame));

int chCount = getOutputSignal().getChannelCount();
std::vector<CSAMPLE> floor_sample(chCount);
std::vector<CSAMPLE> ceil_sample(chCount);
std::vector<CSAMPLE> floorSample(chCount);
std::vector<CSAMPLE> ceilSample(chCount);

std::fill(floor_sample.begin(), floor_sample.end(), 0.0);
std::fill(ceil_sample.begin(), ceil_sample.end(), 0.0);
std::fill(floorSample.begin(), floorSample.end(), 0.0);
std::fill(ceilSample.begin(), ceilSample.end(), 0.0);

double startFrame = m_dNextFrame;
SINT i = 0;
Expand Down Expand Up @@ -261,23 +261,23 @@ double EngineBufferScaleLinear::do_scale(CSAMPLE* buf, SINT buf_size) {
// we have advanced to a new buffer in the previous run,
// but the floor still points to the old buffer
// so take the cached sample, this happens on slow rates
for (int c = 0; c < chCount; c++) {
floor_sample[c] = m_floorSampleOld[c];
ceil_sample[c] = m_bufferInt[c];
for (int chIdx = 0; chIdx < chCount; chIdx++) {
floorSample[chIdx] = m_floorSampleOld[chIdx];
ceilSample[chIdx] = m_bufferInt[chIdx];
}
} else if (sampleCount + 2 * chCount - 1 < m_bufferIntSize) {
// take floor_sample form the buffer of the previous run
for (int c = 0; c < chCount; c++) {
floor_sample[c] = m_bufferInt[sampleCount + c];
ceil_sample[c] = m_bufferInt[sampleCount + chCount + c];
// take floorSample form the buffer of the previous run
for (int chIdx = 0; chIdx < chCount; chIdx++) {
floorSample[chIdx] = m_bufferInt[sampleCount + chIdx];
ceilSample[chIdx] = m_bufferInt[sampleCount + chCount + chIdx];
}
} else {
// if we don't have the ceil_sample in buffer, load some more
// if we don't have the ceilSample in buffer, load some more

if (sampleCount + chCount - 1 < m_bufferIntSize) {
// take floor_sample form the buffer of the previous run
for (int c = 0; c < chCount; c++) {
floor_sample[c] = m_bufferInt[sampleCount + c];
// take floorSample form the buffer of the previous run
for (int chIdx = 0; chIdx < chCount; chIdx++) {
floorSample[chIdx] = m_bufferInt[sampleCount + chIdx];
}
}

Expand Down Expand Up @@ -312,14 +312,14 @@ double EngineBufferScaleLinear::do_scale(CSAMPLE* buf, SINT buf_size) {
sampleCount = getOutputSignal().frames2samples(currentFrameFloor);
} while (sampleCount + 2 * chCount - 1 >= m_bufferIntSize);

for (int c = 0; c < chCount; c++) {
for (int chIdx = 0; chIdx < chCount; chIdx++) {
// Now that the buffer is up to date, we can get the value of the sample
// at the floor of our position.
if (currentFrameFloor >= 0) {
// the previous position is in the new buffer
floor_sample[c] = m_bufferInt[sampleCount + c];
floorSample[chIdx] = m_bufferInt[sampleCount + chIdx];
}
ceil_sample[c] = m_bufferInt[sampleCount + chCount + c];
ceilSample[chIdx] = m_bufferInt[sampleCount + chCount + chIdx];
}
}

Expand All @@ -328,11 +328,11 @@ double EngineBufferScaleLinear::do_scale(CSAMPLE* buf, SINT buf_size) {
CSAMPLE frac = static_cast<CSAMPLE>(m_dCurrentFrame) - currentFrameFloor;

// Perform linear interpolation
for (int c = 0; c < chCount; c++) {
buf[i + c] = floor_sample[c] + frac * (ceil_sample[c] - floor_sample[c]);
for (int chIdx = 0; chIdx < chCount; chIdx++) {
buf[i + chIdx] = floorSample[chIdx] + frac * (ceilSample[chIdx] - floorSample[chIdx]);
}

m_floorSampleOld = floor_sample;
m_floorSampleOld = floorSample;

// increment the index for the next loop
m_dNextFrame = m_dCurrentFrame + rate_add;
Expand Down
14 changes: 7 additions & 7 deletions src/engine/bufferscalers/enginebufferscalerubberband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ void EngineBufferScaleRubberBand::onOutputSignalChanged() {

m_pRubberBand.reset();

for (int c = 0; c < channelCount; c++) {
if (m_buffers[c].size() == MAX_BUFFER_LEN) {
for (int chIdx = 0; chIdx < channelCount; chIdx++) {
if (m_buffers[chIdx].size() == MAX_BUFFER_LEN) {
continue;
}
m_buffers[c] = mixxx::SampleBuffer(MAX_BUFFER_LEN);
m_bufferPtrs[c] = m_buffers[c].data();
m_buffers[chIdx] = mixxx::SampleBuffer(MAX_BUFFER_LEN);
m_bufferPtrs[chIdx] = m_buffers[chIdx].data();
}

RubberBandStretcher::Options rubberbandOptions =
Expand Down Expand Up @@ -200,10 +200,10 @@ SINT EngineBufferScaleRubberBand::retrieveAndDeinterleave(
break;
default: {
int chCount = getOutputSignal().getChannelCount();
for (SINT i = 0; i < frames; ++i) {
for (SINT frameIdx = 0; frameIdx < frames; ++frameIdx) {
for (int channel = 0; channel < chCount; channel++) {
m_buffers[channel].data()[i] =
pBuffer[i * chCount + channel];
m_buffers[channel].data()[frameIdx] =
pBuffer[frameIdx * chCount + channel];
}
}
} break;
Expand Down
7 changes: 4 additions & 3 deletions src/engine/channels/enginedeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ void EngineDeck::processStem(CSAMPLE* pOut, const int iBufferSize) {
SampleUtil::clear(pOut, iBufferSize);
const CSAMPLE* pIn = m_stemBuffer.data();
for (int i = 0; i < iBufferSize; i += mixxx::kEngineChannelOutputCount) {
for (int c = 0; c < m_pBuffer->getChannelCount(); c += mixxx::kEngineChannelOutputCount) {
for (int chIdx = 0; chIdx < m_pBuffer->getChannelCount();
chIdx += mixxx::kEngineChannelOutputCount) {
// TODO(XXX): apply stem gain or skip muted stem
pOut[i] += pIn[stereoChannelCount * i + c];
pOut[i + 1] += pIn[stereoChannelCount * i + c + 1];
pOut[i] += pIn[stereoChannelCount * i + chIdx];
pOut[i + 1] += pIn[stereoChannelCount * i + chIdx + 1];
}
}
// TODO(XXX): process stem DSP
Expand Down
19 changes: 10 additions & 9 deletions src/util/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,12 @@ void SampleUtil::linearCrossfadeUnaryBuffersOut(
DEBUG_ASSERT(numSamples % channelCount == 0);
int numFrame = numSamples / channelCount;
const CSAMPLE_GAIN cross_inc = CSAMPLE_GAIN_ONE / CSAMPLE_GAIN(numSamples / channelCount);
for (int c = 0; c < channelCount; c++) {
for (int chIdx = 0; chIdx < channelCount; chIdx++) {
for (int i = 0; i < numFrame; ++i) {
const CSAMPLE_GAIN cross_mix = cross_inc * i;
pDestSrcFadeOut[i * channelCount + c] *= (CSAMPLE_GAIN_ONE - cross_mix);
pDestSrcFadeOut[i * channelCount + c] += pSrcFadeIn[i * channelCount + c] * cross_mix;
pDestSrcFadeOut[i * channelCount + chIdx] *= (CSAMPLE_GAIN_ONE - cross_mix);
pDestSrcFadeOut[i * channelCount + chIdx] +=
pSrcFadeIn[i * channelCount + chIdx] * cross_mix;
}
}
}
Expand Down Expand Up @@ -735,12 +736,12 @@ void SampleUtil::linearCrossfadeUnaryBuffersIn(
int channelCount) {
int numFrame = numSamples / channelCount;
const CSAMPLE_GAIN cross_inc = CSAMPLE_GAIN_ONE / CSAMPLE_GAIN(numSamples / channelCount);
for (int c = 0; c < channelCount; c++) {
for (int chIdx = 0; chIdx < channelCount; chIdx++) {
for (int i = 0; i < numFrame; ++i) {
const CSAMPLE_GAIN cross_mix = cross_inc * i;
pDestSrcFadeIn[i * channelCount + c] *= cross_mix;
pDestSrcFadeIn[i * channelCount + c] +=
pSrcFadeOut[i * channelCount + c] *
pDestSrcFadeIn[i * channelCount + chIdx] *= cross_mix;
pDestSrcFadeIn[i * channelCount + chIdx] +=
pSrcFadeOut[i * channelCount + chIdx] *
(CSAMPLE_GAIN_ONE - cross_mix);
}
}
Expand Down Expand Up @@ -894,8 +895,8 @@ void SampleUtil::copyReverseUnary(CSAMPLE* M_RESTRICT pDest,
DEBUG_ASSERT(numSamples % channelCount == 0);
for (SINT j = 0; j < numSamples / channelCount; ++j) {
const int endpos = (numSamples - 1) - j * channelCount;
for (int c = 0; c < channelCount; c++) {
pDest[j * channelCount + c] = pSrc[endpos - channelCount - c + 1];
for (int chIdx = 0; chIdx < channelCount; chIdx++) {
pDest[j * channelCount + chIdx] = pSrc[endpos - channelCount - chIdx + 1];
}
}
}

0 comments on commit 9b70576

Please sign in to comment.