Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 5, 2024
2 parents c1542ba + 6b2aca1 commit ee0f04f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
36 changes: 7 additions & 29 deletions src/AudioTools/AudioLibs/TfLiteAudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Configure FFT to output 16 bit fixed point.
#define FIXED_POINT 16

//#include <MicroTFLite.h>
#include <TensorFlowLite.h>
#include <cmath>
#include <cstdint>
Expand All @@ -13,7 +14,6 @@
#include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h"
#include "tensorflow/lite/micro/all_ops_resolver.h"
#include "tensorflow/lite/micro/kernels/micro_ops.h"
#include "tensorflow/lite/micro/micro_error_reporter.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
#include "tensorflow/lite/micro/system_setup.h"
Expand Down Expand Up @@ -55,25 +55,6 @@ class TfLiteWriter {
virtual bool begin(TfLiteAudioStreamBase *parent) = 0;
virtual bool write(const int16_t sample) = 0;
};
/**
* @brief Error Reporter using the Audio Tools Logger
* @ingroup tflite
* @author Phil Schatzmann
* @copyright GPLv3
*/
class TfLiteAudioErrorReporter : public tflite::ErrorReporter {
public:
virtual ~TfLiteAudioErrorReporter() {}
virtual int Report(const char* format, va_list args) override {
int result = snprintf(msg, 200, format, args);
LOGE(msg);
return result;
}

protected:
char msg[200];
} my_error_reporter;
tflite::ErrorReporter* error_reporter = &my_error_reporter;

/**
* @brief Configuration settings for TfLiteAudioStream
Expand All @@ -96,7 +77,7 @@ struct TfLiteConfig {
// Create an area of memory to use for input, output, and intermediate arrays.
// The size of this will depend on the model you’re using, and may need to be
// determined by experimentation.
int kTensorArenaSize = 10 * 1024;
size_t kTensorArenaSize = 10 * 1024;

// Keeping these as constant expressions allow us to allocate fixed-sized
// arrays on the stack for our working memory.
Expand Down Expand Up @@ -980,14 +961,12 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
TRACEI();
if (cfg.useAllOpsResolver) {
tflite::AllOpsResolver resolver;
static tflite::MicroInterpreter static_interpreter(
p_model, resolver, p_tensor_arena, cfg.kTensorArenaSize,
error_reporter);
static tflite::MicroInterpreter static_interpreter{
p_model, resolver, p_tensor_arena, cfg.kTensorArenaSize};
p_interpreter = &static_interpreter;
} else {
// NOLINTNEXTLINE(runtime-global-variables)
static tflite::MicroMutableOpResolver<4> micro_op_resolver(
error_reporter);
static tflite::MicroMutableOpResolver<4> micro_op_resolver{};
if (micro_op_resolver.AddDepthwiseConv2D() != kTfLiteOk) {
return false;
}
Expand All @@ -1001,9 +980,8 @@ class TfLiteAudioStream : public TfLiteAudioStreamBase {
return false;
}
// Build an p_interpreter to run the model with.
static tflite::MicroInterpreter static_interpreter(
p_model, micro_op_resolver, p_tensor_arena, cfg.kTensorArenaSize,
error_reporter);
static tflite::MicroInterpreter static_interpreter{
p_model, micro_op_resolver, p_tensor_arena, cfg.kTensorArenaSize};
p_interpreter = &static_interpreter;
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/AudioTools/CoreAudio/AudioHttp/URLStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ class URLStream : public AbstractURLStream {
total_read = 0;
active = result == 200;
LOGI("==> http status: %d", result);
#if USE_AUDIO_LOGGING
custom_log_level.reset();

#endif
return active;
}

Expand All @@ -121,8 +122,9 @@ class URLStream : public AbstractURLStream {
total_read = 0;
active = result == 200;
LOGI("==> http status: %d", result);
#if USE_AUDIO_LOGGING
custom_log_level.reset();

#endif
return active;
}

Expand Down Expand Up @@ -247,14 +249,17 @@ class URLStream : public AbstractURLStream {
return request.available() > 0;
}

#if USE_AUDIO_LOGGING
/// Defines the class specific custom log level
void setLogLevel(AudioLogger::LogLevel level) { custom_log_level.set(level); }

#endif
const char* urlStr() { return url_str.c_str(); }

protected:
HttpRequest request;
#if USE_AUDIO_LOGGING
CustomLogLevel custom_log_level;
#endif
Str url_str;
Url url;
long size;
Expand Down Expand Up @@ -282,7 +287,9 @@ class URLStream : public AbstractURLStream {

bool preProcess(const char* urlStr, const char* acceptMime) {
TRACED();
#if USE_AUDIO_LOGGING
custom_log_level.set();
#endif
url_str = urlStr;
url.setUrl(url_str.c_str());
int result = -1;
Expand Down

0 comments on commit ee0f04f

Please sign in to comment.