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
AudioRecorderAdapter Class Referenceabstract

Abstract adapter class for recording audio signals. More...

#include <audiorecorderadapter.h>

+ Inheritance diagram for AudioRecorderAdapter:
+ Collaboration diagram for AudioRecorderAdapter:

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)
 
StroboscopegetStroboscope ()
 
- 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< PCMDataTypemCurrentPacket
 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< PCMDataTypePacketType
 Type definition of a PCM packet (vector of PCM values). More...
 

Detailed Description

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.

Constructor & Destructor Documentation

AudioRecorderAdapter::AudioRecorderAdapter ( )

Constructor.

Definition at line 68 of file audiorecorderadapter.cpp.

+ Here is the call graph for this function:

virtual AudioRecorderAdapter::~AudioRecorderAdapter ( )
inlinevirtual

Empty destructor.

Definition at line 67 of file audiorecorderadapter.h.

Member Function Documentation

void AudioRecorderAdapter::automaticControl ( double  intensity,
double  level 
)
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.

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

+ Here is the call graph for this function:

void AudioRecorderAdapter::controlRecordingState ( double  level)
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.

Parameters
E: energy of the actual package

Definition at line 351 of file audiorecorderadapter.cpp.

+ Here is the call graph for this function:

double AudioRecorderAdapter::convertIntensityToLevel ( double  intensity)
private

Convert an intensity (variance) of the signal to a VU level.

Parameters
intensity: Variance of the PCM signal
Returns
Level to be displayed by the VU meter (not clipped to [0,1])

Definition at line 181 of file audiorecorderadapter.cpp.

double AudioRecorderAdapter::convertLevelToIntensity ( double  level)
private

Convert a VU level to the corresponding intensity. This function is the inverse of convertIntensityToLevel.

Parameters
level: Level used to display in a VU meter
Returns
Corresponding intensity

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.

Parameters
packet: The packet with the audio PCM data (call by reference)

Definition at line 399 of file audiorecorderadapter.cpp.

+ Here is the call graph for this function:

virtual double AudioRecorderAdapter::getDeviceInputGain ( ) const
protectedpure virtual

Implemented in AudioRecorderForQt.

double AudioRecorderAdapter::getStopLevel ( ) const
inline

Definition at line 75 of file audiorecorderadapter.h.

Stroboscope* AudioRecorderAdapter::getStroboscope ( )
inline

Definition at line 80 of file audiorecorderadapter.h.

void AudioRecorderAdapter::pushRawData ( const PacketType data)
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.

Parameters
data: Vector containing the raw pcm data to be copied

Definition at line 214 of file audiorecorderadapter.cpp.

+ Here is the call graph for this function:

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.

Parameters
packet: Reference to the packet where the new data is stored.

Definition at line 163 of file audiorecorderadapter.cpp.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

virtual void AudioRecorderAdapter::setDeviceInputGain ( double  volume)
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.

Parameters
muted: Activate or deactivate the muting

Definition at line 125 of file audiorecorderadapter.cpp.

void AudioRecorderAdapter::setSamplingRate ( int  rate)
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.

Parameters
rate: New sampling rate

Reimplemented from AudioBase.

Definition at line 143 of file audiorecorderadapter.cpp.

+ Here is the call graph for this function:

void AudioRecorderAdapter::setStandby ( bool  flag)
inline

Definition at line 77 of file audiorecorderadapter.h.

void AudioRecorderAdapter::setWaitingFlag ( bool  flag)
inline

Definition at line 78 of file audiorecorderadapter.h.

Member Data Documentation

const double AudioRecorderAdapter::ATTACKRATE = 0.97
static

Attack rate at which the sliding level goes up (1=instantly).

Definition at line 58 of file audiorecorderadapter.h.

const int AudioRecorderAdapter::BUFFER_SIZE_IN_SECONDS = 2
static

Capacity of the local circular audio buffer in seconds.

Definition at line 56 of file audiorecorderadapter.h.

const double AudioRecorderAdapter::DB_OFF = 2
static

dB shift for off mark (high value = shorter recording)

Definition at line 63 of file audiorecorderadapter.h.

const double AudioRecorderAdapter::DECAYRATE = 0.7
static

Decay rate at which the sliding level goes down.

Definition at line 59 of file audiorecorderadapter.h.

const double AudioRecorderAdapter::LEVEL_CUTOFF = 0.9
static

Level above which the input mGain is automatically reduced.

Definition at line 62 of file audiorecorderadapter.h.

const double AudioRecorderAdapter::LEVEL_RETRIGGER = 0.3
static

Level below which retriggering (restart) is allowed.

Definition at line 60 of file audiorecorderadapter.h.

const double AudioRecorderAdapter::LEVEL_TRIGGER = 0.48
static

Level above which the recorder starts to operate.

Definition at line 61 of file audiorecorderadapter.h.

int AudioRecorderAdapter::mCounter
private

Counts counting incoming PCM values.

Definition at line 96 of file audiorecorderadapter.h.

int AudioRecorderAdapter::mCounterThreshold
private

Counter threshold for updating energy.

Definition at line 97 of file audiorecorderadapter.h.

CircularBuffer<PCMDataType> AudioRecorderAdapter::mCurrentPacket
private

Local audio buffer.

Definition at line 110 of file audiorecorderadapter.h.

std::mutex AudioRecorderAdapter::mCurrentPacketMutex
mutableprivate

Buffer access mutexbo.

Definition at line 111 of file audiorecorderadapter.h.

double AudioRecorderAdapter::mGain
private

Recording amplification factor.

Definition at line 95 of file audiorecorderadapter.h.

std::map<int,double> AudioRecorderAdapter::mIntensityHistogram
private

Histogram of intensities.

Definition at line 108 of file audiorecorderadapter.h.

bool AudioRecorderAdapter::mMuted
private

Is the input device muted.

Definition at line 94 of file audiorecorderadapter.h.

int AudioRecorderAdapter::mPacketCounter
private

Counter for the number of packages.

Definition at line 106 of file audiorecorderadapter.h.

double AudioRecorderAdapter::mPacketM1
private

First intensity moment of a single packet.

Definition at line 98 of file audiorecorderadapter.h.

double AudioRecorderAdapter::mPacketM2
private

Second intensity moment of a single packet.

Definition at line 99 of file audiorecorderadapter.h.

bool AudioRecorderAdapter::mRecording
private

Flag true if recording is on.

Definition at line 102 of file audiorecorderadapter.h.

bool AudioRecorderAdapter::mRestartable
private

Flag true if start/retriggering possible.

Definition at line 103 of file audiorecorderadapter.h.

double AudioRecorderAdapter::mSlidingLevel
private

Sliding VU level of the signal.

Definition at line 100 of file audiorecorderadapter.h.

bool AudioRecorderAdapter::mStandby
private

Standby flag.

Definition at line 105 of file audiorecorderadapter.h.

double AudioRecorderAdapter::mStopLevel
private

Level at which recording stops.

Definition at line 101 of file audiorecorderadapter.h.

Stroboscope AudioRecorderAdapter::mStroboscope
private

Instance of stroboscope.

Definition at line 113 of file audiorecorderadapter.h.

bool AudioRecorderAdapter::mWaiting
private

Wait for the data analysis to be completed.

Definition at line 104 of file audiorecorderadapter.h.

const int AudioRecorderAdapter::UPDATE_IN_MILLISECONDS = 50
static

Update interval in milliseconds, defining the packet size.

Definition at line 57 of file audiorecorderadapter.h.


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