Skip to content

Commit

Permalink
Merge pull request #4341 from tcoyvwac/fix/remove-raw-pointer-types
Browse files Browse the repository at this point in the history
Removed raw array pointer types for std::vector
  • Loading branch information
uklotzde authored Oct 19, 2021
2 parents b077d80 + 242e631 commit 070a475
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 143 deletions.
21 changes: 9 additions & 12 deletions src/analyzer/analyzergain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

AnalyzerGain::AnalyzerGain(UserSettingsPointer pConfig)
: m_rgSettings(pConfig),
m_pLeftTempBuffer(nullptr),
m_pRightTempBuffer(nullptr),
m_iBufferSize(0) {
m_pReplayGain = new ReplayGain();
}

AnalyzerGain::~AnalyzerGain() {
delete[] m_pLeftTempBuffer;
delete[] m_pRightTempBuffer;
delete m_pReplayGain;
}

Expand All @@ -40,15 +36,16 @@ bool AnalyzerGain::processSamples(const CSAMPLE *pIn, const int iLen) {

int halfLength = static_cast<int>(iLen / 2);
if (halfLength > m_iBufferSize) {
delete[] m_pLeftTempBuffer;
delete[] m_pRightTempBuffer;
m_pLeftTempBuffer = new CSAMPLE[halfLength];
m_pRightTempBuffer = new CSAMPLE[halfLength];
m_pLeftTempBuffer.resize(halfLength);
m_pRightTempBuffer.resize(halfLength);
}
SampleUtil::deinterleaveBuffer(m_pLeftTempBuffer, m_pRightTempBuffer, pIn, halfLength);
SampleUtil::applyGain(m_pLeftTempBuffer, 32767, halfLength);
SampleUtil::applyGain(m_pRightTempBuffer, 32767, halfLength);
return m_pReplayGain->process(m_pLeftTempBuffer, m_pRightTempBuffer, halfLength);
SampleUtil::deinterleaveBuffer(m_pLeftTempBuffer.data(),
m_pRightTempBuffer.data(),
pIn,
halfLength);
SampleUtil::applyGain(m_pLeftTempBuffer.data(), 32767, halfLength);
SampleUtil::applyGain(m_pRightTempBuffer.data(), 32767, halfLength);
return m_pReplayGain->process(m_pLeftTempBuffer.data(), m_pRightTempBuffer.data(), halfLength);
}

