Skip to content

Commit f6c7c49

Browse files
committed
Update for using the new pre/postprocess_in/output_channels member
1 parent 3169f7f commit f6c7c49

21 files changed

Lines changed: 96 additions & 95 deletions

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [ ] Add option to select different model functions
1010
- [ ] Add option for dynamic input size
1111
- [ ] Manual inference triggering
12+
- [ ] Fix TFLite benchmark error
1213

1314
## How to handle parameters
1415

docs/anira-usage.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ There are also some optional parameters that can be set in the `anira::Inference
9595
If your model does not require any specific pre- or post-processing, you can use the default `anira::PrePostProcessor`. This is likely to be the case if the input and output shapes of the model are the same, the batchsize is 1, and your model operates in the time domain.
9696

9797
```cpp
98-
anira::PrePostProcessor pp_processor;
98+
anira::PrePostProcessor pp_processor(inference_config);
9999
```
100100
101101
If your model requires custom pre- or post-processing, you can inherit from the `anira::PrePostProcessor` class and overwrite the ```pre_process``` and ```post_process``` methods so that they match your model's requirements. In the ```pre_process``` method, we get the input samples from the audio application through an `anira::RingBuffer` and push them into the output buffer, which is an `anira::BufferF`. This output buffer is then used for inference. In the ```post_process``` method we get the input samples through an `anira::BufferF` and push them into the output buffer, which is an `anira::RingBuffer`. The samples from this output buffer are then returned to the audio application by the `anira::InferenceHandler`.
@@ -108,6 +108,8 @@ When your pre- and post-processing requires to access values from the `anira::In
108108
109109
class CustomPrePostProcessor : public anira::PrePostProcessor {
110110
public:
111+
using anira::PrePostProcessor::PrePostProcessor;
112+
111113
virtual void pre_process(anira::RingBuffer& input, anira::BufferF& output, [[maybe_unused]] anira::InferenceBackend current_inference_backend) override {
112114
pop_samples_from_buffer(input, output, inference_config.get_tensor_output_size()[inference_config.m_index_audio_data[anira::IndexAudioData::Output]], inference_config.get_tensor_input_size()[inference_config.m_index_audio_data[anira::IndexAudioData::Input]]-inference_config.get_tensor_output_size()[inference_config.m_index_audio_data[anira::IndexAudioData::Output]]);
113115
};
@@ -144,9 +146,9 @@ In your application, you will need to create an instance of the `anira::Inferenc
144146
// Sample initialization in your application's initialization function
145147

146148
// Default PrePostProcessor
147-
anira::PrePostProcessor pp_processor;
149+
anira::PrePostProcessor pp_processor(inference_config);
148150
// or custom PrePostProcessor
149-
CustomPrePostProcessor pp_processor;
151+
CustomPrePostProcessor pp_processor(inference_config);
150152

151153
// Create an InferenceHandler instance
152154
anira::InferenceHandler inference_handler(pp_processor, inference_config);

docs/benchmark-usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef anira::benchmark::ProcessBlockFixture ProcessBlockFixture;
2929
anira::InferenceConfig my_inference_config(
3030
...
3131
);
32-
anira::PrePostProcessor my_pp_processor;
32+
anira::PrePostProcessor my_pp_processor(my_inference_config);
3333

3434
BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_SIMPLE)(::benchmark::State& state) {
3535

@@ -43,7 +43,7 @@ BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_SIMPLE)(::benchmark::State& state) {
4343
m_inference_handler->set_inference_backend(inference_backend);
4444

4545
// Create a static Buffer instance
46-
m_buffer = std::make_unique<anira::Buffer<float>>(my_inference_config.m_num_audio_channels[anira::Input], host_config.m_host_buffer_size);
46+
m_buffer = std::make_unique<anira::Buffer<float>>(my_inference_config.get_preprocess_input_channels()[0], host_config.m_host_buffer_size);
4747

4848
// Initialize the repetition
4949
initialize_repetition(my_inference_config, host_config, inference_backend, true);
@@ -240,7 +240,7 @@ BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_ADVANCED)(::benchmark::State& state)
240240
// Use state.range(2) to select the inference backend
241241
m_inference_handler->set_inference_backend(inference_backends[state.range(2)]);
242242
243-
m_buffer = std::make_unique<anira::Buffer<float>>(inference_config.m_num_audio_channels[anira::Input], host_config.m_host_buffer_size);
243+
m_buffer = std::make_unique<anira::Buffer<float>>(inference_config.get_preprocess_input_channels()[0], host_config.m_host_buffer_size);
244244
245245
initialize_repetition(inference_config, host_config, inference_backends[state.range(2)]);
246246

examples/benchmark/advanced-benchmark/defineAdvancedBenchmark.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@ BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_ADVANCED)(::benchmark::State& state)
6666
anira::PrePostProcessor *my_pp_processor;
6767

6868
if (state.range(1) == 0) {
69-
my_pp_processor = new CNNPrePostProcessor();
70-
static_cast<CNNPrePostProcessor*>(my_pp_processor)->m_inference_config = inference_config;
69+
my_pp_processor = new CNNPrePostProcessor(inference_config);
7170
} else if (state.range(1) == 1) {
72-
my_pp_processor = new HybridNNPrePostProcessor();
73-
static_cast<HybridNNPrePostProcessor*>(my_pp_processor)->m_inference_config = inference_config;
71+
my_pp_processor = new HybridNNPrePostProcessor(inference_config);
7472
} else if (state.range(1) == 2) {
75-
my_pp_processor = new anira::PrePostProcessor();
73+
my_pp_processor = new anira::PrePostProcessor(inference_config);
7674
}
7775

7876
ClearCustomProcessor clear_custom_processor(inference_config);
@@ -81,7 +79,7 @@ BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_ADVANCED)(::benchmark::State& state)
8179
m_inference_handler->prepare(host_config);
8280
m_inference_handler->set_inference_backend(inference_backends[state.range(2)]);
8381

84-
m_buffer = std::make_unique<anira::Buffer<float>>(inference_config.m_num_audio_channels[anira::Input], host_config.m_host_buffer_size);
82+
m_buffer = std::make_unique<anira::Buffer<float>>(inference_config.get_preprocess_input_channels()[0], host_config.m_host_buffer_size);
8583

8684
initialize_repetition(inference_config, host_config, inference_backends[state.range(2)]);
8785

examples/benchmark/cnn-size-benchmark/defineCNNSizeBenchmark.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_CNNSIZE)(::benchmark::State& state) {
6060

6161
anira::PrePostProcessor *my_pp_processor;
6262

63-
my_pp_processor = new CNNPrePostProcessor();
64-
static_cast<CNNPrePostProcessor*>(my_pp_processor)->m_inference_config = inference_config;
63+
my_pp_processor = new CNNPrePostProcessor(inference_config);
6564

6665
m_inference_handler = std::make_unique<anira::InferenceHandler>(*my_pp_processor, inference_config);
6766
m_inference_handler->prepare(host_config);
6867
m_inference_handler->set_inference_backend(inference_backends[state.range(2)]);
6968

70-
m_buffer = std::make_unique<anira::Buffer<float>>(inference_config.m_num_audio_channels[anira::Input], host_config.m_host_buffer_size);
69+
m_buffer = std::make_unique<anira::Buffer<float>>(inference_config.get_preprocess_input_channels()[0], host_config.m_host_buffer_size);
7170

7271
initialize_repetition(inference_config, host_config, inference_backends[state.range(2)]);
7372

examples/benchmark/simple-benchmark/defineSimpleBenchmark.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
typedef anira::benchmark::ProcessBlockFixture ProcessBlockFixture;
2929

3030
// anira::InferenceConfig my_inference_config = cnn_config;
31-
// CNNPrePostProcessor my_pp_processor;
31+
// CNNPrePostProcessor my_pp_processor(my_inference_config);
3232
anira::InferenceConfig my_inference_config = hybridnn_config;
33-
HybridNNPrePostProcessor my_pp_processor;
33+
HybridNNPrePostProcessor my_pp_processor(my_inference_config);
3434
// anira::InferenceConfig my_inference_config = rnn_config;
35-
// anira::PrePostProcessor my_pp_processor;
35+
// anira::PrePostProcessor my_pp_processor(my_inference_config);
3636
// anira::InferenceConfig my_inference_config = gain_config;
3737
// anira::PrePostProcessor my_pp_processor(my_inference_config);
3838
// anira::InferenceConfig my_inference_config = stereo_gain_config;
@@ -48,7 +48,7 @@ BENCHMARK_DEFINE_F(ProcessBlockFixture, BM_SIMPLE)(::benchmark::State& state) {
4848
m_inference_handler->prepare(host_config);
4949
m_inference_handler->set_inference_backend(inference_backend);
5050

51-
m_buffer = std::make_unique<anira::Buffer<float>>(my_inference_config.m_num_audio_channels[anira::Input], host_config.m_host_buffer_size);
51+
m_buffer = std::make_unique<anira::Buffer<float>>(my_inference_config.get_preprocess_input_channels()[0], host_config.m_host_buffer_size);
5252

5353
initialize_repetition(my_inference_config, host_config, inference_backend);
5454

examples/clap-audio-plugin/anira-clap-demo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ AniraClapPluginExample::AniraClapPluginExample(const clap_host *host)
1717
clap::helpers::CheckingLevel::Maximal>(&m_desc, host),
1818
m_bypass_processor(m_inference_config),
1919
m_anira_context(static_cast<int>(std::thread::hardware_concurrency() / 2)),
20+
m_pp_processor(m_inference_config),
2021
m_inference_handler(m_pp_processor, m_inference_config, m_bypass_processor, m_anira_context),
2122
m_plugin_latency(0)
2223
{

examples/juce-audio-plugin/PluginProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ AudioPluginAudioProcessor::AudioPluginAudioProcessor()
1616
anira_context_config(
1717
std::thread::hardware_concurrency() / 2 > 0 ? std::thread::hardware_concurrency() / 2 : 1 // Total number of threads
1818
),
19+
pp_processor(inference_config),
1920
#if MODEL_TO_USE == 1 || MODEL_TO_USE == 2
2021
// The bypass_processor is not needed for inference, but for the round trip test to output audio when selecting the CUSTOM backend. It must be customized when default pp_processor is replaced by a custom one.
2122
bypass_processor(inference_config),
2223
inference_handler(pp_processor, inference_config, bypass_processor, anira_context_config),
2324
#elif MODEL_TO_USE == 3 || MODEL_TO_USE == 4 || MODEL_TO_USE == 5
24-
pp_processor(inference_config),
2525
inference_handler(pp_processor, inference_config),
2626
#endif
2727
dry_wet_mixer(32768) // 32768 samples of max latency compensation for the dry-wet mixer

extras/models/cnn/CNNPrePostProcessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
class CNNPrePostProcessor : public anira::PrePostProcessor
88
{
99
public:
10+
using anira::PrePostProcessor::PrePostProcessor;
11+
1012
virtual void pre_process(anira::RingBuffer& input, anira::BufferF& output, [[maybe_unused]] anira::InferenceBackend current_inference_backend) override {
1113
pop_samples_from_buffer(input, output, m_inference_config.get_tensor_output_size()[m_inference_config.m_index_audio_data[anira::IndexAudioData::Output]], m_inference_config.get_tensor_input_size()[m_inference_config.m_index_audio_data[anira::IndexAudioData::Input]]-m_inference_config.get_tensor_output_size()[m_inference_config.m_index_audio_data[anira::IndexAudioData::Output]]);
1214
}
13-
14-
anira::InferenceConfig m_inference_config = cnn_config;
1515
};
1616

1717
#endif //ANIRA_CNNPREPOSTPROCESSOR_H

extras/models/hybrid-nn/HybridNNPrePostProcessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
class HybridNNPrePostProcessor : public anira::PrePostProcessor
88
{
99
public:
10+
using anira::PrePostProcessor::PrePostProcessor;
11+
1012
virtual void pre_process(anira::RingBuffer& input, anira::BufferF& output, [[maybe_unused]] anira::InferenceBackend current_inference_backend) override {
1113
int64_t num_batches = 0;
1214
int64_t num_input_samples = 0;
@@ -67,8 +69,6 @@ class HybridNNPrePostProcessor : public anira::PrePostProcessor
6769
pop_samples_from_buffer(input, output, (size_t) num_output_samples, (size_t) (num_input_samples-num_output_samples), base_index);
6870
}
6971
}
70-
71-
anira::InferenceConfig m_inference_config = hybridnn_config;
7272
};
7373

7474
#endif //ANIRA_HYBRIDNNPREPOSTPROCESSOR_H

0 commit comments

Comments
 (0)