Commit b1f87f6e authored by Paul Bethge's avatar Paul Bethge
Browse files

add normalization

parent ce6d957b
......@@ -60,6 +60,10 @@ class AudioClassifier : public ofxTF2::Model {
// downsample and empty the incoming Fifo
downsample(bufferFifo, sample, downsamplingFactor);
ofLog() << std::to_string(sample[0]);
normalize(sample);
ofLog() << std::to_string(sample[0]);
// convert recorded sample to a batch of size one
ofxTF2::shapeVector tensorShape {1, static_cast<ofxTF2::shape_t>(sample.size()), 1};
auto input = ofxTF2::vectorToTensor(sample, tensorShape);
......@@ -79,6 +83,23 @@ class AudioClassifier : public ofxTF2::Model {
private:
// inplace normalization
void normalize(SimpleAudioBuffer & sample) {
// find absolute maximum value
float max = 0.0;
for (const auto& s : sample) {
if (abs(s) > max) {
max = abs(s);
}
}
if (max == 0.0)
return;
for (auto&& s : sample) {
s /= max;
}
}
// downsample by an integer
void downsample(AudioBufferFifo & bufferFifo, SimpleAudioBuffer & sample,
const std::size_t downsamplingFactor) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment