Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory issues #55

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions NAM/get_dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ std::unique_ptr<DSP> get_dsp(dspData& conf)
{
verify_config_version(conf.version);

auto &architecture = conf.architecture;
nlohmann::json &config = conf.config;
std::vector<float> &params = conf.params;
auto& architecture = conf.architecture;
nlohmann::json& config = conf.config;
std::vector<float>& params = conf.params;
bool haveLoudness = false;
double loudness = TARGET_DSP_LOUDNESS;

Expand Down
4 changes: 2 additions & 2 deletions dsp/ImpulseResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void dsp::ImpulseResponse::_SetWeights(const double sampleRate)
if (this->mRawAudioSampleRate == sampleRate)
{
this->mResampled.resize(this->mRawAudio.size());
memcpy(this->mResampled.data(), this->mRawAudio.data(), this->mResampled.size());
memcpy(this->mResampled.data(), this->mRawAudio.data(), sizeof(float) * this->mResampled.size());
}
else
{
Expand All @@ -58,7 +58,7 @@ void dsp::ImpulseResponse::_SetWeights(const double sampleRate)
padded.resize(this->mRawAudio.size() + 2);
padded[0] = 0.0f;
padded[padded.size() - 1] = 0.0f;
memcpy(padded.data() + 1, this->mRawAudio.data(), this->mRawAudio.size());
memcpy(padded.data() + 1, this->mRawAudio.data(), sizeof(float) * this->mRawAudio.size());
dsp::ResampleCubic<float>(padded, this->mRawAudioSampleRate, sampleRate, 0.0, this->mResampled);
}
// Simple implementation w/ no resample...
Expand Down
20 changes: 6 additions & 14 deletions dsp/wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,23 @@ std::string dsp::wav::GetMsgForLoadReturnCode(LoadReturnCode retCode)
{
case (LoadReturnCode::ERROR_OPENING):
message << "Failed to open file (is it being used by another "
"program?)";
"program?)";
break;
case (LoadReturnCode::ERROR_NOT_RIFF): message << "File is not a WAV file."; break;
case (LoadReturnCode::ERROR_NOT_WAVE): message << "File is not a WAV file."; break;
case (LoadReturnCode::ERROR_MISSING_FMT):
message << "File is missing expected format chunk.";
break;
case (LoadReturnCode::ERROR_MISSING_FMT): message << "File is missing expected format chunk."; break;
case (LoadReturnCode::ERROR_INVALID_FILE): message << "WAV file contents are invalid."; break;
case (LoadReturnCode::ERROR_UNSUPPORTED_FORMAT_ALAW):
message << "Unsupported file format \"A-law\"";
break;
case (LoadReturnCode::ERROR_UNSUPPORTED_FORMAT_MULAW):
message << "Unsupported file format \"mu-law\"";
break;
case (LoadReturnCode::ERROR_UNSUPPORTED_FORMAT_ALAW): message << "Unsupported file format \"A-law\""; break;
case (LoadReturnCode::ERROR_UNSUPPORTED_FORMAT_MULAW): message << "Unsupported file format \"mu-law\""; break;
case (LoadReturnCode::ERROR_UNSUPPORTED_FORMAT_EXTENSIBLE):
message << "Unsupported file format \"extensible\"";
break;
case (LoadReturnCode::ERROR_NOT_MONO): message << "File is not mono."; break;
case (LoadReturnCode::ERROR_UNSUPPORTED_BITS_PER_SAMPLE):
message << "Unsupported bits per sample";
break;
case (LoadReturnCode::ERROR_UNSUPPORTED_BITS_PER_SAMPLE): message << "Unsupported bits per sample"; break;
case (dsp::wav::LoadReturnCode::ERROR_OTHER): message << "???"; break;
default: message << "???"; break;
}

return message.str();
}

Expand Down
52 changes: 26 additions & 26 deletions tools/benchmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include "NAM/dsp.h"

using std::chrono::high_resolution_clock;
using std::chrono::duration_cast;
using std::chrono::duration;
using std::chrono::duration_cast;
using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;

#define AUDIO_BUFFER_SIZE 64
Expand All @@ -31,41 +31,41 @@ int main(int argc, char* argv[])

std::unique_ptr<DSP> model;

model.reset();
model = std::move(get_dsp(modelPath));
model.reset();
model = std::move(get_dsp(modelPath));

if (model == nullptr)
{
std::cerr << "Failed to load model\n";
if (model == nullptr)
{
std::cerr << "Failed to load model\n";

exit(1);
}
exit(1);
}

auto t1 = high_resolution_clock::now();
auto t1 = high_resolution_clock::now();

size_t bufferSize = 64;
size_t numBuffers = (48000 / 64) * 2;
size_t bufferSize = 64;
size_t numBuffers = (48000 / 64) * 2;

std::cout << "Running benchmark\n";
std::cout << "Running benchmark\n";

for (size_t i = 0; i < numBuffers; i++)
{
model->process(buffers, buffers, 1, AUDIO_BUFFER_SIZE, 1.0, 1.0, mNAMParams);
model->finalize_(AUDIO_BUFFER_SIZE);
}
for (size_t i = 0; i < numBuffers; i++)
{
model->process(buffers, buffers, 1, AUDIO_BUFFER_SIZE, 1.0, 1.0, mNAMParams);
model->finalize_(AUDIO_BUFFER_SIZE);
}

std::cout << "Finished\n";
std::cout << "Finished\n";

auto t2 = high_resolution_clock::now();
auto t2 = high_resolution_clock::now();

/* Getting number of milliseconds as an integer. */
auto ms_int = duration_cast<milliseconds>(t2 - t1);
/* Getting number of milliseconds as an integer. */
auto ms_int = duration_cast<milliseconds>(t2 - t1);

/* Getting number of milliseconds as a double. */
duration<double, std::milli> ms_double = t2 - t1;
/* Getting number of milliseconds as a double. */
duration<double, std::milli> ms_double = t2 - t1;

std::cout << ms_int.count() << "ms\n";
std::cout << ms_double.count() << "ms\n";
std::cout << ms_int.count() << "ms\n";
std::cout << ms_double.count() << "ms\n";
}
else
{
Expand Down