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() { Effect::~Effect() {
if (this->buffer != nullptr) { delete this->buffer;
delete this->buffer; this->buffer = nullptr;
this->buffer = nullptr;
}
} }
int32_t Effect::process(audio_buffer_s *in, audio_buffer_s *out) { 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() { ProcessUnit_FX::~ProcessUnit_FX() {
if (this->adaptiveBuffer != nullptr) { delete this->adaptiveBuffer;
delete this->adaptiveBuffer; this->adaptiveBuffer = nullptr;
this->adaptiveBuffer = nullptr;
} delete this->waveBuffer;
if (this->waveBuffer != nullptr) { this->waveBuffer = nullptr;
delete this->waveBuffer;
this->waveBuffer = nullptr; delete this->convolver;
} this->convolver = nullptr;
if (this->convolver != nullptr) {
delete this->convolver; delete this->vhe;
this->convolver = nullptr; this->vhe = nullptr;
}
if (this->vhe != nullptr) { delete this->viperDdc;
delete this->vhe; this->viperDdc = nullptr;
this->vhe = nullptr;
} delete this->spectrumExtend;
if (this->viperDdc != nullptr) { this->spectrumExtend = nullptr;
delete this->viperDdc;
this->viperDdc = nullptr; delete this->iirFilter;
} this->iirFilter = nullptr;
if (this->spectrumExtend != nullptr) {
delete this->spectrumExtend; delete this->colorfulMusic;
this->spectrumExtend = nullptr; this->colorfulMusic = nullptr;
}
if (this->iirFilter != nullptr) { delete this->reverberation;
delete this->iirFilter; this->reverberation = nullptr;
this->iirFilter = nullptr;
} delete this->playbackGain;
if (this->colorfulMusic != nullptr) { this->playbackGain = nullptr;
delete this->colorfulMusic;
this->colorfulMusic = nullptr; delete this->fetCompressor;
} this->fetCompressor = nullptr;
if (this->reverberation != nullptr) {
delete this->reverberation; delete this->dynamicSystem;
this->reverberation = nullptr; this->dynamicSystem = nullptr;
}
if (this->playbackGain != nullptr) { delete this->viperBass;
delete this->playbackGain; this->viperBass = nullptr;
this->playbackGain = nullptr;
} delete this->viperClarity;
if (this->fetCompressor != nullptr) { this->viperClarity = nullptr;
delete this->fetCompressor;
this->fetCompressor = nullptr; delete this->diffSurround;
} this->diffSurround = nullptr;
if (this->dynamicSystem != nullptr) {
delete this->dynamicSystem; delete this->cure;
this->dynamicSystem = nullptr; this->cure = nullptr;
}
if (this->viperBass != nullptr) { delete this->tubeSimulator;
delete this->viperBass; this->tubeSimulator = nullptr;
this->viperBass = nullptr;
} delete this->analogX;
if (this->viperClarity != nullptr) { this->analogX = nullptr;
delete this->viperClarity;
this->viperClarity = nullptr; delete this->speakerCorrection;
} this->speakerCorrection = 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;
}
for (auto &softwareLimiter: softwareLimiters) { for (auto &softwareLimiter: softwareLimiters) {
if (softwareLimiter != nullptr) { delete softwareLimiter;
delete softwareLimiter; softwareLimiter = nullptr;
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) { if (param_2 > 0 && segmentSize > 0 && segmentSize % 2 == 0) {
this->enabled = false; this->enabled = false;
ReleaseResources(); ReleaseResources();
this->data = (PConvData *) malloc(0x140); // TODO: Sizeof this->data = new PConvData; //(PConvData *) malloc(0x140); // TODO: Sizeof
memset(this->data, 0, 0x140); // Ditto memset(this->data, 0, 0x140); // Ditto
this->segmentSize = segmentSize; this->segmentSize = segmentSize;
int n = ProcessKernel(buf, param_2, 1); 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) { if (param_5 > 0 && segmentSize > 0 && segmentSize % 2 == 0) {
this->enabled = false; this->enabled = false;
ReleaseResources(); ReleaseResources();
this->data = (PConvData *) malloc(0x140); // TODO: Sizeof this->data = new PConvData; //(PConvData *) malloc(0x140); // TODO: Sizeof
memset(this->data, 0, 0x140); // Ditto memset(this->data, 0, 0x140); // Ditto
this->segmentSize = segmentSize; this->segmentSize = segmentSize;
int n = ProcessKernel(1, param_2, param_4, param_5); int n = ProcessKernel(1, param_2, param_4, param_5);

View File

@ -13,10 +13,8 @@ TimeConstDelay::TimeConstDelay() {
} }
TimeConstDelay::~TimeConstDelay() { TimeConstDelay::~TimeConstDelay() {
if (this->samples != nullptr) { delete this->samples;
free(this->samples); this->samples = nullptr;
this->samples = nullptr;
}
} }
float TimeConstDelay::ProcessSample(float sample) { float TimeConstDelay::ProcessSample(float sample) {
@ -31,10 +29,8 @@ float TimeConstDelay::ProcessSample(float sample) {
void TimeConstDelay::SetParameters(uint32_t samplerate, float delay) { void TimeConstDelay::SetParameters(uint32_t samplerate, float delay) {
this->sampleCount = (int) ((float) samplerate * delay * 0.5f); this->sampleCount = (int) ((float) samplerate * delay * 0.5f);
if (this->samples != nullptr) { delete this->samples;
free(this->samples); this->samples = new float[this->sampleCount];
}
this->samples = new float[this->sampleCount * sizeof(float)];
this->offset = 0; this->offset = 0;
memset(this->samples, 0, this->sampleCount * sizeof(float)); 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->channels = channels;
this->size = size * channels; this->size = size * channels;
this->index = 0; this->index = 0;
this->buffer = (float *) malloc(this->size * sizeof(float)); this->buffer = new float[this->size];
} }
WaveBuffer_I32::~WaveBuffer_I32() { WaveBuffer_I32::~WaveBuffer_I32() {
free(this->buffer); delete this->buffer;
this->buffer = nullptr;
} }
void WaveBuffer_I32::Reset() { void WaveBuffer_I32::Reset() {
@ -82,12 +83,9 @@ int WaveBuffer_I32::PushSamples(float *source, uint32_t size) {
if (size > 0) { if (size > 0) {
if (this->size < this->channels * size + this->index) { if (this->size < this->channels * size + this->index) {
float *buf = (float *) malloc((this->channels * size + this->index) * sizeof(float)); auto *buf = new float[this->channels * size + this->index];
if (buf == nullptr) {
return 0;
}
memcpy(buf, this->buffer, this->index * sizeof(float)); memcpy(buf, this->buffer, this->index * sizeof(float));
free(this->buffer); delete this->buffer;
this->buffer = buf; this->buffer = buf;
this->size = this->channels * size + this->index; this->size = this->channels * size + this->index;
} }
@ -105,12 +103,9 @@ int WaveBuffer_I32::PushZeros(uint32_t size) {
if (size > 0) { if (size > 0) {
if (this->size < this->channels * size + this->index) { if (this->size < this->channels * size + this->index) {
float *buf = (float *) malloc((this->channels * size + this->index) * sizeof(float)); auto *buf = new float[this->channels * size + this->index];
if (buf == nullptr) {
return 0;
}
memcpy(buf, this->buffer, this->index * sizeof(float)); memcpy(buf, this->buffer, this->index * sizeof(float));
free(this->buffer); delete this->buffer;
this->buffer = buf; this->buffer = buf;
this->size = this->channels * size + this->index; this->size = this->channels * size + this->index;
} }
@ -128,12 +123,9 @@ float *WaveBuffer_I32::PushZerosGetBuffer(uint32_t size) {
if (size > 0) { if (size > 0) {
if (this->size < this->channels * size + this->index) { if (this->size < this->channels * size + this->index) {
float *buf = (float *) malloc((this->channels * size + this->index) * sizeof(float)); auto *buf = new float[this->channels * size + this->index];
if (buf == nullptr) {
return nullptr;
}
memcpy(buf, this->buffer, this->index * sizeof(float)); memcpy(buf, this->buffer, this->index * sizeof(float));
free(this->buffer); delete this->buffer;
this->buffer = buf; this->buffer = buf;
this->size = this->channels * size + this->index; this->size = this->channels * size + this->index;
} }