29 #include "../../messages/messagerecorderenergychanged.h"
30 #include "../../messages/messagemodechanged.h"
31 #include "../../messages/messagehandler.h"
32 #include "../../math/mathtools.h"
33 #include "../../system/log.h"
82 mIntensityHistogram(),
216 if (data.size()==0)
return;
224 for (
auto &pcmvalue : data)
279 if (intensity == 0)
return;
295 double dB = 4.34294 * log(intensity);
302 double norm=0, MIN=0, MAX=0;
306 MIN += pow(fabs(static_cast<double>(e.first)),10) * e.second;
307 MAX += exp(e.first) * e.second;
310 double dBoff = -pow(MIN/norm,1.0/10) +
DB_OFF;
311 double dBmax = log(MAX/norm);
314 double gain_target = exp(-dBmax/4.34294/2.0);
323 MessageHandler::send<MessageRecorderEnergyChanged>(
329 if (
mPacketCounter >= 10)
for (
auto &e: mIntensityHistogram) e.second /= 1.018;
361 LogI(
"Recording stopped");
377 else LogI(
"Recording started");
379 mRestartable =
false;
402 double maxamplitude = 0;
403 for (
auto &y : packet)
if (fabs(y)>maxamplitude) maxamplitude = fabs(y);
404 double trigger = std::min(0.2,maxamplitude*maxamplitude/100);
407 int sections = packet.size() / w;
408 if (sections < 2)
return;
409 size_t entries_to_delete = 0;
410 for (
int sec = 0; sec < sections; ++sec)
413 for (
int i = sec*w; i < (sec+1)*w; ++i) energy += packet[i] * packet[i];
414 if (energy / w < trigger) entries_to_delete += w;
418 EptAssert(entries_to_delete <= packet.size(),
"inconsistent numbers of elements");
419 if (entries_to_delete > 0)
420 packet.erase(packet.begin(), packet.begin() + entries_to_delete);
AudioRecorderAdapter()
Constructor.
std::vector< PCMDataType > PacketType
Type definition of a PCM packet (vector of PCM values).
double mSlidingLevel
Sliding VU level of the signal.
static const double ATTACKRATE
Attack rate at which the sliding level goes up (1=instantly).
std::vector< data_type > getOrderedData() const
Copy entire data in a time-ordered form.
double convertIntensityToLevel(double intensity)
Convert an intensity (variance) of the signal to a VU level.
void setMuted(bool muted)
Set and reset the muting flag.
void pushRawData(const AudioBase::PacketType &data)
Stroboscope::pushRawData.
CircularBuffer< PCMDataType > mCurrentPacket
Local audio buffer.
bool mMuted
Is the input device muted.
static const double LEVEL_TRIGGER
Level above which the recorder starts to operate.
void pushRawData(const PacketType &data)
The implementation calls this function when new data is available.
void controlRecordingState(double level)
Control the beginning and the end of recording.
static const int BUFFER_SIZE_IN_SECONDS
Capacity of the local circular audio buffer in seconds.
std::mutex mCurrentPacketMutex
Buffer access mutexbo.
static void send(Args &&...args)
short function for creating and sending a message
The input level changed (actual signal)
Stroboscope mStroboscope
Instance of stroboscope.
bool mStandby
Standby flag.
bool mRecording
Flag true if recording is on.
virtual void setDeviceInputGain(double volume)=0
bool mWaiting
Wait for the data analysis to be completed.
int mCounterThreshold
Counter threshold for updating energy.
double convertLevelToIntensity(double level)
Convert a VU level to the corresponding intensity. This function is the inverse of convertIntensityTo...
std::map< int, double > mIntensityHistogram
Histogram of intensities.
int mPacketCounter
Counter for the number of packages.
static const int UPDATE_IN_MILLISECONDS
Update interval in milliseconds, defining the packet size.
void readAll(PacketType &packet)
Read all data from the internal buffer.
void resetInputLevelControl()
Reset input level control.
double mStopLevel
Level at which recording stops.
double mGain
Recording amplification factor.
int getSamplingRate() const
Get the actual sampling rate.
void resize(std::size_t maximum_size)
Resize the buffer, shrink oldest data if necessary.
static const double LEVEL_CUTOFF
Level above which the input mGain is automatically reduced.
void push_back(const data_type &data)
Append a new data element to the buffer.
void setSamplingRate(int rate) override
void automaticControl(double intensity, double level)
Automatic noise estimation and threshold adjustment.
static const double DB_OFF
dB shift for off mark (high value = shorter recording)
double mPacketM2
Second intensity moment of a single packet.
static const double LEVEL_RETRIGGER
Level below which retriggering (restart) is allowed.
double mPacketM1
First intensity moment of a single packet.
virtual double getDeviceInputGain() const =0
bool mRestartable
Flag true if start/retriggering possible.
int mCounter
Counts counting incoming PCM values.
virtual void setSamplingRate(int rate)
Allow the implementation to change the sampling rate during operation.
void cutSilence(PacketType &packet)
Cut trailing silence.
void clear()
Clear the buffer, keeping its maximal size.
keystroke recognized and recording started
static const double DECAYRATE
Decay rate at which the sliding level goes down.