Skip to content

Commit

Permalink
refactor: replace magic numbers with FFT_BUFFER_CHUNK_SIZE constant
Browse files Browse the repository at this point in the history
  • Loading branch information
BayernMuller committed Nov 3, 2024
1 parent e9082c7 commit 5a87a82
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/algorithm/signature_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

SignatureGenerator::SignatureGenerator()
: input_pending_processing_(), sample_processed_(0), max_time_seconds_(3.1),
fft_object_(2048),
next_signature_(16000, 0), samples_ring_buffer_(2048, 0),
fft_outputs_(256, fft::RealArray(1025, 0.0)),
fft_object_(FFT_BUFFER_CHUNK_SIZE), next_signature_(16000, 0),
samples_ring_buffer_(FFT_BUFFER_CHUNK_SIZE, 0), fft_outputs_(256, fft::RealArray(1025, 0.0)),
spread_ffts_output_(256, fft::RealArray(1025, 0.0))
{
}
Expand Down Expand Up @@ -64,19 +63,20 @@ void SignatureGenerator::doFFT(const LowQualityTrack &input)
samples_ring_buffer_.begin() + samples_ring_buffer_.position());

samples_ring_buffer_.position() += input.size();
samples_ring_buffer_.position() %= 2048;
samples_ring_buffer_.position() %= FFT_BUFFER_CHUNK_SIZE;
samples_ring_buffer_.num_written() += input.size();

fft::RealArray excerpt_from_ring_buffer(2048, 0.0);
fft::RealArray excerpt_from_ring_buffer(FFT_BUFFER_CHUNK_SIZE, 0.0);

std::copy(samples_ring_buffer_.begin() + samples_ring_buffer_.position(),
samples_ring_buffer_.end(), excerpt_from_ring_buffer.begin());

std::copy(samples_ring_buffer_.begin(),
samples_ring_buffer_.begin() + samples_ring_buffer_.position(),
excerpt_from_ring_buffer.begin() + 2048 - samples_ring_buffer_.position());
excerpt_from_ring_buffer.begin() + FFT_BUFFER_CHUNK_SIZE -
samples_ring_buffer_.position());

for (int i = 0; i < 2048; ++i)
for (int i = 0; i < FFT_BUFFER_CHUNK_SIZE; ++i)
{
excerpt_from_ring_buffer[i] *= HANNIG_MATRIX[i];
}
Expand Down Expand Up @@ -204,7 +204,7 @@ void SignatureGenerator::doPeakRecognition()
void SignatureGenerator::resetSignatureGenerater()
{
next_signature_ = Signature(16000, 0);
samples_ring_buffer_ = RingBuffer<std::int16_t>(2048, 0);
samples_ring_buffer_ = RingBuffer<std::int16_t>(FFT_BUFFER_CHUNK_SIZE, 0);
fft_outputs_ = RingBuffer<fft::RealArray>(256, fft::RealArray(1025, 0.0));
spread_ffts_output_ = RingBuffer<fft::RealArray>(256, fft::RealArray(1025, 0.0));
}
1 change: 1 addition & 0 deletions lib/algorithm/signature_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "utils/ring_buffer.h"

constexpr auto MAX_PEAKS = 255u;
constexpr auto FFT_BUFFER_CHUNK_SIZE = 2048u;

class SignatureGenerator
{
Expand Down

0 comments on commit 5a87a82

Please sign in to comment.