arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AudioInputMonitor Class Reference

Monitors audio input and reports if the volume exceeds a specified limit within a given period. More...

#include <AudioStreams.h>

Inheritance diagram for AudioInputMonitor:
ModifyingStream AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 AudioInputMonitor (AudioOutput &ao, uint8_t limitPercent=20)
 Construct a new AudioInputMonitor with an output.
 
 AudioInputMonitor (AudioStream &as, uint8_t limitPercent=20)
 Construct a new AudioInputMonitor with an input stream.
 
 AudioInputMonitor (Print &print, uint8_t limitPercent=20)
 Construct a new AudioInputMonitor with a Print output.
 
 AudioInputMonitor (Stream &stream, uint8_t limitPercent=20)
 Construct a new AudioInputMonitor with a Stream input.
 
 AudioInputMonitor (uint8_t limitPercent=20)
 Construct a new AudioInputMonitor with a volume limit in percent.
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int available () override
 
virtual int availableForWrite () override
 
bool begin () override
 Begin processing with the current audio information.
 
bool begin (AudioInfo info)
 Begin processing with the given audio information.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
virtual void flush () override
 
VolumeMetergetVolumeMeter ()
 Access the underlying VolumeMeter.
 
bool isActive (uint16_t time_ms=1000)
 Returns true if the volume exceeded the limit during the last period.
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
uint8_t limitPercent () const
 Get the current volume threshold as percent.
 
virtual operator bool ()
 
size_t readBytes (uint8_t *data, size_t len) override
 Read audio data from the monitor (same as VolumeMeter)
 
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void setAudioInfo (AudioInfo info) override
 Set the audio information.
 
void setLimitPercent (uint8_t percent)
 Set the volume threshold as percent.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setOutput (AudioOutput &out)
 Set the output target.
 
void setOutput (Print &out) override
 Set the output target.
 
void setStream (AudioStream &io)
 Set the input stream.
 
void setStream (Stream &io) override
 Set the input stream.
 
void setWriteBufferSize (int size)
 
size_t write (const uint8_t *data, size_t len) override
 Write audio data to the monitor (same as VolumeMeter)
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
AudioInfo info
 
bool is_notify_active = true
 
uint8_t limit_percent = 20
 Threshold percent.
 
Vector< AudioInfoSupport * > notify_vector
 
uint64_t time_over_last_volume_limit = 0
 Last over-limit time (ms)
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 
VolumeMeter volume_meter
 Volume calculation.
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

Monitors audio input and reports if the volume exceeds a specified limit within a given period.

This class uses a VolumeMeter internally and tracks if the input volume has exceeded the specified limit during the last period. It can be used in an audio processing chain as a ModifyingStream.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ AudioInputMonitor() [1/5]

AudioInputMonitor ( uint8_t  limitPercent = 20)
inline

Construct a new AudioInputMonitor with a volume limit in percent.

Parameters
limitPercentThe volume threshold as percent (default: 20)

◆ AudioInputMonitor() [2/5]

AudioInputMonitor ( AudioStream as,
uint8_t  limitPercent = 20 
)
inline

Construct a new AudioInputMonitor with an input stream.

Parameters
asReference to an AudioStream
limitPercentThe volume threshold as percent (default: 20)

◆ AudioInputMonitor() [3/5]

AudioInputMonitor ( AudioOutput ao,
uint8_t  limitPercent = 20 
)
inline

Construct a new AudioInputMonitor with an output.

Parameters
aoReference to an AudioOutput
limitPercentThe volume threshold as percent (default: 20)

◆ AudioInputMonitor() [4/5]

AudioInputMonitor ( Print print,
uint8_t  limitPercent = 20 
)
inline

Construct a new AudioInputMonitor with a Print output.

Parameters
printReference to a Print object
limitPercentThe volume threshold as percent (default: 20)

◆ AudioInputMonitor() [5/5]

AudioInputMonitor ( Stream stream,
uint8_t  limitPercent = 20 
)
inline

Construct a new AudioInputMonitor with a Stream input.

Parameters
streamReference to a Stream object
limitPercentThe volume threshold as percent (default: 20)

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

virtual int available ( )
inlineoverridevirtualinherited

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

Begin processing with the current audio information.

Returns
true if successful

Reimplemented from BaseStream.

◆ begin() [2/2]

bool begin ( AudioInfo  info)
inline

Begin processing with the given audio information.

Parameters
infoAudioInfo structure
Returns
true if successful

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

Reimplemented from Print.

Reimplemented in ResampleStream, BufferedTaskStream, and BufferedStream.

◆ getVolumeMeter()

VolumeMeter & getVolumeMeter ( )
inline

Access the underlying VolumeMeter.

Returns
Reference to the internal VolumeMeter

◆ isActive()

bool isActive ( uint16_t  time_ms = 1000)
inline

Returns true if the volume exceeded the limit during the last period.

Parameters
time_msThe period in milliseconds to check (default: 1000)
Returns
true if the volume exceeded the limit during the period

◆ limitPercent()

uint8_t limitPercent ( ) const
inline

Get the current volume threshold as percent.

Returns
The current volume threshold (0-100)

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ readBytes()

size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Read audio data from the monitor (same as VolumeMeter)

Parameters
dataPointer to buffer to fill
lenNumber of bytes to read
Returns
Number of bytes read

Reimplemented from AudioStream.

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverridevirtual

Set the audio information.

Parameters
infoAudioInfo structure

Reimplemented from AudioStream.

◆ setLimitPercent()

void setLimitPercent ( uint8_t  percent)
inline

Set the volume threshold as percent.

Parameters
percentThe new volume threshold (0-100)

◆ setOutput() [1/2]

void setOutput ( AudioOutput out)
inline

Set the output target.

Parameters
outReference to a Print object

◆ setOutput() [2/2]

void setOutput ( Print out)
inlineoverridevirtual

Set the output target.

Parameters
outReference to a Print object

Implements ModifyingStream.

◆ setStream() [1/2]

void setStream ( AudioStream io)
inline

Set the input stream.

Parameters
ioReference to a Stream object

◆ setStream() [2/2]

void setStream ( Stream io)
inlineoverridevirtual

Set the input stream.

Parameters
ioReference to a Stream object

Implements ModifyingStream.

◆ write() [1/2]

size_t write ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Write audio data to the monitor (same as VolumeMeter)

Parameters
dataPointer to audio data
lenNumber of bytes
Returns
Number of bytes written

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

Reimplemented in BufferedTaskStream, and BufferedStream.


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