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()
|
ResampleBuf()
|
||||||
{
|
{
|
||||||
processed = 0;
|
processed = 0;
|
||||||
buf = NULL;
|
|
||||||
leftBuffer = NULL;
|
|
||||||
rightBuffer = NULL;
|
|
||||||
|
|
||||||
SBSMSBuf = NULL;
|
|
||||||
outputLeftTrack = NULL;
|
outputLeftTrack = NULL;
|
||||||
outputRightTrack = NULL;
|
outputRightTrack = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ResampleBuf()
|
~ResampleBuf()
|
||||||
{
|
{
|
||||||
if(buf) free(buf);
|
|
||||||
if(leftBuffer) free(leftBuffer);
|
|
||||||
if(rightBuffer) free(rightBuffer);
|
|
||||||
if(SBSMSBuf) free(SBSMSBuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bPitch;
|
bool bPitch;
|
||||||
audio *buf;
|
ArrayOf<audio> buf;
|
||||||
double ratio;
|
double ratio;
|
||||||
sampleCount processed;
|
sampleCount processed;
|
||||||
size_t blockSize;
|
size_t blockSize;
|
||||||
long SBSMSBlockSize;
|
long SBSMSBlockSize;
|
||||||
sampleCount offset;
|
sampleCount offset;
|
||||||
sampleCount end;
|
sampleCount end;
|
||||||
float *leftBuffer;
|
ArrayOf<float> leftBuffer;
|
||||||
float *rightBuffer;
|
ArrayOf<float> rightBuffer;
|
||||||
WaveTrack *leftTrack;
|
WaveTrack *leftTrack;
|
||||||
WaveTrack *rightTrack;
|
WaveTrack *rightTrack;
|
||||||
std::unique_ptr<SBSMS> sbsms;
|
std::unique_ptr<SBSMS> sbsms;
|
||||||
std::unique_ptr<SBSMSInterface> iface;
|
std::unique_ptr<SBSMSInterface> iface;
|
||||||
audio *SBSMSBuf;
|
ArrayOf<audio> SBSMSBuf;
|
||||||
|
|
||||||
// Not required by callbacks, but makes for easier cleanup
|
// Not required by callbacks, but makes for easier cleanup
|
||||||
std::unique_ptr<Resampler> resampler;
|
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.
|
// Get the samples from the tracks and put them in the buffers.
|
||||||
r->leftTrack->Get((samplePtr)(r->leftBuffer), floatSample, r->offset, blockSize);
|
r->leftTrack->Get((samplePtr)(r->leftBuffer.get()), floatSample, r->offset, blockSize);
|
||||||
r->rightTrack->Get((samplePtr)(r->rightBuffer), floatSample, r->offset, blockSize);
|
r->rightTrack->Get((samplePtr)(r->rightBuffer.get()), floatSample, r->offset, blockSize);
|
||||||
|
|
||||||
// convert to sbsms audio format
|
// convert to sbsms audio format
|
||||||
for(decltype(blockSize) i=0; i<blockSize; i++) {
|
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];
|
r->buf[i][1] = r->rightBuffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
data->buf = r->buf;
|
data->buf = r->buf.get();
|
||||||
data->size = blockSize;
|
data->size = blockSize;
|
||||||
if(r->bPitch) {
|
if(r->bPitch) {
|
||||||
float t0 = r->processed.as_float() / r->iface->getSamplesToInput();
|
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)
|
long postResampleCB(void *cb_data, SBSMSFrame *data)
|
||||||
{
|
{
|
||||||
ResampleBuf *r = (ResampleBuf*) cb_data;
|
ResampleBuf *r = (ResampleBuf*) cb_data;
|
||||||
auto count = r->sbsms->read(r->iface.get(), r->SBSMSBuf, r->SBSMSBlockSize);
|
auto count = r->sbsms->read(r->iface.get(), r->SBSMSBuf.get(), r->SBSMSBlockSize);
|
||||||
data->buf = r->SBSMSBuf;
|
data->buf = r->SBSMSBuf.get();
|
||||||
data->size = count;
|
data->size = count;
|
||||||
data->ratio0 = 1.0 / r->ratio;
|
data->ratio0 = 1.0 / r->ratio;
|
||||||
data->ratio1 = 1.0 / r->ratio;
|
data->ratio1 = 1.0 / r->ratio;
|
||||||
@ -285,11 +276,11 @@ bool EffectSBSMS::Process()
|
|||||||
ResampleBuf rb;
|
ResampleBuf rb;
|
||||||
auto maxBlockSize = leftTrack->GetMaxBlockSize();
|
auto maxBlockSize = leftTrack->GetMaxBlockSize();
|
||||||
rb.blockSize = maxBlockSize;
|
rb.blockSize = maxBlockSize;
|
||||||
rb.buf = (audio*)calloc(rb.blockSize,sizeof(audio));
|
rb.buf.reinit(rb.blockSize, true);
|
||||||
rb.leftTrack = leftTrack;
|
rb.leftTrack = leftTrack;
|
||||||
rb.rightTrack = rightTrack?rightTrack:leftTrack;
|
rb.rightTrack = rightTrack?rightTrack:leftTrack;
|
||||||
rb.leftBuffer = (float*)calloc(maxBlockSize,sizeof(float));
|
rb.leftBuffer.reinit(maxBlockSize, true);
|
||||||
rb.rightBuffer = (float*)calloc(maxBlockSize,sizeof(float));
|
rb.rightBuffer.reinit(maxBlockSize, true);
|
||||||
|
|
||||||
// Samples in selection
|
// Samples in selection
|
||||||
auto samplesIn = end - start;
|
auto samplesIn = end - start;
|
||||||
@ -325,7 +316,7 @@ bool EffectSBSMS::Process()
|
|||||||
rb.resampler = std::make_unique<Resampler>(resampleCB, &rb, srProcess==srTrack?SlideIdentity:SlideConstant);
|
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.sbsms = std::make_unique<SBSMS>(rightTrack ? 2 : 1, rb.quality.get(), true);
|
||||||
rb.SBSMSBlockSize = rb.sbsms->getInputFrameSize();
|
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
|
// Note: width of getMaxPresamples() is only long. Widen it
|
||||||
decltype(start) processPresamples = rb.quality->getMaxPresamples();
|
decltype(start) processPresamples = rb.quality->getMaxPresamples();
|
||||||
|
@ -277,7 +277,8 @@ void AUControl::CreateCocoa()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioUnitCocoaViewInfo *viewInfo = (AudioUnitCocoaViewInfo *) malloc(dataSize);
|
ArrayOf<char> buffer{ dataSize };
|
||||||
|
auto viewInfo = (AudioUnitCocoaViewInfo *) buffer.get();
|
||||||
if (viewInfo == NULL)
|
if (viewInfo == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -331,8 +332,6 @@ void AUControl::CreateCocoa()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(viewInfo);
|
|
||||||
|
|
||||||
if (!mView)
|
if (!mView)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -474,7 +473,8 @@ void AUControl::CreateCarbon()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioComponentDescription *compList = (AudioComponentDescription *) malloc(dataSize);
|
ArrayOf<char> buffer{ dataSize };
|
||||||
|
auto compList = (AudioComponentDescription *) buffer.get();
|
||||||
if (compList == NULL)
|
if (compList == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -488,11 +488,7 @@ void AUControl::CreateCarbon()
|
|||||||
compList,
|
compList,
|
||||||
&dataSize);
|
&dataSize);
|
||||||
if (result != noErr)
|
if (result != noErr)
|
||||||
{
|
|
||||||
free(compList);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Get the component
|
// Get the component
|
||||||
AudioComponent comp = AudioComponentFindNext(NULL, &compList[0]);
|
AudioComponent comp = AudioComponentFindNext(NULL, &compList[0]);
|
||||||
@ -500,9 +496,6 @@ void AUControl::CreateCarbon()
|
|||||||
// Try to create an instance
|
// Try to create an instance
|
||||||
result = AudioComponentInstanceNew(comp, &mInstance);
|
result = AudioComponentInstanceNew(comp, &mInstance);
|
||||||
|
|
||||||
// Done with the list
|
|
||||||
free(compList);
|
|
||||||
|
|
||||||
if (result != noErr)
|
if (result != noErr)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -2187,7 +2187,8 @@ void AudioUnitEffect::GetChannelCounts()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AUChannelInfo *info = (AUChannelInfo *) malloc(dataSize);
|
ArrayOf<char> buffer{ dataSize };
|
||||||
|
auto info = (AUChannelInfo *) buffer.get();
|
||||||
|
|
||||||
// Retrieve the channel info
|
// Retrieve the channel info
|
||||||
result = AudioUnitGetProperty(mUnit,
|
result = AudioUnitGetProperty(mUnit,
|
||||||
@ -2202,7 +2203,6 @@ void AudioUnitEffect::GetChannelCounts()
|
|||||||
mAudioIns = 2;
|
mAudioIns = 2;
|
||||||
mAudioOuts = 2;
|
mAudioOuts = 2;
|
||||||
|
|
||||||
free(info);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,11 +316,6 @@ LV2Effect::LV2Effect(const LilvPlugin *plug)
|
|||||||
|
|
||||||
mDialog = NULL;
|
mDialog = NULL;
|
||||||
|
|
||||||
mURIMap = NULL;
|
|
||||||
mNumURIMap = 0;
|
|
||||||
mOptions = NULL;
|
|
||||||
mNumOptions = 0;
|
|
||||||
|
|
||||||
mIdleFeature = NULL;
|
mIdleFeature = NULL;
|
||||||
mOptionsInterface = NULL;
|
mOptionsInterface = NULL;
|
||||||
|
|
||||||
@ -329,19 +324,6 @@ LV2Effect::LV2Effect(const LilvPlugin *plug)
|
|||||||
|
|
||||||
LV2Effect::~LV2Effect()
|
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_PREFIX "makeResident", NULL);
|
||||||
AddFeature(LV2_UI__noUserResize, NULL);
|
AddFeature(LV2_UI__noUserResize, NULL);
|
||||||
AddFeature(LV2_BUF_SIZE__boundedBlockLength, 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_URI_MAP_URI, &mUriMapFeature);
|
||||||
AddFeature(LV2_URID__map, &mURIDMapFeature);
|
AddFeature(LV2_URID__map, &mURIDMapFeature);
|
||||||
AddFeature(LV2_URID__unmap, &mURIDUnmapFeature);
|
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)
|
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.resize(1 + mOptions.size());
|
||||||
mOptions = (LV2_Options_Option *) realloc(mOptions, mNumOptions * sizeof(LV2_Options_Option));
|
|
||||||
memset(&mOptions[ndx], 0, sizeof(mOptions[ndx]));
|
memset(&mOptions[ndx], 0, sizeof(mOptions[ndx]));
|
||||||
|
|
||||||
if (key != NULL)
|
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)
|
LV2_Feature *LV2Effect::AddFeature(const char *uri, void *data)
|
||||||
{
|
{
|
||||||
mFeatures.resize(mFeatures.size() + 1);
|
size_t ndx = mFeatures.size();
|
||||||
|
mFeatures.resize(1 + mFeatures.size());
|
||||||
auto &pFeature = mFeatures.back();
|
|
||||||
|
|
||||||
if (uri != NULL)
|
if (uri != NULL)
|
||||||
{
|
{
|
||||||
pFeature = make_movable<LV2_Feature>();
|
mFeatures[ndx].reset( safenew LV2_Feature );
|
||||||
pFeature->URI = uri;
|
mFeatures[ndx]->URI = uri;
|
||||||
pFeature->data = data;
|
mFeatures[ndx]->data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
mFeaturePtrs.push_back(pFeature.get());
|
return mFeatures[ndx].get();
|
||||||
return pFeature.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LilvInstance *LV2Effect::InitInstance(float sampleRate)
|
LilvInstance *LV2Effect::InitInstance(float sampleRate)
|
||||||
{
|
{
|
||||||
LilvInstance *handle = lilv_plugin_instantiate(mPlug,
|
LilvInstance *handle = lilv_plugin_instantiate(
|
||||||
sampleRate,
|
mPlug, sampleRate,
|
||||||
mFeaturePtrs.data());
|
reinterpret_cast<const LV2_Feature *const *>(mFeatures.data()));
|
||||||
if (!handle)
|
if (!handle)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1478,7 +1457,7 @@ bool LV2Effect::BuildFancy()
|
|||||||
lilv_node_as_uri(uiType),
|
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_bundle_uri(ui))),
|
||||||
lilv_uri_to_path(lilv_node_as_uri(lilv_ui_get_binary_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);
|
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)
|
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;
|
return i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mNumURIMap += 1;
|
mURIMap.resize(1 + mURIMap.size());
|
||||||
mURIMap = (char **) realloc(mURIMap, mNumURIMap * sizeof(char*));
|
mURIMap[ndx].reset( strdup(uri) );
|
||||||
mURIMap[mNumURIMap - 1] = strdup(uri);
|
|
||||||
|
|
||||||
return mNumURIMap;
|
return ndx + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static callback
|
// 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)
|
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;
|
return NULL;
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include "../../MemoryX.h"
|
#include "../../MemoryX.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <wx/checkbox.h>
|
#include <wx/checkbox.h>
|
||||||
#include <wx/dialog.h>
|
#include <wx/dialog.h>
|
||||||
#include <wx/dynarray.h>
|
#include <wx/dynarray.h>
|
||||||
@ -289,8 +288,7 @@ private:
|
|||||||
|
|
||||||
bool mUseGUI;
|
bool mUseGUI;
|
||||||
|
|
||||||
char **mURIMap;
|
std::vector< movable_ptr_with_deleter<char, freer> > mURIMap;
|
||||||
int mNumURIMap;
|
|
||||||
|
|
||||||
LV2_URI_Map_Feature mUriMapFeature;
|
LV2_URI_Map_Feature mUriMapFeature;
|
||||||
LV2_URID_Map mURIDMapFeature;
|
LV2_URID_Map mURIDMapFeature;
|
||||||
@ -302,11 +300,9 @@ private:
|
|||||||
size_t mSampleRateOption;
|
size_t mSampleRateOption;
|
||||||
|
|
||||||
LV2_Options_Interface *mOptionsInterface;
|
LV2_Options_Interface *mOptionsInterface;
|
||||||
LV2_Options_Option *mOptions;
|
std::vector<LV2_Options_Option> mOptions;
|
||||||
int mNumOptions;
|
|
||||||
|
|
||||||
std::vector<movable_ptr<LV2_Feature>> mFeatures;
|
std::vector<movable_ptr<LV2_Feature>> mFeatures;
|
||||||
std::vector<LV2_Feature*> mFeaturePtrs;
|
|
||||||
|
|
||||||
LV2_Feature *mInstanceAccessFeature;
|
LV2_Feature *mInstanceAccessFeature;
|
||||||
LV2_Feature *mParentFeature;
|
LV2_Feature *mParentFeature;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user