void AnalyzerGain::storeResults(TrackPointer tio) {
Expand Down
6 changes: 4 additions & 2 deletions src/analyzer/analyzergain.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <vector>

#include "analyzer/analyzer.h"
#include "preferences/replaygainsettings.h"

Expand All @@ -30,8 +32,8 @@ class AnalyzerGain : public Analyzer {

private:
ReplayGainSettings m_rgSettings;
CSAMPLE* m_pLeftTempBuffer;
CSAMPLE* m_pRightTempBuffer;
std::vector<CSAMPLE> m_pLeftTempBuffer;
std::vector<CSAMPLE> m_pRightTempBuffer;
ReplayGain* m_pReplayGain;
int m_iBufferSize;
};
26 changes: 10 additions & 16 deletions src/effects/lv2/lv2effectprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ LV2EffectProcessor::LV2EffectProcessor(EngineEffect* pEngineEffect,
const LilvPlugin* plugin,
const QList<int>& audioPortIndices,
const QList<int>& controlPortIndices)
: m_pPlugin(plugin),
: m_inputL(MAX_BUFFER_LEN),
m_inputR(MAX_BUFFER_LEN),
m_outputL(MAX_BUFFER_LEN),
m_outputR(MAX_BUFFER_LEN),
m_params(pManifest->parameters().size()),
m_pPlugin(plugin),
m_audioPortIndices(audioPortIndices),
m_controlPortIndices(controlPortIndices),
m_pEffectsManager(nullptr) {
m_inputL = new float[MAX_BUFFER_LEN];
m_inputR = new float[MAX_BUFFER_LEN];
m_outputL = new float[MAX_BUFFER_LEN];
m_outputR = new float[MAX_BUFFER_LEN];
m_params = new float[pManifest->parameters().size()];

const QList<EffectManifestParameterPointer>& effectManifestParameterList =
pManifest->parameters();

Expand Down Expand Up @@ -51,11 +50,6 @@ LV2EffectProcessor::~LV2EffectProcessor() {
}
m_channelStateMatrix.clear();

delete[] m_inputL;
delete[] m_inputR;
delete[] m_outputL;
delete[] m_outputR;
delete[] m_params;
}

void LV2EffectProcessor::initialize(
Expand Down Expand Up @@ -147,10 +141,10 @@ LV2EffectGroupState* LV2EffectProcessor::createGroupState(const mixxx::EnginePar

// We assume the audio ports are in the following order:
// input_left, input_right, output_left, output_right
lilv_instance_connect_port(handle, m_audioPortIndices[0], m_inputL);
lilv_instance_connect_port(handle, m_audioPortIndices[1], m_inputR);
lilv_instance_connect_port(handle, m_audioPortIndices[2], m_outputL);
lilv_instance_connect_port(handle, m_audioPortIndices[3], m_outputR);
lilv_instance_connect_port(handle, m_audioPortIndices[0], m_inputL.data());
lilv_instance_connect_port(handle, m_audioPortIndices[1], m_inputR.data());
lilv_instance_connect_port(handle, m_audioPortIndices[2], m_outputL.data());
lilv_instance_connect_port(handle, m_audioPortIndices[3], m_outputR.data());

lilv_instance_activate(handle);
}
Expand Down
12 changes: 7 additions & 5 deletions src/effects/lv2/lv2effectprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <lilv/lilv.h>

#include <vector>

#include "effects/defs.h"
#include "effects/effectmanifest.h"
#include "effects/effectprocessor.h"
Expand Down Expand Up @@ -56,11 +58,11 @@ class LV2EffectProcessor : public EffectProcessor {
LV2EffectGroupState* createGroupState(const mixxx::EngineParameters& bufferParameters);

QList<EngineEffectParameter*> m_parameters;
float* m_inputL;
float* m_inputR;
float* m_outputL;
float* m_outputR;
float* m_params;
std::vector<CSAMPLE> m_inputL;
std::vector<CSAMPLE> m_inputR;
std::vector<CSAMPLE> m_outputL;
std::vector<CSAMPLE> m_outputR;
std::vector<CSAMPLE> m_params;
const LilvPlugin* m_pPlugin;
const QList<int> m_audioPortIndices;
const QList<int> m_controlPortIndices;
Expand Down
22 changes: 9 additions & 13 deletions src/effects/lv2/lv2manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
#include "util/fpclassify.h"

LV2Manifest::LV2Manifest(const LilvPlugin* plug,
QHash<QString, LilvNode*>& properties)
QHash<QString, LilvNode*>& properties)
: m_pEffectManifest(new EffectManifest()),
m_status(AVAILABLE) {
m_minimum(lilv_plugin_get_num_ports(plug)),

m_maximum(lilv_plugin_get_num_ports(plug)),

m_default(lilv_plugin_get_num_ports(plug)),

m_status(AVAILABLE) {
m_pLV2plugin = plug;

// Get and set the ID
Expand All @@ -25,11 +30,8 @@ LV2Manifest::LV2Manifest(const LilvPlugin* plug,
lilv_node_free(info);

int numPorts = lilv_plugin_get_num_ports(plug);
m_minimum = new float[numPorts];
m_maximum = new float[numPorts];
m_default = new float[numPorts];
lilv_plugin_get_port_ranges_float(m_pLV2plugin, m_minimum, m_maximum,
m_default);
lilv_plugin_get_port_ranges_float(
m_pLV2plugin, m_minimum.data(), m_maximum.data(), m_default.data());

// Counters to determine the type of the plug in
int inputPorts = 0;
Expand Down Expand Up @@ -152,12 +154,6 @@ LV2Manifest::LV2Manifest(const LilvPlugin* plug,
lilv_nodes_free(features);
}

LV2Manifest::~LV2Manifest() {
delete[] m_minimum;
delete[] m_maximum;
delete[] m_default;
}

EffectManifestPointer LV2Manifest::getEffectManifest() const {
return m_pEffectManifest;
}
Expand Down
9 changes: 5 additions & 4 deletions src/effects/lv2/lv2manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <lilv/lilv.h>

#include <vector>

#include "effects/defs.h"
#include "effects/effectmanifest.h"

Expand All @@ -14,7 +16,6 @@ class LV2Manifest {
};

LV2Manifest(const LilvPlugin* plug, QHash<QString, LilvNode*>& properties);
~LV2Manifest();
EffectManifestPointer getEffectManifest() const;
QList<int> getAudioPortIndices();
QList<int> getControlPortIndices();
Expand All @@ -38,8 +39,8 @@ class LV2Manifest {
QList<int> controlPortIndices;

// Arrays used for storing minimum, maximum and default parameter values
float* m_minimum;
float* m_maximum;
float* m_default;
std::vector<float> m_minimum;
std::vector<float> m_maximum;
std::vector<float> m_default;
Status m_status;
};
28 changes: 9 additions & 19 deletions src/encoder/encoderfdkaac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ EncoderFdkAac::EncoderFdkAac(EncoderCallback* pCallback)
m_pCallback(pCallback),
m_pLibrary(nullptr),
m_pInputFifo(nullptr),
m_pFifoChunkBuffer(nullptr),
m_readRequired(0),
m_aacEnc(),
m_pAacDataBuffer(nullptr),
m_aacInfo(),
m_hasSbr(false) {
// Load the shared library
Expand Down Expand Up @@ -164,8 +162,6 @@ EncoderFdkAac::~EncoderFdkAac() {
kLogger.debug() << "Unloaded libfdk-aac";
}

delete[] m_pAacDataBuffer;
delete[] m_pFifoChunkBuffer;
delete m_pInputFifo;
}

Expand Down Expand Up @@ -283,11 +279,7 @@ int EncoderFdkAac::initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUs
// This initializes the encoder handle but not the encoder itself.
// Actual encoder init is done below.
aacEncOpen(&m_aacEnc, 0, m_channels);
VERIFY_OR_DEBUG_ASSERT(!m_pAacDataBuffer) {
delete[] m_pAacDataBuffer;
m_pAacDataBuffer = nullptr;
}
m_pAacDataBuffer = new unsigned char[kOutBufferBits * m_channels]();
m_pAacDataBuffer.resize(kOutBufferBits * m_channels);

// AAC Object Type: specifies "mode": AAC-LC, HE-AAC, HE-AACv2, DAB AAC, etc...
if (aacEncoder_SetParam(m_aacEnc, AACENC_AOT, m_aacAot) != AACENC_OK) {
Expand Down Expand Up @@ -355,11 +347,7 @@ int EncoderFdkAac::initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUs
}
m_pInputFifo = new FIFO<SAMPLE>(EngineSideChain::SIDECHAIN_BUFFER_SIZE * 2);

VERIFY_OR_DEBUG_ASSERT(!m_pFifoChunkBuffer) {
delete[] m_pFifoChunkBuffer;
m_pFifoChunkBuffer = nullptr;
}
m_pFifoChunkBuffer = new SAMPLE[m_readRequired * sizeof(SAMPLE)]();
m_pFifoChunkBuffer.resize(m_readRequired * sizeof(SAMPLE));
return 0;
}

Expand Down Expand Up @@ -394,12 +382,12 @@ void EncoderFdkAac::encodeBuffer(const CSAMPLE* samples, const int sampleCount)
}

void EncoderFdkAac::processFIFO() {
if (!m_pInputFifo || !m_pFifoChunkBuffer) {
if (!m_pInputFifo || m_pFifoChunkBuffer.empty()) {
return;
}

while (m_pInputFifo->readAvailable() >= m_readRequired) {
m_pInputFifo->read(m_pFifoChunkBuffer, m_readRequired);
m_pInputFifo->read(m_pFifoChunkBuffer.data(), m_readRequired);

// fdk-aac only accept pointers for most buffer settings.
// Declare settings here and point to them below.
Expand All @@ -414,7 +402,8 @@ void EncoderFdkAac::processFIFO() {
// Input Buffer
AACENC_BufDesc inputBuf;
inputBuf.numBufs = 1;
inputBuf.bufs = (void**)&m_pFifoChunkBuffer;
void* chunkBuffer[] = {m_pFifoChunkBuffer.data()};
inputBuf.bufs = chunkBuffer;
inputBuf.bufSizes = &inDataSize;
inputBuf.bufElSizes = &inSampleSize;
inputBuf.bufferIdentifiers = &inDataDescription;
Expand All @@ -426,7 +415,8 @@ void EncoderFdkAac::processFIFO() {
// Output (result) Buffer
AACENC_BufDesc outputBuf;
outputBuf.numBufs = 1;
outputBuf.bufs = (void**)&m_pAacDataBuffer;
void* dataBuffer[] = {m_pAacDataBuffer.data()};
outputBuf.bufs = dataBuffer;
outputBuf.bufSizes = &outDataSize;
outputBuf.bufElSizes = &outElemSize;
outputBuf.bufferIdentifiers = &outDataDescription;
Expand All @@ -445,7 +435,7 @@ void EncoderFdkAac::processFIFO() {
kLogger.warning() << "encoder ignored" << sampleDiff << "samples!";
}

m_pCallback->write(nullptr, m_pAacDataBuffer, 0, outputDesc.numOutBytes);
m_pCallback->write(nullptr, m_pAacDataBuffer.data(), 0, outputDesc.numOutBytes);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/encoder/encoderfdkaac.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QLibrary>
#include <QString>
#include <memory>
#include <vector>

#include "encoder/encoder.h"
#include "util/fifo.h"
Expand Down Expand Up @@ -205,10 +206,10 @@ class EncoderFdkAac : public Encoder {
EncoderCallback* m_pCallback;
std::unique_ptr<QLibrary> m_pLibrary;
FIFO<SAMPLE>* m_pInputFifo;
SAMPLE* m_pFifoChunkBuffer;
std::vector<SAMPLE> m_pFifoChunkBuffer;
int m_readRequired;
HANDLE_AACENCODER m_aacEnc;
unsigned char* m_pAacDataBuffer;
std::vector<unsigned char> m_pAacDataBuffer;
AACENC_InfoStruct m_aacInfo;
bool m_hasSbr;
};
21 changes: 9 additions & 12 deletions src/test/analyserwaveformtest.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <gtest/gtest.h>

#include <QDir>
#include <QtDebug>

#include "test/mixxxtest.h"
#include <vector>

#include "analyzer/analyzerwaveform.h"
#include "library/dao/analysisdao.h"
#include "test/mixxxtest.h"
#include "track/track.h"

#define BIGBUF_SIZE (1024 * 1024) //Megabyte
Expand All @@ -18,9 +19,7 @@ namespace {
class AnalyzerWaveformTest : public MixxxTest {
protected:
AnalyzerWaveformTest()
: aw(config(), QSqlDatabase()),
bigbuf(nullptr),
canaryBigBuf(nullptr) {
: aw(config(), QSqlDatabase()) {
}

void SetUp() override {
Expand All @@ -31,14 +30,14 @@ class AnalyzerWaveformTest : public MixxxTest {
mixxx::audio::Bitrate(),
mixxx::Duration::fromMillis(1000));

bigbuf = new CSAMPLE[BIGBUF_SIZE];
bigbuf.resize(BIGBUF_SIZE);
for (int i = 0; i < BIGBUF_SIZE; i++)
bigbuf[i] = MAGIC_FLOAT;

//Memory layout for canaryBigBuf looks like
// [ canary | big buf | canary ]

canaryBigBuf = new CSAMPLE[BIGBUF_SIZE + 2 * CANARY_SIZE];
canaryBigBuf.resize(BIGBUF_SIZE + 2 * CANARY_SIZE);
for (int i = 0; i < CANARY_SIZE; i++)
canaryBigBuf[i] = CANARY_FLOAT;
for (int i = CANARY_SIZE; i < CANARY_SIZE + BIGBUF_SIZE; i++)
Expand All @@ -48,21 +47,19 @@ class AnalyzerWaveformTest : public MixxxTest {
}

void TearDown() override {
delete[] bigbuf;
delete[] canaryBigBuf;
}

protected:
AnalyzerWaveform aw;
TrackPointer tio;
CSAMPLE* bigbuf;
CSAMPLE* canaryBigBuf;
std::vector<CSAMPLE> bigbuf;
std::vector<CSAMPLE> canaryBigBuf;
};

//Test to make sure we don't modify the source buffer.
TEST_F(AnalyzerWaveformTest, simpleAnalyze) {
aw.initialize(tio, tio->getSampleRate(), BIGBUF_SIZE);
aw.processSamples(bigbuf, BIGBUF_SIZE);
aw.processSamples(bigbuf.data(), BIGBUF_SIZE);
aw.storeResults(tio);
aw.cleanup();
for (int i = 0; i < BIGBUF_SIZE; i++) {
Expand Down
Loading

0 comments on commit 070a475

Please sign in to comment.