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.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Stroboscope
22 //=============================================================================
23 
24 // Test sine waves with: play -n synth sin 440 vol 0.1
25 // monitor system input with xoscope
26 
27 #ifndef STROBOSCOPE_H
28 #define STROBOSCOPE_H
29 
30 #include <complex>
31 #include <vector>
32 #include <mutex>
33 
34 #include "../audiobase.h"
35 
37 
66 
68 {
69 private:
71  const double AMPLITUDE_DAMPING = 0.95;
72 
74  const double FRAME_DAMPING = 0.5;
75 
76 public:
77  using Complex = std::complex<double>;
78  using ComplexVector = std::vector<Complex>;
79 
80  Stroboscope (AudioRecorderAdapter *recorder);
81  void start () { mActive = true; }
82  void stop () { mActive = false; }
83 
84  void setFramesPerSecond (double fps);
85  void setFrequencies (const std::vector<double> &frequencies);
86  void pushRawData (const AudioBase::PacketType &data);
87 
88 private:
90  bool mActive;
93  double mMaxAmplitude;
97  std::mutex mMutex;
98 };
99 
100 #endif // STROBOSCOPE_H
ComplexVector mComplexPhase
Rotating complex number.
Definition: stroboscope.h:94
void setFramesPerSecond(double fps)
Stroboscope::setFramesPerSecond.
std::vector< PCMDataType > PacketType
Type definition of a PCM packet (vector of PCM values).
Definition: audiobase.h:51
Abstract adapter class for recording audio signals.
void pushRawData(const AudioBase::PacketType &data)
Stroboscope::pushRawData.
Definition: stroboscope.cpp:59
bool mActive
Flag indicating activity (start/stop)
Definition: stroboscope.h:90
std::mutex mMutex
Mutex protecting access from different threads.
Definition: stroboscope.h:97
ComplexVector mComplexIncrement
Factor by which the complex number rotates.
Definition: stroboscope.h:95
ComplexVector mMeanComplexPhase
Phase average over the actual frame.
Definition: stroboscope.h:96
void stop()
Stop the stroboscope.
Definition: stroboscope.h:82
Class for a stroboscopic tuning indicator.
Definition: stroboscope.h:67
const double FRAME_DAMPING
Damping of the complex phases from frame to frame (0...1)
Definition: stroboscope.h:74
int mSampleCounter
Actual number of PCM samples read.
Definition: stroboscope.h:92
Stroboscope(AudioRecorderAdapter *recorder)
Constructor.
Definition: stroboscope.cpp:40
std::vector< Complex > ComplexVector
Type for a vector of complex numbers.
Definition: stroboscope.h:78
void start()
Start the stroboscope.
Definition: stroboscope.h:81
void setFrequencies(const std::vector< double > &frequencies)
Stroboscope::setFrequencies.
const double AMPLITUDE_DAMPING
Damping factor of the normalizing amplitude level on a single frame (0...1)
Definition: stroboscope.h:71
double mMaxAmplitude
Sliding amplitude to normalize the data.
Definition: stroboscope.h:93
AudioRecorderAdapter * mRecorder
Pointer to the audio recorder.
Definition: stroboscope.h:89
int mSamplesPerFrame
Number of PCM samples per frame.
Definition: stroboscope.h:91
std::complex< double > Complex
Type for a complex number.
Definition: stroboscope.h:77