22#include < iostream>
33#include < NeuralAudio/NeuralModel.h>
44
5+ using namespace NeuralAudio ;
6+
57static std::string LoadModes[] = { " Internal" , " RTNeural" , " NAMCore" };
68
7- NeuralAudio:: NeuralModel* LoadModel (std::filesystem::path modelPath, NeuralAudio:: EModelLoadMode loadMode)
9+ NeuralModel* LoadModel (std::filesystem::path modelPath, EModelLoadMode loadMode)
810{
9- NeuralAudio:: NeuralModel::SetWaveNetLoadMode (loadMode);
10- NeuralAudio:: NeuralModel::SetLSTMLoadMode (loadMode);
11+ NeuralModel::SetWaveNetLoadMode (loadMode);
12+ NeuralModel::SetLSTMLoadMode (loadMode);
1113
1214 try
1315 {
@@ -22,7 +24,9 @@ NeuralAudio::NeuralModel* LoadModel(std::filesystem::path modelPath, NeuralAudio
2224
2325 if (model->GetLoadMode () != loadMode)
2426 {
25- std::cout << " **Warning: Tried to load " << LoadModes[loadMode] << " but got " << LoadModes[model->GetLoadMode ()] << std::endl;
27+ delete model;
28+
29+ return nullptr ;
2630 }
2731
2832 if (model->GetLoadMode () != NeuralAudio::EModelLoadMode::NAMCore)
@@ -43,7 +47,7 @@ NeuralAudio::NeuralModel* LoadModel(std::filesystem::path modelPath, NeuralAudio
4347 return nullptr ;
4448}
4549
46- static std::tuple<double , double > BenchModel (NeuralAudio:: NeuralModel* model, int blockSize, int numBlocks)
50+ static std::tuple<double , double > BenchModel (NeuralModel* model, int blockSize, int numBlocks)
4751{
4852 std::vector<float > inData;
4953 inData.resize (blockSize);
@@ -73,7 +77,7 @@ static std::tuple<double, double> BenchModel(NeuralAudio::NeuralModel* model, in
7377 return std::tie (tot, maxBlock);
7478}
7579
76- static double ComputeError (NeuralAudio:: NeuralModel* model1, NeuralAudio:: NeuralModel* model2, int blockSize, int numBlocks)
80+ static double ComputeError (NeuralModel* model1, NeuralModel* model2, int blockSize, int numBlocks)
7781{
7882 std::vector<float > inData;
7983 inData.resize (blockSize);
@@ -121,32 +125,56 @@ void RunNAMTests(std::filesystem::path modelPath, int blockSize)
121125
122126 int numBlocks = dataSize / blockSize;
123127
124- NeuralAudio:: NeuralModel::SetDefaultMaxAudioBufferSize (blockSize);
128+ NeuralModel::SetDefaultMaxAudioBufferSize (blockSize);
125129
126- auto rtNeuralModel = LoadModel (modelPath, NeuralAudio:: EModelLoadMode::RTNeural);
127- auto namCoreModel = LoadModel (modelPath, NeuralAudio:: EModelLoadMode::NAMCore);
128- auto internalModel = LoadModel (modelPath, NeuralAudio:: EModelLoadMode::Internal);
130+ NeuralModel* rtNeuralModel = LoadModel (modelPath, EModelLoadMode::RTNeural);
131+ NeuralModel* namCoreModel = LoadModel (modelPath, EModelLoadMode::NAMCore);
132+ NeuralModel* internalModel = LoadModel (modelPath, EModelLoadMode::Internal);
129133
130- double rms = ComputeError (namCoreModel, internalModel, blockSize, numBlocks);
131- std::cout << " NAM vs Internal RMS err: " << rms << std::endl;
134+ double rms;
132135
133- rms = ComputeError (namCoreModel, rtNeuralModel, blockSize, numBlocks);
134- std::cout << " NAM vs RTNeural RMS err: " << rms << std::endl;
135- std::cout << std::endl;
136+ if (namCoreModel != nullptr )
137+ {
138+ }
136139
137- auto internal = BenchModel (internalModel, blockSize, numBlocks);
138- auto rt = BenchModel (rtNeuralModel, blockSize, numBlocks);
139- auto nam = BenchModel (namCoreModel, blockSize, numBlocks);
140+ std::tuple<double , double > internal;
141+ std::tuple<double , double > rtNeural;
142+ std::tuple<double , double > namCore;
143+
144+ internal = BenchModel (internalModel, blockSize, numBlocks);
140145
141- std::cout << " NAM Core: " << std::get<0 >(nam) << " (" << std::get<1 >(nam) << " )" << std::endl;
142- std::cout << " RTNeural: " << std::get<0 >(rt) << " (" << std::get<1 >(rt) << " )" << std::endl;
143146 std::cout << " Internal: " << std::get<0 >(internal) << " (" << std::get<1 >(internal) << " )" << std::endl;
144- std::cout << " RTNeural is: " << (std::get<0 >(nam) / std::get<0 >(rt)) << " x NAM" << std::endl;
145- std::cout << " Internal is: " << (std::get<0 >(nam) / std::get<0 >(internal)) << " x NAM" << std::endl;
146147
147- std::cout << std::endl;
148+ if (namCoreModel != nullptr )
149+ {
150+ std::cout << std::endl;
151+
152+ namCore = BenchModel (namCoreModel, blockSize, numBlocks);
153+
154+ rms = ComputeError (namCoreModel, internalModel, blockSize, numBlocks);
148155
149- std::cout << " ***here" << std::endl;
156+ std::cout << " NAM Core: " << std::get<0 >(namCore) << " (" << std::get<1 >(namCore) << " )" << std::endl;
157+ std::cout << " NAM vs Internal RMS err: " << rms << std::endl;
158+ std::cout << " Internal is: " << (std::get<0 >(namCore) / std::get<0 >(internal)) << " x NAM" << std::endl;
159+ }
160+
161+ if (rtNeuralModel != nullptr )
162+ {
163+ std::cout << std::endl;
164+
165+ rtNeural = BenchModel (rtNeuralModel, blockSize, numBlocks);
166+
167+ std::cout << " RTNeural: " << std::get<0 >(rtNeural) << " (" << std::get<1 >(rtNeural) << " )" << std::endl;
168+ rms = ComputeError (namCoreModel, rtNeuralModel, blockSize, numBlocks);
169+ std::cout << " NAM vs RTNeural RMS err: " << rms << std::endl;
170+
171+ if (namCoreModel != nullptr )
172+ {
173+ std::cout << " RTNeural is: " << (std::get<0 >(namCore) / std::get<0 >(rtNeural)) << " x NAM" << std::endl;
174+ }
175+ }
176+
177+ std::cout << std::endl;
150178}
151179
152180void RunKerasTests (std::filesystem::path modelPath, int blockSize)
@@ -159,8 +187,8 @@ void RunKerasTests(std::filesystem::path modelPath, int blockSize)
159187
160188 NeuralAudio::NeuralModel::SetDefaultMaxAudioBufferSize (blockSize);
161189
162- auto internalModel = LoadModel (modelPath, NeuralAudio:: EModelLoadMode::Internal);
163- auto rtNeuralModel = LoadModel (modelPath, NeuralAudio:: EModelLoadMode::RTNeural);
190+ auto internalModel = LoadModel (modelPath, EModelLoadMode::Internal);
191+ auto rtNeuralModel = LoadModel (modelPath, EModelLoadMode::RTNeural);
164192
165193 double rms = ComputeError (rtNeuralModel, internalModel, blockSize, numBlocks);
166194 std::cout << " Internal vs RTNeural RMS err: " << rms << std::endl;
@@ -195,11 +223,13 @@ int RunDefaultTests(int blockSize)
195223
196224 modelPath = modelPath / " Models" ;
197225
198- std::cout << " Loading models from: " << modelPath << std::endl;
226+ std::cout << " Loading models from: " << modelPath << std::endl << std::endl ;
199227
200228 std::cout << " WaveNet (Standard) Test" << std::endl;
201229 RunNAMTests (modelPath / " BossWN-standard.nam" , blockSize);
202230
231+ std::cout << std::endl;
232+
203233 std::cout << " LSTM (1x16) Test" << std::endl;
204234 RunNAMTests (modelPath / " BossLSTM-1x16.nam" , blockSize);
205235
@@ -208,6 +238,8 @@ int RunDefaultTests(int blockSize)
208238
209239int main (int argc, char * argv[])
210240{
241+ std::cout << std::endl;
242+
211243 int blockSize = 64 ;
212244
213245 std::filesystem::path modelPath;
0 commit comments