Skip to content

Commit

Permalink
Changed type of bufferSizes to std::size_t and removed the i prefix o…
Browse files Browse the repository at this point in the history
…f the name at many related parts of the code
  • Loading branch information
JoergAtGithub committed Nov 1, 2024
1 parent 29c627b commit 748163d
Show file tree
Hide file tree
Showing 70 changed files with 351 additions and 350 deletions.
22 changes: 11 additions & 11 deletions .codespellignorelines
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
pInOut, pInOut,
CSAMPLE* pInOut,
CSAMPLE* pInOut,
void EnginePregain::process(CSAMPLE* pInOut, const int iBufferSize) {
void EngineDelay::process(CSAMPLE* pInOut, const int iBufferSize) {
void EnginePregain::process(CSAMPLE* pInOut, const size_t bufferSize) {
void EngineDelay::process(CSAMPLE* pInOut, const size_t bufferSize) {
pInOut[i] = (CSAMPLE) processSample(fbuf1, (double) pInOut[i]);
pInOut[i + 1] = (CSAMPLE) processSample(fbuf2, (double) pInOut[i + 1]);
m_pDelayBuffer[m_iDelayPos] = pInOut[i];
pInOut[i] = m_pDelayBuffer[iDelaySourcePos];
SampleUtil::applyRampingGain(&pInOut[0], m_fPrevGain, 0, iBufferSize / 2);
SampleUtil::applyRampingGain(&pInOut[iBufferSize / 2], 0, totalGain, iBufferSize / 2);
SampleUtil::applyRampingGain(pInOut, m_fPrevGain, totalGain, iBufferSize);
SampleUtil::applyGain(pInOut, totalGain, iBufferSize);
void process(CSAMPLE* pInOut, const int iBufferSize) override;
void process(CSAMPLE* pInOut, const int iBufferSize);
virtual void process(CSAMPLE* pInOut, const int iBufferSize);
SampleUtil::applyRampingGain(&pInOut[0], m_fPrevGain, 0, bufferSize / 2);
SampleUtil::applyRampingGain(&pInOut[bufferSize / 2], 0, totalGain, bufferSize / 2);
SampleUtil::applyRampingGain(pInOut, m_fPrevGain, totalGain, bufferSize);
SampleUtil::applyGain(pInOut, totalGain, bufferSize);
void process(CSAMPLE* pInOut, const size_t bufferSize) override;
void process(CSAMPLE* pInOut, const size_t bufferSize);
virtual void process(CSAMPLE* pInOut, const size_t bufferSize);
"CSAMPLE_GAIN gain%(i)din, CSAMPLE_GAIN gain%(i)dout"
"gain%(i)dout == CSAMPLE_GAIN_ZERO) {"
"pSrc%(i)d, gain%(i)din, gain%(i)dout" % {"i": j}
"(gain%(i)dout - gain%(i)din) / (iNumSamples / 2);"
MOCK_METHOD(void, process, (CSAMPLE * pInOut, const int iBufferSize), (override));
MOCK_METHOD(void, process, (CSAMPLE * pInOut, const size_t bufferSize), (override));
const QString kName3 = QStringLiteral("I'm blue, da ba dee");
float m_k2vg; // IIF factor
float m_k2vgNew; // IIF factor
Expand Down Expand Up @@ -71,6 +71,6 @@ void EngineEffectsDelay::process(CSAMPLE* pInOut,
// Source: FIPS 180-4 Secure Hash Standard (SHS)
// ALAC/CAF has been added in version 1.0.26
QStringLiteral("caf"),
void EngineFilter::process(CSAMPLE* pInOut, const int iBufferSize)
void EngineFilter::process(CSAMPLE* pInOut, const size_t bufferSize)
// Note(RRyan/Max Linke):
// https://github.com/codders/libshout/blob/a17fb84671d3732317b0353d7281cc47e2df6cf6/src/timing/timing.c
2 changes: 1 addition & 1 deletion src/encoder/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Encoder {

virtual int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) = 0;
// encodes the provided buffer of audio.
virtual void encodeBuffer(const CSAMPLE *samples, const int size) = 0;
virtual void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) = 0;
// Adds metadata to the encoded audio, i.e., the ID3 tag. Currently only used
// by EngineRecord, ShoutConnection does something different.
virtual void updateMetaData(const QString& artist, const QString& title, const QString& album) = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/encoder/encoderfdkaac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ int EncoderFdkAac::initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUs
return 0;
}

void EncoderFdkAac::encodeBuffer(const CSAMPLE* samples, const int sampleCount) {
void EncoderFdkAac::encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) {
if (!m_pInputFifo) {
return;
}
int writeCount = sampleCount;
int writeCount = static_cast<int>(bufferSize);
int writeAvailable = m_pInputFifo->writeAvailable();
if (writeCount > writeAvailable) {
kLogger.warning() << "FIFO buffer too small, losing samples!"
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderfdkaac.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EncoderFdkAac : public Encoder {
virtual ~EncoderFdkAac();

int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) override;
void encodeBuffer(const CSAMPLE* samples, const int sampleCount) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;
void updateMetaData(const QString& artist, const QString& title, const QString& album) override;
void flush() override;
void setEncoderSettings(const EncoderSettings& settings) override;
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderffmpegcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int EncoderFfmpegCore::getSerial() {
return l_iSerial;
}

void EncoderFfmpegCore::encodeBuffer(const CSAMPLE *samples, const int size) {
void EncoderFfmpegCore::encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) {
unsigned char *l_strBuffer = NULL;
int l_iBufferLen = 0;
//int l_iAudioCpyLen = m_iAudioInputFrameSize *
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderffmpegcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EncoderFfmpegCore : public Encoder {
#endif
~EncoderFfmpegCore();
int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) override;
void encodeBuffer(const CSAMPLE *samples, const int size) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;
void updateMetaData(const QString& artist, const QString& title, const QString& album) override;
void flush() override;
void setEncoderSettings(const EncoderSettings& settings) override;
Expand Down
49 changes: 26 additions & 23 deletions src/encoder/encodermp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,32 @@ void EncoderMp3::setEncoderSettings(const EncoderSettings& settings) {
}
}

int EncoderMp3::bufferOutGrow(int size) {
if (m_bufferOutSize >= size) {
int EncoderMp3::bufferOutGrow(std::size_t bufferSsize) {
if (m_bufferOutSize >= bufferSsize) {
return 0;
}

m_bufferOut = (unsigned char *)realloc(m_bufferOut, size);
m_bufferOut = (unsigned char*)realloc(m_bufferOut, bufferSsize);
if (m_bufferOut == nullptr) {
return -1;
}

m_bufferOutSize = size;
m_bufferOutSize = bufferSsize;
return 0;
}

int EncoderMp3::bufferInGrow(int size) {
if (m_bufferInSize >= size) {
int EncoderMp3::bufferInGrow(std::size_t bufferSsize) {
if (m_bufferInSize >= bufferSsize) {
return 0;
}

m_bufferIn[0] = (float *)realloc(m_bufferIn[0], size * sizeof(float));
m_bufferIn[1] = (float *)realloc(m_bufferIn[1], size * sizeof(float));
m_bufferIn[0] = (float*)realloc(m_bufferIn[0], bufferSsize * sizeof(float));
m_bufferIn[1] = (float*)realloc(m_bufferIn[1], bufferSsize * sizeof(float));
if ((m_bufferIn[0] == nullptr) || (m_bufferIn[1] == nullptr)) {
return -1;
}

m_bufferInSize = size;
m_bufferInSize = bufferSsize;
return 0;
}

Expand All @@ -117,7 +117,7 @@ void EncoderMp3::flush() {
return;
}
// Flush also writes ID3 tags.
int rc = lame_encode_flush(m_lameFlags, m_bufferOut, m_bufferOutSize);
int rc = lame_encode_flush(m_lameFlags, m_bufferOut, static_cast<int>(m_bufferOutSize));
if (rc < 0) {
return;
}
Expand All @@ -127,39 +127,42 @@ void EncoderMp3::flush() {
// `lame_get_lametag_frame` returns the number of bytes copied into buffer,
// or the required buffer size, if the provided buffer is too small.
// Function failed, if the return value is larger than `m_bufferOutSize`!
int numBytes = static_cast<int>(
lame_get_lametag_frame(m_lameFlags, m_bufferOut, m_bufferOutSize));
std::size_t numBytes =
lame_get_lametag_frame(m_lameFlags, m_bufferOut, m_bufferOutSize);
if (numBytes > m_bufferOutSize) {
bufferOutGrow(numBytes);
numBytes = static_cast<int>(lame_get_lametag_frame(
m_lameFlags, m_bufferOut, m_bufferOutSize));
numBytes = lame_get_lametag_frame(
m_lameFlags, m_bufferOut, m_bufferOutSize);
}
// Write the lame/xing header.
m_pCallback->seek(0);
m_pCallback->write(nullptr, m_bufferOut, 0, numBytes);
m_pCallback->write(nullptr, m_bufferOut, 0, static_cast<int>(numBytes));
}

void EncoderMp3::encodeBuffer(const CSAMPLE *samples, const int size) {
void EncoderMp3::encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) {
if (m_lameFlags == nullptr) {
return;
}
int outsize = 0;
std::size_t outsize = 0;
int rc = 0;

outsize = (int)((1.25 * size + 7200) + 1);
outsize = (int)((1.25 * bufferSize + 7200) + 1);
bufferOutGrow(outsize);

bufferInGrow(size);
bufferInGrow(bufferSize);

// Deinterleave samples. We use normalized floats in the engine [-1.0, 1.0]
// but LAME expects samples in the range [SHRT_MIN, SHRT_MAX].
for (int i = 0; i < size/2; ++i) {
for (std::size_t i = 0; i < bufferSize / 2; ++i) {
m_bufferIn[0][i] = samples[i*2] * SHRT_MAX;
m_bufferIn[1][i] = samples[i*2+1] * SHRT_MAX;
}

rc = lame_encode_buffer_float(m_lameFlags, m_bufferIn[0], m_bufferIn[1],
size/2, m_bufferOut, m_bufferOutSize);
rc = lame_encode_buffer_float(m_lameFlags,
m_bufferIn[0],
m_bufferIn[1],
static_cast<int>(bufferSize / 2),
m_bufferOut,
static_cast<int>(m_bufferOutSize));
if (rc < 0) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/encoder/encodermp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class EncoderMp3 final : public Encoder {
~EncoderMp3() override;

int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) override;
void encodeBuffer(const CSAMPLE *samples, const int size) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;
void updateMetaData(const QString& artist, const QString& title, const QString& album) override;
void flush() override;
void setEncoderSettings(const EncoderSettings& settings) override;

private:
void initStream();
int bufferOutGrow(int size);
int bufferInGrow(int size);
int bufferOutGrow(std::size_t bufferSsize);
int bufferInGrow(std::size_t bufferSsize);

lame_t m_lameFlags;
QString m_metaDataTitle;
Expand All @@ -35,9 +35,9 @@ class EncoderMp3 final : public Encoder {
vbr_mode m_encoding_mode;
MPEG_mode_e m_stereo_mode;
unsigned char *m_bufferOut;
int m_bufferOutSize;
std::size_t m_bufferOutSize;
float* m_bufferIn[2];
int m_bufferInSize;
std::size_t m_bufferInSize;

EncoderCallback* m_pCallback;
};
4 changes: 2 additions & 2 deletions src/encoder/encoderopus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ void EncoderOpus::pushTagsPacket() {
}
}

void EncoderOpus::encodeBuffer(const CSAMPLE *samples, const int size) {
void EncoderOpus::encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) {
if (!m_pOpus) {
return;
}

int writeRequired = size;
int writeRequired = static_cast<int>(bufferSize);
int writeAvailable = m_fifoBuffer.writeAvailable();
if (writeRequired > writeAvailable) {
kLogger.warning() << "FIFO buffer too small, losing samples!"
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderopus.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EncoderOpus: public Encoder {
~EncoderOpus() override;

int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) override;
void encodeBuffer(const CSAMPLE *samples, const int size) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;
void updateMetaData(const QString& artist, const QString& title, const QString& album) override;
void flush() override;
void setEncoderSettings(const EncoderSettings& settings) override;
Expand Down
10 changes: 5 additions & 5 deletions src/encoder/encodersndfileflac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ void EncoderSndfileFlac::setEncoderSettings(const EncoderSettings& settings)
m_compression = static_cast<double>(settings.getCompression()) / 8.0;
}

void EncoderSndfileFlac::encodeBuffer(const CSAMPLE* pBuffer, const int iBufferSize) {
void EncoderSndfileFlac::encodeBuffer(const CSAMPLE* pBuffer, const std::size_t bufferSize) {
if (m_pClampBuffer) {
SINT numSamplesLeft = iBufferSize;
while (numSamplesLeft > 0) {
SINT numSamplesLeft = bufferSize;
while (numSamplesLeft > 0) {
const SINT numSamplesToWrite = math_min(numSamplesLeft, kEncBufferSize);
convertFloat32ToIntFormat(m_pClampBuffer.get(),
pBuffer,
Expand All @@ -70,9 +70,9 @@ void EncoderSndfileFlac::encodeBuffer(const CSAMPLE* pBuffer, const int iBufferS
sf_write_int(m_pSndfile, m_pClampBuffer.get(), numSamplesToWrite);
pBuffer += numSamplesToWrite;
numSamplesLeft -= numSamplesToWrite;
}
}
} else {
sf_write_float(m_pSndfile, pBuffer, iBufferSize);
sf_write_float(m_pSndfile, pBuffer, bufferSize);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encodersndfileflac.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EncoderSndfileFlac : public EncoderWave {
~EncoderSndfileFlac() override = default;

void setEncoderSettings(const EncoderSettings& settings) override;
void encodeBuffer(const CSAMPLE* samples, const int size) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;

protected:
void initStream() override;
Expand Down
10 changes: 5 additions & 5 deletions src/encoder/encodervorbis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,25 @@ void EncoderVorbis::writePage() {
}
}

void EncoderVorbis::encodeBuffer(const CSAMPLE *samples, const int size) {
float **buffer = vorbis_analysis_buffer(&m_vdsp, size);
void EncoderVorbis::encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) {
float** buffer = vorbis_analysis_buffer(&m_vdsp, static_cast<int>(bufferSize));

// Deinterleave samples. We use normalized floats in the engine [-1.0, 1.0]
// and libvorbis expects samples in the range [-1.0, 1.0] so no conversion
// is required.
if (m_channels == 2) {
for (int i = 0; i < size/2; ++i) {
for (std::size_t i = 0; i < bufferSize / 2; ++i) {
buffer[0][i] = samples[i*2];
buffer[1][i] = samples[i*2+1];
}
}
else {
for (int i = 0; i < size/2; ++i) {
for (std::size_t i = 0; i < bufferSize / 2; ++i) {
buffer[0][i] = (samples[i*2] + samples[i*2+1]) / 2.f;
}
}
/** encodes audio **/
vorbis_analysis_wrote(&m_vdsp, size/2);
vorbis_analysis_wrote(&m_vdsp, static_cast<int>(bufferSize) / 2);
/** writes the OGG page and sends it to file or stream **/
writePage();
}
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encodervorbis.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EncoderVorbis : public Encoder {
~EncoderVorbis() override;

int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) override;
void encodeBuffer(const CSAMPLE *samples, const int size) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;
void updateMetaData(const QString& artist, const QString& title, const QString& album) override;
void flush() override;
void setEncoderSettings(const EncoderSettings& settings) override;
Expand Down
5 changes: 2 additions & 3 deletions src/encoder/encoderwave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ void EncoderWave::flush() {
sf_write_sync(m_pSndfile);
}


void EncoderWave::encodeBuffer(const CSAMPLE *pBuffer, const int iBufferSize) {
sf_write_float(m_pSndfile, pBuffer, iBufferSize);
void EncoderWave::encodeBuffer(const CSAMPLE* pBuffer, const std::size_t bufferSize) {
sf_write_float(m_pSndfile, pBuffer, bufferSize);
}

/* Originally called from enginebroadcast.cpp to update metadata information
Expand Down
2 changes: 1 addition & 1 deletion src/encoder/encoderwave.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EncoderWave : public Encoder {
~EncoderWave() override;

int initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUserErrorMessage) override;
void encodeBuffer(const CSAMPLE *samples, const int size) override;
void encodeBuffer(const CSAMPLE* samples, const std::size_t bufferSize) override;
void updateMetaData(const QString& artist, const QString& title, const QString& album) override;
void flush() override;
void setEncoderSettings(const EncoderSettings& settings) override;
Expand Down
Loading

0 comments on commit 748163d

Please sign in to comment.