Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Class for a stroboscopic tuning indicator. More...
#include <stroboscope.h>
Public Types | |
using | Complex = std::complex< double > |
Type for a complex number. More... | |
using | ComplexVector = std::vector< Complex > |
Type for a vector of complex numbers. More... | |
Public Member Functions | |
Stroboscope (AudioRecorderAdapter *recorder) | |
Constructor. More... | |
void | start () |
Start the stroboscope. More... | |
void | stop () |
Stop the stroboscope. More... | |
void | setFramesPerSecond (double fps) |
Stroboscope::setFramesPerSecond. More... | |
void | setFrequencies (const std::vector< double > &frequencies) |
Stroboscope::setFrequencies. More... | |
void | pushRawData (const AudioBase::PacketType &data) |
Stroboscope::pushRawData. More... | |
Private Attributes | |
const double | AMPLITUDE_DAMPING = 0.95 |
Damping factor of the normalizing amplitude level on a single frame (0...1) More... | |
const double | FRAME_DAMPING = 0.5 |
Damping of the complex phases from frame to frame (0...1) More... | |
AudioRecorderAdapter * | mRecorder |
Pointer to the audio recorder. More... | |
bool | mActive |
Flag indicating activity (start/stop) More... | |
int | mSamplesPerFrame |
Number of PCM samples per frame. More... | |
int | mSampleCounter |
Actual number of PCM samples read. More... | |
double | mMaxAmplitude |
Sliding amplitude to normalize the data. More... | |
ComplexVector | mComplexPhase |
Rotating complex number. More... | |
ComplexVector | mComplexIncrement |
Factor by which the complex number rotates. More... | |
ComplexVector | mMeanComplexPhase |
Phase average over the actual frame. More... | |
std::mutex | mMutex |
Mutex protecting access from different threads. More... | |
Class for a stroboscopic tuning indicator.
Ordinary stroboscopic tuners show the analog audio signal amplitude in terms of light intensity masked by a rotating disk. See e.g. https://en.wikipedia.org/wiki/Electronic_tuner#How_a_strobe_tuner_works
Doing the same in our software would require to send the complete PCM data to a stroboscopic drawer which would display it in real time pixel by pixel. This would be computationally expensive. Moreover, the messaging sytem would not be suitable for such a data stream.
We therefore choose a different method. The AudioRecorderAdapter holds an instance of this class and calls the function pushRawData (see below), transmitting all PCM data. This data is reorganized in packages of the size mSamplesPerFrame. Each frame is convolved with a complex number rotating on its unit circle. The speed at which the complex number rotates corresponds to the expected frequencies of the partials, as specified by the function set Frequencies. The result is a set of complex numbers (one for each partial), encoding the intensity of the partial and its complex phase shift. This data is sent (only once for each frame) via the messaging system.
The TuningIndicatorDrawer listens to these messages and draws horizontal bars with phase-shifted rainbow colors.
Definition at line 67 of file stroboscope.h.
using Stroboscope::Complex = std::complex<double> |
Type for a complex number.
Definition at line 77 of file stroboscope.h.
using Stroboscope::ComplexVector = std::vector<Complex> |
Type for a vector of complex numbers.
Definition at line 78 of file stroboscope.h.
Stroboscope::Stroboscope | ( | AudioRecorderAdapter * | recorder | ) |
void Stroboscope::pushRawData | ( | const AudioBase::PacketType & | data | ) |
data |
Definition at line 59 of file stroboscope.cpp.
void Stroboscope::setFramesPerSecond | ( | double | fps | ) |
Stroboscope::setFramesPerSecond.
fps |
Definition at line 101 of file stroboscope.cpp.
void Stroboscope::setFrequencies | ( | const std::vector< double > & | frequencies | ) |
frequencies |
Definition at line 116 of file stroboscope.cpp.
|
inline |
Start the stroboscope.
Definition at line 81 of file stroboscope.h.
|
inline |
Stop the stroboscope.
Definition at line 82 of file stroboscope.h.
|
private |
Damping factor of the normalizing amplitude level on a single frame (0...1)
Definition at line 71 of file stroboscope.h.
|
private |
Damping of the complex phases from frame to frame (0...1)
Definition at line 74 of file stroboscope.h.
|
private |
Flag indicating activity (start/stop)
Definition at line 90 of file stroboscope.h.
|
private |
Factor by which the complex number rotates.
Definition at line 95 of file stroboscope.h.
|
private |
Rotating complex number.
Definition at line 94 of file stroboscope.h.
|
private |
Sliding amplitude to normalize the data.
Definition at line 93 of file stroboscope.h.
|
private |
Phase average over the actual frame.
Definition at line 96 of file stroboscope.h.
|
private |
Mutex protecting access from different threads.
Definition at line 97 of file stroboscope.h.
|
private |
Pointer to the audio recorder.
Definition at line 89 of file stroboscope.h.
|
private |
Actual number of PCM samples read.
Definition at line 92 of file stroboscope.h.
|
private |
Number of PCM samples per frame.
Definition at line 91 of file stroboscope.h.