Use new and delete instead of malloc and free

This commit is contained in:
Iscle 2022-08-24 10:02:52 +02:00
parent 7954f0cc79
commit c357e50030
5 changed files with 76 additions and 111 deletions

View File

@ -32,10 +32,8 @@ Effect::Effect() {
}
Effect::~Effect() {
if (this->buffer != nullptr) {
delete this->buffer;
this->buffer = nullptr;
}
delete this->buffer;
this->buffer = nullptr;
}
int32_t Effect::process(audio_buffer_s *in, audio_buffer_s *out) {

View File

@ -114,87 +114,66 @@ ProcessUnit_FX::ProcessUnit_FX() {
}
ProcessUnit_FX::~ProcessUnit_FX() {
if (this->adaptiveBuffer != nullptr) {
delete this->adaptiveBuffer;
this->adaptiveBuffer = nullptr;
}
if (this->waveBuffer != nullptr) {
delete this->waveBuffer;
this->waveBuffer = nullptr;
}
if (this->convolver != nullptr) {
delete this->convolver;
this->convolver = nullptr;
}
if (this->vhe != nullptr) {
delete this->vhe;
this->vhe = nullptr;
}
if (this->viperDdc != nullptr) {
delete this->viperDdc;
this->viperDdc = nullptr;
}
if (this->spectrumExtend != nullptr) {
delete this->spectrumExtend;
this->spectrumExtend = nullptr;
}
if (this->iirFilter != nullptr) {
delete this->iirFilter;
this->iirFilter = nullptr;
}
if (this->colorfulMusic != nullptr) {
delete this->colorfulMusic;
this->colorfulMusic = nullptr;
}
if (this->reverberation != nullptr) {
delete this->reverberation;
this->reverberation = nullptr;
}
if (this->playbackGain != nullptr) {
delete this->playbackGain;
this->playbackGain = nullptr;
}
if (this->fetCompressor != nullptr) {
delete this->fetCompressor;
this->fetCompressor = nullptr;
}
if (this->dynamicSystem != nullptr) {
delete this->dynamicSystem;
this->dynamicSystem = nullptr;
}
if (this->viperBass != nullptr) {
delete this->viperBass;
this->viperBass = nullptr;
}
if (this->viperClarity != nullptr) {
delete this->viperClarity;
this->viperClarity = nullptr;
}
if (this->diffSurround != nullptr) {
delete this->diffSurround;
this->diffSurround = nullptr;
}
if (this->cure != nullptr) {
delete this->cure;
this->cure = nullptr;
}
if (this->tubeSimulator != nullptr) {
delete this->tubeSimulator;
this->tubeSimulator = nullptr;
}
if (this->analogX != nullptr) {
delete this->analogX;
this->analogX = nullptr;
}
if (this->speakerCorrection != nullptr) {
delete this->speakerCorrection;
this->speakerCorrection = nullptr;
}
delete this->adaptiveBuffer;
this->adaptiveBuffer = nullptr;
delete this->waveBuffer;
this->waveBuffer = nullptr;
delete this->convolver;
this->convolver = nullptr;
delete this->vhe;
this->vhe = nullptr;
delete this->viperDdc;
this->viperDdc = nullptr;
delete this->spectrumExtend;
this->spectrumExtend = nullptr;
delete this->iirFilter;
this->iirFilter = nullptr;
delete this->colorfulMusic;
this->colorfulMusic = nullptr;
delete this->reverberation;
this->reverberation = nullptr;
delete this->playbackGain;
this->playbackGain = nullptr;
delete this->fetCompressor;
this->fetCompressor = nullptr;
delete this->dynamicSystem;
this->dynamicSystem = nullptr;
delete this->viperBass;
this->viperBass = nullptr;
delete this->viperClarity;
this->viperClarity = nullptr;
delete this->diffSurround;
this->diffSurround = nullptr;
delete this->cure;
this->cure = nullptr;
delete this->tubeSimulator;
this->tubeSimulator = nullptr;
delete this->analogX;
this->analogX = nullptr;
delete this->speakerCorrection;
this->speakerCorrection = nullptr;
for (auto &softwareLimiter: softwareLimiters) {
if (softwareLimiter != nullptr) {
delete softwareLimiter;
softwareLimiter = nullptr;
}
delete softwareLimiter;
softwareLimiter = nullptr;
}
}

View File

@ -56,7 +56,7 @@ int PConvSingle_F32::LoadKernel(float *buf, int param_2, int segmentSize) {
if (param_2 > 0 && segmentSize > 0 && segmentSize % 2 == 0) {
this->enabled = false;
ReleaseResources();
this->data = (PConvData *) malloc(0x140); // TODO: Sizeof
this->data = new PConvData; //(PConvData *) malloc(0x140); // TODO: Sizeof
memset(this->data, 0, 0x140); // Ditto
this->segmentSize = segmentSize;
int n = ProcessKernel(buf, param_2, 1);
@ -76,7 +76,7 @@ int PConvSingle_F32::LoadKernel(float *buf, float *param_2, int segmentSize, int
if (param_5 > 0 && segmentSize > 0 && segmentSize % 2 == 0) {
this->enabled = false;
ReleaseResources();
this->data = (PConvData *) malloc(0x140); // TODO: Sizeof
this->data = new PConvData; //(PConvData *) malloc(0x140); // TODO: Sizeof
memset(this->data, 0, 0x140); // Ditto
this->segmentSize = segmentSize;
int n = ProcessKernel(1, param_2, param_4, param_5);

View File

@ -13,10 +13,8 @@ TimeConstDelay::TimeConstDelay() {
}
TimeConstDelay::~TimeConstDelay() {
if (this->samples != nullptr) {
free(this->samples);
this->samples = nullptr;
}
delete this->samples;
this->samples = nullptr;
}
float TimeConstDelay::ProcessSample(float sample) {
@ -31,10 +29,8 @@ float TimeConstDelay::ProcessSample(float sample) {
void TimeConstDelay::SetParameters(uint32_t samplerate, float delay) {
this->sampleCount = (int) ((float) samplerate * delay * 0.5f);
if (this->samples != nullptr) {
free(this->samples);
}
this->samples = new float[this->sampleCount * sizeof(float)];
delete this->samples;
this->samples = new float[this->sampleCount];
this->offset = 0;
memset(this->samples, 0, this->sampleCount * sizeof(float));
}

View File

@ -10,11 +10,12 @@ WaveBuffer_I32::WaveBuffer_I32(int channels, uint32_t size) {
this->channels = channels;
this->size = size * channels;
this->index = 0;
this->buffer = (float *) malloc(this->size * sizeof(float));
this->buffer = new float[this->size];
}
WaveBuffer_I32::~WaveBuffer_I32() {
free(this->buffer);
delete this->buffer;
this->buffer = nullptr;
}
void WaveBuffer_I32::Reset() {
@ -82,12 +83,9 @@ int WaveBuffer_I32::PushSamples(float *source, uint32_t size) {
if (size > 0) {
if (this->size < this->channels * size + this->index) {
float *buf = (float *) malloc((this->channels * size + this->index) * sizeof(float));
if (buf == nullptr) {
return 0;
}
auto *buf = new float[this->channels * size + this->index];
memcpy(buf, this->buffer, this->index * sizeof(float));
free(this->buffer);
delete this->buffer;
this->buffer = buf;
this->size = this->channels * size + this->index;
}
@ -105,12 +103,9 @@ int WaveBuffer_I32::PushZeros(uint32_t size) {
if (size > 0) {
if (this->size < this->channels * size + this->index) {
float *buf = (float *) malloc((this->channels * size + this->index) * sizeof(float));
if (buf == nullptr) {
return 0;
}
auto *buf = new float[this->channels * size + this->index];
memcpy(buf, this->buffer, this->index * sizeof(float));
free(this->buffer);
delete this->buffer;
this->buffer = buf;
this->size = this->channels * size + this->index;
}
@ -128,12 +123,9 @@ float *WaveBuffer_I32::PushZerosGetBuffer(uint32_t size) {
if (size > 0) {
if (this->size < this->channels * size + this->index) {
float *buf = (float *) malloc((this->channels * size + this->index) * sizeof(float));
if (buf == nullptr) {
return nullptr;
}
auto *buf = new float[this->channels * size + this->index];
memcpy(buf, this->buffer, this->index * sizeof(float));
free(this->buffer);
delete this->buffer;
this->buffer = buf;
this->size = this->channels * size + this->index;
}