mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-29 14:48:39 +02:00
Remove naked malloc (or similar) and free in: other effects
This commit is contained in:
parent
0c7e467a08
commit
cab99f7234
@ -33,38 +33,29 @@ public:
|
||||
ResampleBuf()
|
||||
{
|
||||
processed = 0;
|
||||
buf = NULL;
|
||||
leftBuffer = NULL;
|
||||
rightBuffer = NULL;
|
||||
|
||||
SBSMSBuf = NULL;
|
||||
outputLeftTrack = NULL;
|
||||
outputRightTrack = NULL;
|
||||
}
|
||||
|
||||
~ResampleBuf()
|
||||
{
|
||||
if(buf) free(buf);
|
||||
if(leftBuffer) free(leftBuffer);
|
||||
if(rightBuffer) free(rightBuffer);
|
||||
if(SBSMSBuf) free(SBSMSBuf);
|
||||
}
|
||||
|
||||
bool bPitch;
|
||||
audio *buf;
|
||||
ArrayOf<audio> buf;
|
||||
double ratio;
|
||||
sampleCount processed;
|
||||
size_t blockSize;
|
||||
long SBSMSBlockSize;
|
||||
sampleCount offset;
|
||||
sampleCount end;
|
||||
float *leftBuffer;
|
||||
float *rightBuffer;
|
||||
ArrayOf<float> leftBuffer;
|
||||
ArrayOf<float> rightBuffer;
|
||||
WaveTrack *leftTrack;
|
||||
WaveTrack *rightTrack;
|
||||
std::unique_ptr<SBSMS> sbsms;
|
||||
std::unique_ptr<SBSMSInterface> iface;
|
||||
audio *SBSMSBuf;
|
||||
ArrayOf<audio> SBSMSBuf;
|
||||
|
||||
// Not required by callbacks, but makes for easier cleanup
|
||||
std::unique_ptr<Resampler> resampler;
|
||||
@ -104,8 +95,8 @@ long resampleCB(void *cb_data, SBSMSFrame *data)
|
||||
);
|
||||
|
||||
// Get the samples from the tracks and put them in the buffers.
|
||||
r->leftTrack->Get((samplePtr)(r->leftBuffer), floatSample, r->offset, blockSize);
|
||||
r->rightTrack->Get((samplePtr)(r->rightBuffer), floatSample, r->offset, blockSize);
|
||||
r->leftTrack->Get((samplePtr)(r->leftBuffer.get()), floatSample, r->offset, blockSize);
|
||||
r->rightTrack->Get((samplePtr)(r->rightBuffer.get()), floatSample, r->offset, blockSize);
|
||||
|
||||
// convert to sbsms audio format
|
||||
for(decltype(blockSize) i=0; i<blockSize; i++) {
|
||||
@ -113,7 +104,7 @@ long resampleCB(void *cb_data, SBSMSFrame *data)
|
||||
r->buf[i][1] = r->rightBuffer[i];
|
||||
}
|
||||
|
||||
data->buf = r->buf;
|
||||
data->buf = r->buf.get();
|
||||
data->size = blockSize;
|
||||
if(r->bPitch) {
|
||||
float t0 = r->processed.as_float() / r->iface->getSamplesToInput();
|
||||
@ -132,8 +123,8 @@ long resampleCB(void *cb_data, SBSMSFrame *data)
|
||||
long postResampleCB(void *cb_data, SBSMSFrame *data)
|
||||
{
|
||||
ResampleBuf *r = (ResampleBuf*) cb_data;
|
||||
auto count = r->sbsms->read(r->iface.get(), r->SBSMSBuf, r->SBSMSBlockSize);
|
||||
data->buf = r->SBSMSBuf;
|
||||
auto count = r->sbsms->read(r->iface.get(), r->SBSMSBuf.get(), r->SBSMSBlockSize);
|
||||
data->buf = r->SBSMSBuf.get();
|
||||
data->size = count;
|
||||
data->ratio0 = 1.0 / r->ratio;
|
||||
data->ratio1 = 1.0 / r->ratio;
|
||||
@ -285,11 +276,11 @@ bool EffectSBSMS::Process()
|
||||
ResampleBuf rb;
|
||||
auto maxBlockSize = leftTrack->GetMaxBlockSize();
|
||||
rb.blockSize = maxBlockSize;
|
||||
rb.buf = (audio*)calloc(rb.blockSize,sizeof(audio));
|
||||
rb.buf.reinit(rb.blockSize, true);
|
||||
rb.leftTrack = leftTrack;
|
||||
rb.rightTrack = rightTrack?rightTrack:leftTrack;
|
||||
rb.leftBuffer = (float*)calloc(maxBlockSize,sizeof(float));
|
||||
rb.rightBuffer = (float*)calloc(maxBlockSize,sizeof(float));
|
||||
rb.leftBuffer.reinit(maxBlockSize, true);
|
||||
rb.rightBuffer.reinit(maxBlockSize, true);
|
||||
|
||||
// Samples in selection
|
||||
auto samplesIn = end - start;
|
||||
@ -325,7 +316,7 @@ bool EffectSBSMS::Process()
|
||||
rb.resampler = std::make_unique<Resampler>(resampleCB, &rb, srProcess==srTrack?SlideIdentity:SlideConstant);
|
||||
rb.sbsms = std::make_unique<SBSMS>(rightTrack ? 2 : 1, rb.quality.get(), true);
|
||||
rb.SBSMSBlockSize = rb.sbsms->getInputFrameSize();
|
||||
rb.SBSMSBuf = (audio*)calloc(rb.SBSMSBlockSize,sizeof(audio));
|
||||
rb.SBSMSBuf.reinit(static_cast<size_t>(rb.SBSMSBlockSize), true);
|
||||
|
||||
// Note: width of getMaxPresamples() is only long. Widen it
|
||||
decltype(start) processPresamples = rb.quality->getMaxPresamples();
|
||||
|
@ -277,7 +277,8 @@ void AUControl::CreateCocoa()
|
||||
return;
|
||||
}
|
||||
|
||||
AudioUnitCocoaViewInfo *viewInfo = (AudioUnitCocoaViewInfo *) malloc(dataSize);
|
||||
ArrayOf<char> buffer{ dataSize };
|
||||
auto viewInfo = (AudioUnitCocoaViewInfo *) buffer.get();
|
||||
if (viewInfo == NULL)
|
||||
{
|
||||
return;
|
||||
@ -331,8 +332,6 @@ void AUControl::CreateCocoa()
|
||||
}
|
||||
}
|
||||
|
||||
free(viewInfo);
|
||||
|
||||
if (!mView)
|
||||
{
|
||||
return;
|
||||
@ -474,7 +473,8 @@ void AUControl::CreateCarbon()
|
||||
return;
|
||||
}
|
||||
|
||||
AudioComponentDescription *compList = (AudioComponentDescription *) malloc(dataSize);
|
||||
ArrayOf<char> buffer{ dataSize };
|
||||
auto compList = (AudioComponentDescription *) buffer.get();
|
||||
if (compList == NULL)
|
||||
{
|
||||
return;
|
||||
@ -488,11 +488,7 @@ void AUControl::CreateCarbon()
|
||||
compList,
|
||||
&dataSize);
|
||||
if (result != noErr)
|
||||
{
|
||||
free(compList);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the component
|
||||
AudioComponent comp = AudioComponentFindNext(NULL, &compList[0]);
|
||||
@ -500,9 +496,6 @@ void AUControl::CreateCarbon()
|
||||
// Try to create an instance
|
||||
result = AudioComponentInstanceNew(comp, &mInstance);
|
||||
|
||||
// Done with the list
|
||||
free(compList);
|
||||
|
||||
if (result != noErr)
|
||||
{
|
||||
return;
|
||||
|
@ -2187,7 +2187,8 @@ void AudioUnitEffect::GetChannelCounts()
|
||||
return;
|
||||
}
|
||||
|
||||
AUChannelInfo *info = (AUChannelInfo *) malloc(dataSize);
|
||||
ArrayOf<char> buffer{ dataSize };
|
||||
auto info = (AUChannelInfo *) buffer.get();
|
||||
|
||||
// Retrieve the channel info
|
||||
result = AudioUnitGetProperty(mUnit,
|
||||
@ -2202,7 +2203,6 @@ void AudioUnitEffect::GetChannelCounts()
|
||||
mAudioIns = 2;
|
||||
mAudioOuts = 2;
|
||||
|
||||
free(info);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -316,11 +316,6 @@ LV2Effect::LV2Effect(const LilvPlugin *plug)
|
||||
|
||||
mDialog = NULL;
|
||||
|
||||
mURIMap = NULL;
|
||||
mNumURIMap = 0;
|
||||
mOptions = NULL;
|
||||
mNumOptions = 0;
|
||||
|
||||
mIdleFeature = NULL;
|
||||
mOptionsInterface = NULL;
|
||||
|
||||
@ -329,19 +324,6 @@ LV2Effect::LV2Effect(const LilvPlugin *plug)
|
||||
|
||||
LV2Effect::~LV2Effect()
|
||||
{
|
||||
if (mURIMap)
|
||||
{
|
||||
for (int i = 0; i < mNumURIMap; i++)
|
||||
{
|
||||
free(mURIMap[i]);
|
||||
}
|
||||
free(mURIMap);
|
||||
}
|
||||
|
||||
if (mOptions)
|
||||
{
|
||||
free(mOptions);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@ -675,7 +657,7 @@ bool LV2Effect::SetHost(EffectHostInterface *host)
|
||||
AddFeature(LV2_UI_PREFIX "makeResident", NULL);
|
||||
AddFeature(LV2_UI__noUserResize, NULL);
|
||||
AddFeature(LV2_BUF_SIZE__boundedBlockLength, NULL);
|
||||
AddFeature(LV2_OPTIONS__options, mOptions);
|
||||
AddFeature(LV2_OPTIONS__options, mOptions.data());
|
||||
AddFeature(LV2_URI_MAP_URI, &mUriMapFeature);
|
||||
AddFeature(LV2_URID__map, &mURIDMapFeature);
|
||||
AddFeature(LV2_URID__unmap, &mURIDUnmapFeature);
|
||||
@ -1302,10 +1284,9 @@ bool LV2Effect::SaveParameters(const wxString & group)
|
||||
|
||||
size_t LV2Effect::AddOption(const char *key, uint32_t size, const char *type, void *value)
|
||||
{
|
||||
int ndx = mNumOptions;
|
||||
int ndx = mOptions.size();
|
||||
|
||||
mNumOptions += 1;
|
||||
mOptions = (LV2_Options_Option *) realloc(mOptions, mNumOptions * sizeof(LV2_Options_Option));
|
||||
mOptions.resize(1 + mOptions.size());
|
||||
memset(&mOptions[ndx], 0, sizeof(mOptions[ndx]));
|
||||
|
||||
if (key != NULL)
|
||||
@ -1323,26 +1304,24 @@ size_t LV2Effect::AddOption(const char *key, uint32_t size, const char *type, vo
|
||||
|
||||
LV2_Feature *LV2Effect::AddFeature(const char *uri, void *data)
|
||||
{
|
||||
mFeatures.resize(mFeatures.size() + 1);
|
||||
|
||||
auto &pFeature = mFeatures.back();
|
||||
size_t ndx = mFeatures.size();
|
||||
mFeatures.resize(1 + mFeatures.size());
|
||||
|
||||
if (uri != NULL)
|
||||
{
|
||||
pFeature = make_movable<LV2_Feature>();
|
||||
pFeature->URI = uri;
|
||||
pFeature->data = data;
|
||||
mFeatures[ndx].reset( safenew LV2_Feature );
|
||||
mFeatures[ndx]->URI = uri;
|
||||
mFeatures[ndx]->data = data;
|
||||
}
|
||||
|
||||
mFeaturePtrs.push_back(pFeature.get());
|
||||
return pFeature.get();
|
||||
return mFeatures[ndx].get();
|
||||
}
|
||||
|
||||
LilvInstance *LV2Effect::InitInstance(float sampleRate)
|
||||
{
|
||||
LilvInstance *handle = lilv_plugin_instantiate(mPlug,
|
||||
sampleRate,
|
||||
mFeaturePtrs.data());
|
||||
LilvInstance *handle = lilv_plugin_instantiate(
|
||||
mPlug, sampleRate,
|
||||
reinterpret_cast<const LV2_Feature *const *>(mFeatures.data()));
|
||||
if (!handle)
|
||||
{
|
||||
return NULL;
|
||||
@ -1478,7 +1457,7 @@ bool LV2Effect::BuildFancy()
|
||||
lilv_node_as_uri(uiType),
|
||||
lilv_uri_to_path(lilv_node_as_uri(lilv_ui_get_bundle_uri(ui))),
|
||||
lilv_uri_to_path(lilv_node_as_uri(lilv_ui_get_binary_uri(ui))),
|
||||
mFeaturePtrs.data());
|
||||
reinterpret_cast<const LV2_Feature *const *>(mFeatures.data()));
|
||||
|
||||
lilv_uis_free(uis);
|
||||
|
||||
@ -2033,19 +2012,19 @@ LV2_URID LV2Effect::urid_map(LV2_URID_Map_Handle handle, const char *uri)
|
||||
|
||||
LV2_URID LV2Effect::URID_Map(const char *uri)
|
||||
{
|
||||
for (int i = 0; i < mNumURIMap; i++)
|
||||
size_t ndx = mURIMap.size();
|
||||
for (int i = 0; i < ndx; i++)
|
||||
{
|
||||
if (strcmp(mURIMap[i], uri) == 0)
|
||||
if (strcmp(mURIMap[i].get(), uri) == 0)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
mNumURIMap += 1;
|
||||
mURIMap = (char **) realloc(mURIMap, mNumURIMap * sizeof(char*));
|
||||
mURIMap[mNumURIMap - 1] = strdup(uri);
|
||||
mURIMap.resize(1 + mURIMap.size());
|
||||
mURIMap[ndx].reset( strdup(uri) );
|
||||
|
||||
return mNumURIMap;
|
||||
return ndx + 1;
|
||||
}
|
||||
|
||||
// static callback
|
||||
@ -2056,9 +2035,9 @@ const char *LV2Effect::urid_unmap(LV2_URID_Unmap_Handle handle, LV2_URID urid)
|
||||
|
||||
const char *LV2Effect::URID_Unmap(LV2_URID urid)
|
||||
{
|
||||
if (urid > 0 && urid <= (LV2_URID) mNumURIMap)
|
||||
if (urid > 0 && urid <= (LV2_URID) mURIMap.size())
|
||||
{
|
||||
return mURIMap[urid - 1];
|
||||
return mURIMap[urid - 1].get();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "../../MemoryX.h"
|
||||
#include <vector>
|
||||
|
||||
#include <wx/checkbox.h>
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/dynarray.h>
|
||||
@ -289,8 +288,7 @@ private:
|
||||
|
||||
bool mUseGUI;
|
||||
|
||||
char **mURIMap;
|
||||
int mNumURIMap;
|
||||
std::vector< movable_ptr_with_deleter<char, freer> > mURIMap;
|
||||
|
||||
LV2_URI_Map_Feature mUriMapFeature;
|
||||
LV2_URID_Map mURIDMapFeature;
|
||||
@ -302,11 +300,9 @@ private:
|
||||
size_t mSampleRateOption;
|
||||
|
||||
LV2_Options_Interface *mOptionsInterface;
|
||||
LV2_Options_Option *mOptions;
|
||||
int mNumOptions;
|
||||
std::vector<LV2_Options_Option> mOptions;
|
||||
|
||||
std::vector<movable_ptr<LV2_Feature>> mFeatures;
|
||||
std::vector<LV2_Feature*> mFeaturePtrs;
|
||||
|
||||
LV2_Feature *mInstanceAccessFeature;
|
||||
LV2_Feature *mParentFeature;
|
||||
|
Loading…
x
Reference in New Issue
Block a user