Entropy Piano Tuner
1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
|
Abstract adapter class for recording audio signals. More...
#include <audiorecorderadapter.h>
Public Member Functions | |
AudioRecorderAdapter () | |
Constructor. More... | |
virtual | ~AudioRecorderAdapter () |
Empty destructor. More... | |
void | resetInputLevelControl () |
Reset input level control. More... | |
void | setMuted (bool muted) |
Set and reset the muting flag. More... | |
void | readAll (PacketType &packet) |
Read all data from the internal buffer. More... | |
void | cutSilence (PacketType &packet) |
Cut trailing silence. More... | |
double | getStopLevel () const |
void | setStandby (bool flag) |
void | setWaitingFlag (bool flag) |
Stroboscope * | getStroboscope () |
Public Member Functions inherited from AudioBase | |
AudioBase () | |
Constructor. More... | |
virtual | ~AudioBase () |
Destructor (no functionality). More... | |
virtual void | init ()=0 |
Inizialize the audio device. More... | |
virtual void | exit ()=0 |
Destroy the audio device. More... | |
virtual void | start ()=0 |
Start/restart the audio device. More... | |
virtual void | stop ()=0 |
Stop the audio device. More... | |
const std::string & | getDeviceName () const |
Get a readable string of the name of the audio device. More... | |
void | setDeviceName (const std::string &n) |
Set the device name. More... | |
int | getSamplingRate () const |
Get the actual sampling rate. More... | |
int | getChannelCount () const |
Get the actual number of channels (1=mono, 2=stereo). More... | |
virtual void | setChannelCount (int cnt) |
Set the number of channels (1=mono, 2=stereo). More... | |
Static Public Attributes | |
static const int | BUFFER_SIZE_IN_SECONDS = 2 |
Capacity of the local circular audio buffer in seconds. More... | |
static const int | UPDATE_IN_MILLISECONDS = 50 |
Update interval in milliseconds, defining the packet size. More... | |
static const double | ATTACKRATE = 0.97 |
Attack rate at which the sliding level goes up (1=instantly). More... | |
static const double | DECAYRATE = 0.7 |
Decay rate at which the sliding level goes down. More... | |
static const double | LEVEL_RETRIGGER = 0.3 |
Level below which retriggering (restart) is allowed. More... | |
static const double | LEVEL_TRIGGER = 0.48 |
Level above which the recorder starts to operate. More... | |
static const double | LEVEL_CUTOFF = 0.9 |
Level above which the input mGain is automatically reduced. More... | |
static const double | DB_OFF = 2 |
dB shift for off mark (high value = shorter recording) More... | |
Protected Member Functions | |
void | pushRawData (const PacketType &data) |
The implementation calls this function when new data is available. More... | |
void | setSamplingRate (int rate) override |
virtual void | setDeviceInputGain (double volume)=0 |
virtual double | getDeviceInputGain () const =0 |
Private Member Functions | |
double | convertIntensityToLevel (double intensity) |
Convert an intensity (variance) of the signal to a VU level. More... | |
double | convertLevelToIntensity (double level) |
Convert a VU level to the corresponding intensity. This function is the inverse of convertIntensityToLevel. More... | |
void | controlRecordingState (double level) |
Control the beginning and the end of recording. More... | |
void | automaticControl (double intensity, double level) |
Automatic noise estimation and threshold adjustment. More... | |
Private Attributes | |
bool | mMuted |
Is the input device muted. More... | |
double | mGain |
Recording amplification factor. More... | |
int | mCounter |
Counts counting incoming PCM values. More... | |
int | mCounterThreshold |
Counter threshold for updating energy. More... | |
double | mPacketM1 |
First intensity moment of a single packet. More... | |
double | mPacketM2 |
Second intensity moment of a single packet. More... | |
double | mSlidingLevel |
Sliding VU level of the signal. More... | |
double | mStopLevel |
Level at which recording stops. More... | |
bool | mRecording |
Flag true if recording is on. More... | |
bool | mRestartable |
Flag true if start/retriggering possible. More... | |
bool | mWaiting |
Wait for the data analysis to be completed. More... | |
bool | mStandby |
Standby flag. More... | |
int | mPacketCounter |
Counter for the number of packages. More... | |
std::map< int, double > | mIntensityHistogram |
Histogram of intensities. More... | |
CircularBuffer< PCMDataType > | mCurrentPacket |
Local audio buffer. More... | |
std::mutex | mCurrentPacketMutex |
Buffer access mutexbo. More... | |
Stroboscope | mStroboscope |
Instance of stroboscope. More... | |
Additional Inherited Members | |
Public Types inherited from AudioBase | |
typedef double | PCMDataType |
typedef std::vector< PCMDataType > | PacketType |
Type definition of a PCM packet (vector of PCM values). More... | |
Abstract adapter class for recording audio signals.
The class has an internal circlar buffer which holds the incoming audio data for a maximum of a few seconds. The user can retrieve the data in form of vector (packet) by calling readAll(&packet).
This class has to be implemented by the actual sound device implementation (AudioRecorderForQt). The implementation has to call pushRawData.
The adapter incorporates an autonomous fully automatic level control.
Definition at line 51 of file audiorecorderadapter.h.
AudioRecorderAdapter::AudioRecorderAdapter | ( | ) |
Constructor.
Definition at line 68 of file audiorecorderadapter.cpp.
|
inlinevirtual |
Empty destructor.
Definition at line 67 of file audiorecorderadapter.h.
|
private |
Automatic noise estimation and threshold adjustment.
This function constructs a histogram of the intensities of all incoming packages. Typically this histogram has a pronounced peak at the left edge, representing the background noise of the microphone in periods of silence. The function locates the edges of the spectrum and adjusts the noise threshold as well as the gain factor.
intensity | : Intensity (variance) of the incoming packet. |
level | : Actual level (shown on the VU meter) of the packet. |
Definition at line 277 of file audiorecorderadapter.cpp.
|
private |
Control the beginning and the end of recording.
This function detects the beginning and the end of the recording period. To this end it counts how many packages have a larger energy than the recording trigger treshold. If there are several of them in a row, the function sends a message that the recording started to all other modules.
The recording process can also be restarted while it is still running provided that the energy falls below the mEnergyRt-threshold.
E | : energy of the actual package |
Definition at line 351 of file audiorecorderadapter.cpp.
|
private |
Convert an intensity (variance) of the signal to a VU level.
intensity | : Variance of the PCM signal |
Definition at line 181 of file audiorecorderadapter.cpp.
|
private |
Convert a VU level to the corresponding intensity. This function is the inverse of convertIntensityToLevel.
level | : Level used to display in a VU meter |
Definition at line 192 of file audiorecorderadapter.cpp.
void AudioRecorderAdapter::cutSilence | ( | PacketType & | packet | ) |
Cut trailing silence.
The local buffer of the adapter has a length of a few seconds. When the recording starts, the buffer will contain a period of silence before the key was hit. This function removes this part of the vector.
packet | : The packet with the audio PCM data (call by reference) |
Definition at line 399 of file audiorecorderadapter.cpp.
|
protectedpure virtual |
Implemented in AudioRecorderForQt.
|
inline |
Definition at line 75 of file audiorecorderadapter.h.
|
inline |
Definition at line 80 of file audiorecorderadapter.h.
|
protected |
The implementation calls this function when new data is available.
This function is called by the implementation when newly read data is ready to be pushed to the local buffer in the adapter. The implementation has to convert the actual PCM data format to floating point values in range [-1,1]. Then it has to call the present function.
The raw signal is multiplied by a gain factor mGain which is adjusted dynamically during the recording process.
data | : Vector containing the raw pcm data to be copied |
Definition at line 214 of file audiorecorderadapter.cpp.
void AudioRecorderAdapter::readAll | ( | PacketType & | packet | ) |
Read all data from the internal buffer.
Reads all data from the internal buffer into the packet vector and clears the internal buffer. This function is called by the SignalAnalyzer.
packet | : Reference to the packet where the new data is stored. |
Definition at line 163 of file audiorecorderadapter.cpp.
void AudioRecorderAdapter::resetInputLevelControl | ( | ) |
Reset input level control.
This function resets the automatic input level control. It is usually called when the reset button below the VU meter is pressed. The function sets the input gain of the impemented input device to 1 by calling the corresponding virtualmfunction. It also sets the local gain to 1 and clears the intensity histogram.
Definition at line 104 of file audiorecorderadapter.cpp.
|
protectedpure virtual |
Implemented in AudioRecorderForQt.
void AudioRecorderAdapter::setMuted | ( | bool | muted | ) |
Set and reset the muting flag.
This will mute the input signal with the effect of sending 0 as input signal and sending the value 0 to the VU meter.
muted | : Activate or deactivate the muting |
Definition at line 125 of file audiorecorderadapter.cpp.
|
overrideprotectedvirtual |
The implementation of the audio device is allowed to change the sampling rate in which case this function is called. It adjusts the actual maximal buffer size so that the maximal time of recording is kept constant.
rate | : New sampling rate |
Reimplemented from AudioBase.
Definition at line 143 of file audiorecorderadapter.cpp.
|
inline |
Definition at line 77 of file audiorecorderadapter.h.
|
inline |
Definition at line 78 of file audiorecorderadapter.h.
|
static |
Attack rate at which the sliding level goes up (1=instantly).
Definition at line 58 of file audiorecorderadapter.h.
|
static |
Capacity of the local circular audio buffer in seconds.
Definition at line 56 of file audiorecorderadapter.h.
|
static |
dB shift for off mark (high value = shorter recording)
Definition at line 63 of file audiorecorderadapter.h.
|
static |
Decay rate at which the sliding level goes down.
Definition at line 59 of file audiorecorderadapter.h.
|
static |
Level above which the input mGain is automatically reduced.
Definition at line 62 of file audiorecorderadapter.h.
|
static |
Level below which retriggering (restart) is allowed.
Definition at line 60 of file audiorecorderadapter.h.
|
static |
Level above which the recorder starts to operate.
Definition at line 61 of file audiorecorderadapter.h.
|
private |
Counts counting incoming PCM values.
Definition at line 96 of file audiorecorderadapter.h.
|
private |
Counter threshold for updating energy.
Definition at line 97 of file audiorecorderadapter.h.
|
private |
Local audio buffer.
Definition at line 110 of file audiorecorderadapter.h.
|
mutableprivate |
Buffer access mutexbo.
Definition at line 111 of file audiorecorderadapter.h.
|
private |
Recording amplification factor.
Definition at line 95 of file audiorecorderadapter.h.
|
private |
Histogram of intensities.
Definition at line 108 of file audiorecorderadapter.h.
|
private |
Is the input device muted.
Definition at line 94 of file audiorecorderadapter.h.
|
private |
Counter for the number of packages.
Definition at line 106 of file audiorecorderadapter.h.
|
private |
First intensity moment of a single packet.
Definition at line 98 of file audiorecorderadapter.h.
|
private |
Second intensity moment of a single packet.
Definition at line 99 of file audiorecorderadapter.h.
|
private |
Flag true if recording is on.
Definition at line 102 of file audiorecorderadapter.h.
|
private |
Flag true if start/retriggering possible.
Definition at line 103 of file audiorecorderadapter.h.
|
private |
Sliding VU level of the signal.
Definition at line 100 of file audiorecorderadapter.h.
|
private |
Standby flag.
Definition at line 105 of file audiorecorderadapter.h.
|
private |
Level at which recording stops.
Definition at line 101 of file audiorecorderadapter.h.
|
private |
Instance of stroboscope.
Definition at line 113 of file audiorecorderadapter.h.
|
private |
Wait for the data analysis to be completed.
Definition at line 104 of file audiorecorderadapter.h.
|
static |
Update interval in milliseconds, defining the packet size.
Definition at line 57 of file audiorecorderadapter.h.