Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Stroboscope Class Reference

Class for a stroboscopic tuning indicator. More...

#include <stroboscope.h>

+ Collaboration diagram for Stroboscope:

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...
 
AudioRecorderAdaptermRecorder
 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...
 

Detailed Description

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.

See also
AudioRecorderAdapter
TuningIndicatorDrawer

Definition at line 67 of file stroboscope.h.

Member Typedef Documentation

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.

Constructor & Destructor Documentation

Stroboscope::Stroboscope ( AudioRecorderAdapter recorder)

Constructor.

Stroboscope::Stroboscope.

Parameters
recorder

Definition at line 40 of file stroboscope.cpp.

Member Function Documentation

void Stroboscope::pushRawData ( const AudioBase::PacketType data)

Stroboscope::pushRawData.

Parameters
data

Definition at line 59 of file stroboscope.cpp.

+ Here is the call graph for this function:

void Stroboscope::setFramesPerSecond ( double  fps)

Stroboscope::setFramesPerSecond.

Parameters
fps

Definition at line 101 of file stroboscope.cpp.

+ Here is the call graph for this function:

void Stroboscope::setFrequencies ( const std::vector< double > &  frequencies)

Stroboscope::setFrequencies.

Parameters
frequencies

Definition at line 116 of file stroboscope.cpp.

+ Here is the call graph for this function:

void Stroboscope::start ( )
inline

Start the stroboscope.

Definition at line 81 of file stroboscope.h.

void Stroboscope::stop ( )
inline

Stop the stroboscope.

Definition at line 82 of file stroboscope.h.

Member Data Documentation

const double Stroboscope::AMPLITUDE_DAMPING = 0.95
private

Damping factor of the normalizing amplitude level on a single frame (0...1)

Definition at line 71 of file stroboscope.h.

const double Stroboscope::FRAME_DAMPING = 0.5
private

Damping of the complex phases from frame to frame (0...1)

Definition at line 74 of file stroboscope.h.

bool Stroboscope::mActive
private

Flag indicating activity (start/stop)

Definition at line 90 of file stroboscope.h.

ComplexVector Stroboscope::mComplexIncrement
private

Factor by which the complex number rotates.

Definition at line 95 of file stroboscope.h.

ComplexVector Stroboscope::mComplexPhase
private

Rotating complex number.

Definition at line 94 of file stroboscope.h.

double Stroboscope::mMaxAmplitude
private

Sliding amplitude to normalize the data.

Definition at line 93 of file stroboscope.h.

ComplexVector Stroboscope::mMeanComplexPhase
private

Phase average over the actual frame.

Definition at line 96 of file stroboscope.h.

std::mutex Stroboscope::mMutex
private

Mutex protecting access from different threads.

Definition at line 97 of file stroboscope.h.

AudioRecorderAdapter* Stroboscope::mRecorder
private

Pointer to the audio recorder.

Definition at line 89 of file stroboscope.h.

int Stroboscope::mSampleCounter
private

Actual number of PCM samples read.

Definition at line 92 of file stroboscope.h.

int Stroboscope::mSamplesPerFrame
private

Number of PCM samples per frame.

Definition at line 91 of file stroboscope.h.


The documentation for this class was generated from the following files: