From 21420a8be90df60b44926ca0860d373f4b39c222 Mon Sep 17 00:00:00 2001 From: tcoyvwac <53616399+tcoyvwac@users.noreply.github.com> Date: Thu, 30 Sep 2021 12:39:07 +0200 Subject: [PATCH] Removed pointer types for std::vector Note: m_pFifoChunkBuffer was actualy an array pointer; was not deleted safely. Refactor fixes memory leak. --- src/analyzer/analyzergain.cpp | 21 ++++++++--------- src/analyzer/analyzergain.h | 6 +++-- src/effects/lv2/lv2effectprocessor.cpp | 23 ++++++++----------- src/effects/lv2/lv2effectprocessor.h | 12 ++++++---- src/effects/lv2/lv2manifest.cpp | 13 ++++------- src/effects/lv2/lv2manifest.h | 8 ++++--- src/encoder/encoderfdkaac.cpp | 16 +++++-------- src/encoder/encoderfdkaac.h | 5 ++-- src/test/analyserwaveformtest.cpp | 21 ++++++++--------- src/test/analyzersilence_test.cpp | 9 ++++---- src/test/sampleutiltest.cpp | 12 +++++----- src/util/circularbuffer.h | 15 ++++++------ src/util/fifo.h | 8 +++---- src/util/rotary.cpp | 13 +++++------ src/util/rotary.h | 4 +++- src/vinylcontrol/vinylcontrolsignalwidget.cpp | 12 ++++------ src/vinylcontrol/vinylcontrolsignalwidget.h | 3 ++- src/vinylcontrol/vinylcontrolxwax.cpp | 12 ++++------ src/vinylcontrol/vinylcontrolxwax.h | 9 ++++---- 19 files changed, 103 insertions(+), 119 deletions(-) diff --git a/src/analyzer/analyzergain.cpp b/src/analyzer/analyzergain.cpp index 0451afc759a9..074ac38971a0 100644 --- a/src/analyzer/analyzergain.cpp +++ b/src/analyzer/analyzergain.cpp @@ -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; } @@ -40,15 +36,16 @@ bool AnalyzerGain::processSamples(const CSAMPLE *pIn, const int iLen) { int halfLength = static_cast(iLen / 2); if (halfLength > m_iBufferSize) { - delete[] m_pLeftTempBuffer; - delete[] m_pRightTempBuffer; - m_pLeftTempBuffer = new CSAMPLE[halfLength]; - m_pRightTempBuffer = new CSAMPLE[halfLength]; + m_pLeftTempBuffer = std::vector(halfLength); + m_pRightTempBuffer = std::vector(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) { diff --git a/src/analyzer/analyzergain.h b/src/analyzer/analyzergain.h index 1a0344da0c43..904b66556f94 100644 --- a/src/analyzer/analyzergain.h +++ b/src/analyzer/analyzergain.h @@ -7,6 +7,8 @@ #pragma once +#include + #include "analyzer/analyzer.h" #include "preferences/replaygainsettings.h" @@ -30,8 +32,8 @@ class AnalyzerGain : public Analyzer { private: ReplayGainSettings m_rgSettings; - CSAMPLE* m_pLeftTempBuffer; - CSAMPLE* m_pRightTempBuffer; + std::vector m_pLeftTempBuffer; + std::vector m_pRightTempBuffer; ReplayGain* m_pReplayGain; int m_iBufferSize; }; diff --git a/src/effects/lv2/lv2effectprocessor.cpp b/src/effects/lv2/lv2effectprocessor.cpp index d455c4a4f6e8..64a5cc3501ae 100644 --- a/src/effects/lv2/lv2effectprocessor.cpp +++ b/src/effects/lv2/lv2effectprocessor.cpp @@ -13,11 +13,11 @@ LV2EffectProcessor::LV2EffectProcessor(EngineEffect* pEngineEffect, 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()]; + m_inputL = std::vector(MAX_BUFFER_LEN); + m_inputR = std::vector(MAX_BUFFER_LEN); + m_outputL = std::vector(MAX_BUFFER_LEN); + m_outputR = std::vector(MAX_BUFFER_LEN); + m_params = std::vector(pManifest->parameters().size()); const QList& effectManifestParameterList = pManifest->parameters(); @@ -51,11 +51,6 @@ LV2EffectProcessor::~LV2EffectProcessor() { } m_channelStateMatrix.clear(); - delete[] m_inputL; - delete[] m_inputR; - delete[] m_outputL; - delete[] m_outputR; - delete[] m_params; } void LV2EffectProcessor::initialize( @@ -148,10 +143,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); } diff --git a/src/effects/lv2/lv2effectprocessor.h b/src/effects/lv2/lv2effectprocessor.h index 9be7cd6206aa..f9d330e9aebb 100644 --- a/src/effects/lv2/lv2effectprocessor.h +++ b/src/effects/lv2/lv2effectprocessor.h @@ -2,6 +2,8 @@ #include +#include + #include "effects/defs.h" #include "effects/effectmanifest.h" #include "effects/effectprocessor.h" @@ -56,11 +58,11 @@ class LV2EffectProcessor : public EffectProcessor { LV2EffectGroupState* createGroupState(const mixxx::EngineParameters& bufferParameters); QList m_parameters; - float* m_inputL; - float* m_inputR; - float* m_outputL; - float* m_outputR; - float* m_params; + std::vector m_inputL; + std::vector m_inputR; + std::vector m_outputL; + std::vector m_outputR; + std::vector m_params; const LilvPlugin* m_pPlugin; const QList m_audioPortIndices; const QList m_controlPortIndices; diff --git a/src/effects/lv2/lv2manifest.cpp b/src/effects/lv2/lv2manifest.cpp index 31c854eca67b..65a119504d7a 100644 --- a/src/effects/lv2/lv2manifest.cpp +++ b/src/effects/lv2/lv2manifest.cpp @@ -25,11 +25,11 @@ 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); + m_minimum = std::vector(numPorts); + m_maximum = std::vector(numPorts); + m_default = std::vector(numPorts); + 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; @@ -153,9 +153,6 @@ LV2Manifest::LV2Manifest(const LilvPlugin* plug, } LV2Manifest::~LV2Manifest() { - delete[] m_minimum; - delete[] m_maximum; - delete[] m_default; } EffectManifestPointer LV2Manifest::getEffectManifest() const { diff --git a/src/effects/lv2/lv2manifest.h b/src/effects/lv2/lv2manifest.h index b0978fad898f..b759f5c2f603 100644 --- a/src/effects/lv2/lv2manifest.h +++ b/src/effects/lv2/lv2manifest.h @@ -2,6 +2,8 @@ #include +#include + #include "effects/defs.h" #include "effects/effectmanifest.h" @@ -38,8 +40,8 @@ class LV2Manifest { QList controlPortIndices; // Arrays used for storing minimum, maximum and default parameter values - float* m_minimum; - float* m_maximum; - float* m_default; + std::vector m_minimum; + std::vector m_maximum; + std::vector m_default; Status m_status; }; diff --git a/src/encoder/encoderfdkaac.cpp b/src/encoder/encoderfdkaac.cpp index fef01f1de712..885081a96f18 100644 --- a/src/encoder/encoderfdkaac.cpp +++ b/src/encoder/encoderfdkaac.cpp @@ -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 @@ -164,8 +162,6 @@ EncoderFdkAac::~EncoderFdkAac() { kLogger.debug() << "Unloaded libfdk-aac"; } - delete[] m_pAacDataBuffer; - delete m_pFifoChunkBuffer; delete m_pInputFifo; } @@ -283,7 +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); - m_pAacDataBuffer = new unsigned char[kOutBufferBits * m_channels](); + m_pAacDataBuffer = std::vector(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) { @@ -347,7 +343,7 @@ int EncoderFdkAac::initEncoder(mixxx::audio::SampleRate sampleRate, QString* pUs // the Live Broadcasting implementation m_pInputFifo = new FIFO(EngineSideChain::SIDECHAIN_BUFFER_SIZE * 2); - m_pFifoChunkBuffer = new SAMPLE[m_readRequired * sizeof(SAMPLE)](); + m_pFifoChunkBuffer = std::vector(m_readRequired * sizeof(SAMPLE)); return 0; } @@ -382,12 +378,12 @@ void EncoderFdkAac::encodeBuffer(const CSAMPLE* samples, const int sampleCount) } void EncoderFdkAac::processFIFO() { - if (!m_pInputFifo || !m_pFifoChunkBuffer) { + if (!m_pInputFifo || !m_pFifoChunkBuffer.data()) { 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. @@ -414,7 +410,7 @@ void EncoderFdkAac::processFIFO() { // Output (result) Buffer AACENC_BufDesc outputBuf; outputBuf.numBufs = 1; - outputBuf.bufs = (void**)&m_pAacDataBuffer; + outputBuf.bufs = reinterpret_cast(m_pAacDataBuffer.data()); outputBuf.bufSizes = &outDataSize; outputBuf.bufElSizes = &outElemSize; outputBuf.bufferIdentifiers = &outDataDescription; @@ -433,7 +429,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); } } diff --git a/src/encoder/encoderfdkaac.h b/src/encoder/encoderfdkaac.h index e7a85549ee89..684f94ebbfe6 100644 --- a/src/encoder/encoderfdkaac.h +++ b/src/encoder/encoderfdkaac.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "encoder/encoder.h" #include "util/fifo.h" @@ -205,10 +206,10 @@ class EncoderFdkAac : public Encoder { EncoderCallback* m_pCallback; std::unique_ptr m_pLibrary; FIFO* m_pInputFifo; - SAMPLE* m_pFifoChunkBuffer; + std::vector m_pFifoChunkBuffer; int m_readRequired; HANDLE_AACENCODER m_aacEnc; - unsigned char* m_pAacDataBuffer; + std::vector m_pAacDataBuffer; AACENC_InfoStruct m_aacInfo; bool m_hasSbr; }; diff --git a/src/test/analyserwaveformtest.cpp b/src/test/analyserwaveformtest.cpp index bab8c4489264..af38186b1aca 100644 --- a/src/test/analyserwaveformtest.cpp +++ b/src/test/analyserwaveformtest.cpp @@ -1,11 +1,12 @@ #include + #include #include - -#include "test/mixxxtest.h" +#include #include "analyzer/analyzerwaveform.h" #include "library/dao/analysisdao.h" +#include "test/mixxxtest.h" #include "track/track.h" #define BIGBUF_SIZE (1024 * 1024) //Megabyte @@ -19,8 +20,8 @@ class AnalyzerWaveformTest : public MixxxTest { protected: AnalyzerWaveformTest() : aw(config(), QSqlDatabase()), - bigbuf(nullptr), - canaryBigBuf(nullptr) { + bigbuf(), + canaryBigBuf() { } void SetUp() override { @@ -31,14 +32,14 @@ class AnalyzerWaveformTest : public MixxxTest { mixxx::audio::Bitrate(), mixxx::Duration::fromMillis(1000)); - bigbuf = new CSAMPLE[BIGBUF_SIZE]; + bigbuf = std::vector(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 = std::vector(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++) @@ -48,21 +49,19 @@ class AnalyzerWaveformTest : public MixxxTest { } void TearDown() override { - delete[] bigbuf; - delete[] canaryBigBuf; } protected: AnalyzerWaveform aw; TrackPointer tio; - CSAMPLE* bigbuf; - CSAMPLE* canaryBigBuf; + std::vector bigbuf; + std::vector 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++) { diff --git a/src/test/analyzersilence_test.cpp b/src/test/analyzersilence_test.cpp index 1a3af6ae7314..6b6e68f4d3a4 100644 --- a/src/test/analyzersilence_test.cpp +++ b/src/test/analyzersilence_test.cpp @@ -2,6 +2,8 @@ #include +#include + #include "engine/engine.h" #include "test/mixxxtest.h" #include "track/track.h" @@ -27,16 +29,15 @@ class AnalyzerSilenceTest : public MixxxTest { mixxx::Duration::fromSeconds(kTrackLengthFrames / 44100.0)); nTrackSampleDataLength = kChannelCount * kTrackLengthFrames; - pTrackSampleData = new CSAMPLE[nTrackSampleDataLength]; + pTrackSampleData = std::vector(nTrackSampleDataLength); } void TearDown() override { - delete[] pTrackSampleData; } void analyzeTrack() { analyzerSilence.initialize(pTrack, pTrack->getSampleRate(), nTrackSampleDataLength); - analyzerSilence.processSamples(pTrackSampleData, nTrackSampleDataLength); + analyzerSilence.processSamples(pTrackSampleData.data(), nTrackSampleDataLength); analyzerSilence.storeResults(pTrack); analyzerSilence.cleanup(); } @@ -44,7 +45,7 @@ class AnalyzerSilenceTest : public MixxxTest { protected: AnalyzerSilence analyzerSilence; TrackPointer pTrack; - CSAMPLE* pTrackSampleData; + std::vector pTrackSampleData; int nTrackSampleDataLength; // in samples }; diff --git a/src/test/sampleutiltest.cpp b/src/test/sampleutiltest.cpp index b890fef13c7f..a0f68c25105e 100644 --- a/src/test/sampleutiltest.cpp +++ b/src/test/sampleutiltest.cpp @@ -1,9 +1,10 @@ #include #include -#include #include #include +#include +#include #include "util/sample.h" #include "util/timer.h" @@ -260,12 +261,12 @@ TEST_F(SampleUtilTest, convertS16ToFloat32) { for (int i = 0; i < buffers.size(); ++i) { CSAMPLE* buffer = buffers[i]; int size = sizes[i]; - SAMPLE* s16 = new SAMPLE[size]; + std::vector s16(size); FillBuffer(buffer, 1.0f, size); for (int j = 0; j < size; ++j) { s16[j] = SAMPLE_MAXIMUM; } - SampleUtil::convertS16ToFloat32(buffer, s16, size); + SampleUtil::convertS16ToFloat32(buffer, s16.data(), size); for (int j = 0; j < size; ++j) { EXPECT_FLOAT_EQ(expectedMax, buffer[j]); } @@ -273,7 +274,7 @@ TEST_F(SampleUtilTest, convertS16ToFloat32) { for (int j = 0; j < size; ++j) { s16[j] = 0; } - SampleUtil::convertS16ToFloat32(buffer, s16, size); + SampleUtil::convertS16ToFloat32(buffer, s16.data(), size); for (int j = 0; j < size; ++j) { EXPECT_FLOAT_EQ(0.0f, buffer[j]); } @@ -281,11 +282,10 @@ TEST_F(SampleUtilTest, convertS16ToFloat32) { for (int j = 0; j < size; ++j) { s16[j] = SAMPLE_MINIMUM; } - SampleUtil::convertS16ToFloat32(buffer, s16, size); + SampleUtil::convertS16ToFloat32(buffer, s16.data(), size); for (int j = 0; j < size; ++j) { EXPECT_FLOAT_EQ(-1.0f, buffer[j]); } - delete [] s16; } } diff --git a/src/util/circularbuffer.h b/src/util/circularbuffer.h index 1fe650f24155..90c95ec0fb1a 100644 --- a/src/util/circularbuffer.h +++ b/src/util/circularbuffer.h @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include // CircularBuffer is a basic implementation of a constant-length circular // buffer. @@ -14,7 +15,7 @@ class CircularBuffer { public: CircularBuffer(unsigned int iLength) : m_iLength(iLength), - m_pBuffer(new T[m_iLength]), + m_pBuffer(std::vector(m_iLength)), m_iWritePos(0), m_iReadPos(0) { // No need to clear the buffer because we consider it to be empty right @@ -22,8 +23,6 @@ class CircularBuffer { } virtual ~CircularBuffer() { - delete [] m_pBuffer; - m_pBuffer = NULL; } // Returns true if the buffer is full @@ -50,7 +49,7 @@ class CircularBuffer { // items written, which could be less than numItems if the buffer becomes // full. unsigned int write(const T* pBuffer, const unsigned int numItems) { - if (m_pBuffer == NULL) + if (m_pBuffer.empty()) return 0; unsigned int itemsWritten = 0; @@ -64,7 +63,7 @@ class CircularBuffer { // Read itemsToRead into pBuffer. Returns the total number of items read, // which may be less than itemsToRead if the buffer becomes empty. unsigned int read(T* pBuffer, const unsigned int itemsToRead) { - if (m_pBuffer == NULL) + if (m_pBuffer.empty()) return 0; unsigned int itemsRead = 0; @@ -76,7 +75,7 @@ class CircularBuffer { } unsigned int skip(const unsigned int itemsToRead) { - if (m_pBuffer == NULL) + if (m_pBuffer.empty()) return 0; unsigned int itemsRead = 0; while (!isEmpty() && itemsRead < itemsToRead) { @@ -88,7 +87,7 @@ class CircularBuffer { private: const unsigned int m_iLength; - T* m_pBuffer; + std::vector m_pBuffer; unsigned int m_iWritePos; unsigned int m_iReadPos; }; diff --git a/src/util/fifo.h b/src/util/fifo.h index dac6b28a1b5c..63cb90a7c5fa 100644 --- a/src/util/fifo.h +++ b/src/util/fifo.h @@ -9,18 +9,16 @@ template class FIFO { public: explicit FIFO(int size) - : m_data(NULL) { + : m_data{std::vector(size)} { size = roundUpToPowerOf2(size); // If we can't represent the next higher power of 2 then bail. if (size < 0) { return; } - m_data = new DataType[size]; PaUtil_InitializeRingBuffer( - &m_ringBuffer, sizeof(DataType), size, m_data); + &m_ringBuffer, sizeof(DataType), size, m_data.data()); } virtual ~FIFO() { - delete [] m_data; } int readAvailable() const { return PaUtil_GetRingBufferReadAvailable(&m_ringBuffer); @@ -64,7 +62,7 @@ class FIFO { } private: - DataType* m_data; + std::vector m_data; PaUtilRingBuffer m_ringBuffer; DISALLOW_COPY_AND_ASSIGN(FIFO); }; diff --git a/src/util/rotary.cpp b/src/util/rotary.cpp index 94355b2beb19..66cc81a95a52 100644 --- a/src/util/rotary.cpp +++ b/src/util/rotary.cpp @@ -5,19 +5,18 @@ constexpr int kiRotaryFilterMaxLen = 50; Rotary::Rotary() - : m_iFilterPos(0), - m_dCalibration(1.0), - m_dLastValue(0.0), - m_iCalibrationCount(0) { - m_iFilterLength = kiRotaryFilterMaxLen; - m_pFilter = new double[m_iFilterLength]; + : m_iFilterLength(kiRotaryFilterMaxLen), + m_iFilterPos(0), + m_pFilter(std::vector(m_iFilterLength)), + m_dCalibration(1.0), + m_dLastValue(0.0), + m_iCalibrationCount(0) { for (int i = 0; i < m_iFilterLength; ++i) { m_pFilter[i] = 0.; } } Rotary::~Rotary() { - delete [] m_pFilter; } /* Note: There's probably a bug in this function (or this class) somewhere. diff --git a/src/util/rotary.h b/src/util/rotary.h index c886a1a9bc9c..2709757e049d 100644 --- a/src/util/rotary.h +++ b/src/util/rotary.h @@ -1,5 +1,7 @@ #pragma once +#include + class Rotary { public: Rotary(); @@ -30,7 +32,7 @@ class Rotary { // Update position in filter int m_iFilterPos; // Pointer to rotary filter buffer - double *m_pFilter; + std::vector m_pFilter; // Calibration value double m_dCalibration; // Last value diff --git a/src/vinylcontrol/vinylcontrolsignalwidget.cpp b/src/vinylcontrol/vinylcontrolsignalwidget.cpp index 690eb4643d46..2984f67130de 100644 --- a/src/vinylcontrol/vinylcontrolsignalwidget.cpp +++ b/src/vinylcontrol/vinylcontrolsignalwidget.cpp @@ -7,7 +7,6 @@ VinylControlSignalWidget::VinylControlSignalWidget() m_iVinylInput(-1), m_iSize(MIXXX_VINYL_SCOPE_SIZE), m_qImage(), - m_imageData(nullptr), m_iAngle(0), m_fSignalQuality(0.0f), m_bVinylActive(false) { @@ -18,8 +17,8 @@ void VinylControlSignalWidget::setSize(int size) { setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); setMinimumSize(size, size); setMaximumSize(size, size); - m_imageData = new uchar[size * size * 4]; - m_qImage = QImage(m_imageData, size, size, 0, QImage::Format_ARGB32); + m_imageData = std::vector(size * size * 4); + m_qImage = QImage(m_imageData.data(), size, size, 0, QImage::Format_ARGB32); } void VinylControlSignalWidget::setVinylInput(int input) { @@ -27,7 +26,6 @@ void VinylControlSignalWidget::setVinylInput(int input) { } VinylControlSignalWidget::~VinylControlSignalWidget() { - delete [] m_imageData; } void VinylControlSignalWidget::setVinylActive(bool active) @@ -57,7 +55,7 @@ void VinylControlSignalWidget::onVinylSignalQualityUpdate(const VinylSignalQuali qual_color.setHsv((int)(120.0 * m_fSignalQuality), 255, 255); qual_color.getRgb(&r, &g, &b); - if (m_imageData == nullptr) { + if (m_imageData.empty()) { return; } @@ -76,9 +74,7 @@ void VinylControlSignalWidget::onVinylSignalQualityUpdate(const VinylSignalQuali void VinylControlSignalWidget::resetWidget() { - if (m_imageData != nullptr) { - memset(m_imageData, 0, sizeof(uchar) * m_iSize * m_iSize * 4); - } + m_imageData = std::vector(m_iSize * m_iSize * 4); } void VinylControlSignalWidget::paintEvent(QPaintEvent* event) { diff --git a/src/vinylcontrol/vinylcontrolsignalwidget.h b/src/vinylcontrol/vinylcontrolsignalwidget.h index 90bb687c70b9..e82277ccf3a5 100644 --- a/src/vinylcontrol/vinylcontrolsignalwidget.h +++ b/src/vinylcontrol/vinylcontrolsignalwidget.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "vinylcontrol/vinylsignalquality.h" @@ -36,7 +37,7 @@ class VinylControlSignalWidget : public QWidget, public VinylSignalQualityListen int m_iSize; QImage m_qImage; - unsigned char * m_imageData; + std::vector m_imageData; int m_iAngle; float m_fSignalQuality; bool m_bVinylActive; diff --git a/src/vinylcontrol/vinylcontrolxwax.cpp b/src/vinylcontrol/vinylcontrolxwax.cpp index fb56654d283f..cc517a5b148f 100644 --- a/src/vinylcontrol/vinylcontrolxwax.cpp +++ b/src/vinylcontrol/vinylcontrolxwax.cpp @@ -29,7 +29,7 @@ QMutex VinylControlXwax::s_xwaxLUTMutex; VinylControlXwax::VinylControlXwax(UserSettingsPointer pConfig, const QString& group) : VinylControl(pConfig, group), m_dVinylPositionOld(0.0), - m_pWorkBuffer(new short[MAX_BUFFER_LEN]), + m_pWorkBuffer(std::vector(MAX_BUFFER_LEN)), m_workBufferSize(MAX_BUFFER_LEN), m_iQualPos(0), m_iQualFilled(0), @@ -42,7 +42,6 @@ VinylControlXwax::VinylControlXwax(UserSettingsPointer pConfig, const QString& g m_dOldDuration(0.0), m_dOldDurationInaccurate(-1.0), m_bWasReversed(false), - m_pPitchRing(nullptr), m_iPitchRingSize(0), m_iPitchRingPos(0), m_iPitchRingFilled(0), @@ -130,7 +129,7 @@ VinylControlXwax::VinylControlXwax(UserSettingsPointer pConfig, const QString& g // Set pitch ring size to 1/4 of one revolution -- a full revolution adds // too much stickiness to the pitch. m_iPitchRingSize = static_cast(60000 / (rpm * latency * 4)); - m_pPitchRing = new double[m_iPitchRingSize]; + m_pPitchRing = std::vector(m_iPitchRingSize); qDebug() << "Xwax Vinyl control starting with a sample rate of:" << iSampleRate; qDebug() << "Building timecode lookup tables for" << strVinylType << "with speed" << strVinylSpeed; @@ -154,8 +153,6 @@ VinylControlXwax::VinylControlXwax(UserSettingsPointer pConfig, const QString& g VinylControlXwax::~VinylControlXwax() { delete m_pSteadySubtle; delete m_pSteadyGross; - delete [] m_pPitchRing; - delete [] m_pWorkBuffer; // Cleanup xwax nicely timecoder_monitor_clear(&timecoder); @@ -202,8 +199,7 @@ void VinylControlXwax::analyzeSamples(CSAMPLE* pSamples, size_t nFrames) { size_t samplesSize = nFrames * kChannels; if (samplesSize > m_workBufferSize) { - delete [] m_pWorkBuffer; - m_pWorkBuffer = new short[samplesSize]; + m_pWorkBuffer = std::vector(samplesSize); m_workBufferSize = samplesSize; } @@ -222,7 +218,7 @@ void VinylControlXwax::analyzeSamples(CSAMPLE* pSamples, size_t nFrames) { // Submit the samples to the xwax timecode processor. The size argument is // in stereo frames. - timecoder_submit(&timecoder, m_pWorkBuffer, nFrames); + timecoder_submit(&timecoder, m_pWorkBuffer.data(), nFrames); bool bHaveSignal = fabs(pSamples[0]) + fabs(pSamples[1]) > kMinSignal; //qDebug() << "signal?" << bHaveSignal; diff --git a/src/vinylcontrol/vinylcontrolxwax.h b/src/vinylcontrol/vinylcontrolxwax.h index 71a5f72a79f3..06c9180ffaaa 100644 --- a/src/vinylcontrol/vinylcontrolxwax.h +++ b/src/vinylcontrol/vinylcontrolxwax.h @@ -1,11 +1,12 @@ #pragma once #include +#include #include "soundio/soundmanagerutil.h" -#include "vinylcontrol/vinylcontrol.h" -#include "vinylcontrol/steadypitch.h" #include "util/types.h" +#include "vinylcontrol/steadypitch.h" +#include "vinylcontrol/vinylcontrol.h" #ifdef _MSC_VER #include "timecoder.h" @@ -53,7 +54,7 @@ class VinylControlXwax : public VinylControl { double m_dVinylPositionOld; // Scratch buffer for CSAMPLE -> short conversions. - short* m_pWorkBuffer; + std::vector m_pWorkBuffer; size_t m_workBufferSize; // Signal quality ring buffer. @@ -91,7 +92,7 @@ class VinylControlXwax : public VinylControl { // The pitch ring buffer. // TODO(XXX): Replace with CircularBuffer instead of handling the ring logic // in VinylControlXwax. - double* m_pPitchRing; + std::vector m_pPitchRing; // How large the pitch ring buffer is. int m_iPitchRingSize; // Our current position in the pitch ring buffer.