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

A simple class to determine the volume. You can use it as final output or as output or input in your audio chain. More...

#include <AudioStreams.h>

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

Public Member Functions

 VolumeMeter ()=default
 
 VolumeMeter (AudioOutput &ao)
 
 VolumeMeter (AudioStream &as)
 
 VolumeMeter (Print &print)
 
 VolumeMeter (Stream &stream)
 
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
 
bool begin (AudioInfo info)
 
void clear ()
 Resets the actual volume.
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
virtual void end ()
 
virtual void flush () override
 
bool isActive () const
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
size_t readBytes (uint8_t *data, size_t len) override
 
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 setActivityCallback (ActivityCallback callback, float threshold=0.2, unsigned long duration_ms=2000)
 
void setAudioInfo (AudioInfo info) override
 Defines the input AudioInfo.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setOutput (AudioOutput &out)
 
void setOutput (Print &out) override
 Defines/Changes the output target.
 
void setStream (AudioStream &io)
 
void setStream (Stream &io) override
 Defines/Changes the input & output.
 
void setWriteBufferSize (int size)
 
float volume ()
 
float volume (int channel)
 
float volumeAvg ()
 Average volume of all channels.
 
float volumeAvg (int channel)
 Average volume of indicated channel.
 
float volumeDB ()
 Volume in db: max amplitude is 0 (range: -1000 to 0)
 
float volumeDB (int channel)
 Volume of indicated channel in db: max amplitude is 0.
 
float volumePercent ()
 Volume in %: max amplitude is 100.
 
float volumePercent (int channel)
 Volume of indicated channel in %: max amplitude is 100.
 
float volumeRatio ()
 Volume Ratio: max amplitude is 1.0.
 
float volumeRatio (int channel)
 Volume Ratio of indicated channel: max amplitude is 1.0.
 
size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

void commit ()
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 
void updateActivityState ()
 
void updateVolume (float tmp, int j)
 
void updateVolumes (const uint8_t *data, size_t len)
 
template<typename T >
void updateVolumesT (const uint8_t *buffer, size_t size)
 

Protected Attributes

int _timeout = 10
 
ActivityCallback activity_callback = nullptr
 
unsigned long activity_duration_ms = 0
 
bool activity_monitoring_enabled = false
 
float activity_threshold = 0.0f
 
float f_volume = 0
 
float f_volume_tmp = 0
 
unsigned long inactive_start_time = 0
 
AudioInfo info
 
bool is_active = false
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
Printp_out = nullptr
 
Streamp_stream = nullptr
 
size_t sample_count_per_channel = 0
 
Vector< floatsum {0}
 
Vector< floatsum_tmp {0}
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
Vector< floatvolumes {0}
 
Vector< floatvolumes_tmp {0}
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

A simple class to determine the volume. You can use it as final output or as output or input in your audio chain.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ VolumeMeter() [1/5]

VolumeMeter ( )
default

◆ VolumeMeter() [2/5]

VolumeMeter ( AudioStream as)
inline

◆ VolumeMeter() [3/5]

VolumeMeter ( AudioOutput ao)
inline

◆ VolumeMeter() [4/5]

VolumeMeter ( Print print)
inline

◆ VolumeMeter() [5/5]

VolumeMeter ( Stream stream)
inline

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

Reimplemented from BaseStream.

◆ begin() [2/2]

bool begin ( AudioInfo  info)
inline

◆ clear()

void clear ( )
inline

Resets the actual volume.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ commit()

void commit ( )
inlineprotected

◆ end()

virtual void end ( )
inlinevirtualinherited

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ isActive()

bool isActive ( ) const
inline

Get current activity state

Returns
true if active (volume above threshold), false if inactive

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ not_supported()

virtual int not_supported ( int  out,
const char msg = "" 
)
inlineprotectedvirtualinherited

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

◆ readBytes()

size_t readBytes ( uint8_t data,
size_t  len 
)
inlineoverridevirtual

Reimplemented from AudioStream.

◆ readSilence()

virtual size_t readSilence ( uint8_t buffer,
size_t  length 
)
inlinevirtualinherited

Source to generate silence: just sets the buffer to 0.

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

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

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ setActivityCallback()

void setActivityCallback ( ActivityCallback  callback,
float  threshold = 0.2,
unsigned long  duration_ms = 2000 
)
inline

Set activity monitoring callback and configure threshold

Parameters
callbackFunction to call when activity state changes (nullptr to disable)
thresholdVolume threshold (0.0 to 1.0) - activity detected when volume exceeds this
duration_msTime in milliseconds volume must be below threshold to be considered inactive

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverridevirtual

Defines the input AudioInfo.

Reimplemented from AudioStream.

◆ setNotifyActive()

void setNotifyActive ( bool  flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active)

◆ setOutput() [1/2]

void setOutput ( AudioOutput out)
inline

◆ setOutput() [2/2]

void setOutput ( Print out)
inlineoverridevirtual

Defines/Changes the output target.

Implements ModifyingStream.

◆ setStream() [1/2]

void setStream ( AudioStream io)
inline

◆ setStream() [2/2]

void setStream ( Stream in)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ updateActivityState()

void updateActivityState ( )
inlineprotected

◆ updateVolume()

void updateVolume ( float  tmp,
int  j 
)
inlineprotected

◆ updateVolumes()

void updateVolumes ( const uint8_t data,
size_t  len 
)
inlineprotected

◆ updateVolumesT()

template<typename T >
void updateVolumesT ( const uint8_t buffer,
size_t  size 
)
inlineprotected

◆ volume() [1/2]

float volume ( )
inline

Determines the volume (max amplitude). The range depends on the bits_per_sample.

◆ volume() [2/2]

float volume ( int  channel)
inline

Determines the volume for the indicated channel. You must call the begin method to define the number of channels

◆ volumeAvg() [1/2]

float volumeAvg ( )
inline

Average volume of all channels.

◆ volumeAvg() [2/2]

float volumeAvg ( int  channel)
inline

Average volume of indicated channel.

◆ volumeDB() [1/2]

float volumeDB ( )
inline

Volume in db: max amplitude is 0 (range: -1000 to 0)

◆ volumeDB() [2/2]

float volumeDB ( int  channel)
inline

Volume of indicated channel in db: max amplitude is 0.

◆ volumePercent() [1/2]

float volumePercent ( )
inline

Volume in %: max amplitude is 100.

◆ volumePercent() [2/2]

float volumePercent ( int  channel)
inline

Volume of indicated channel in %: max amplitude is 100.

◆ volumeRatio() [1/2]

float volumeRatio ( )
inline

Volume Ratio: max amplitude is 1.0.

◆ volumeRatio() [2/2]

float volumeRatio ( int  channel)
inline

Volume Ratio of indicated channel: max amplitude is 1.0.

◆ write() [1/2]

size_t write ( const uint8_t data,
size_t  len 
)
inlineoverridevirtual

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

◆ writeSilence()

virtual void writeSilence ( size_t  len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ activity_callback

ActivityCallback activity_callback = nullptr
protected

◆ activity_duration_ms

unsigned long activity_duration_ms = 0
protected

◆ activity_monitoring_enabled

bool activity_monitoring_enabled = false
protected

◆ activity_threshold

float activity_threshold = 0.0f
protected

◆ f_volume

float f_volume = 0
protected

◆ f_volume_tmp

float f_volume_tmp = 0
protected

◆ inactive_start_time

unsigned long inactive_start_time = 0
protected

◆ info

AudioInfo info
protectedinherited

◆ is_active

bool is_active = false
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_out

Print* p_out = nullptr
protected

◆ p_stream

Stream* p_stream = nullptr
protected

◆ sample_count_per_channel

size_t sample_count_per_channel = 0
protected

◆ sum

Vector<float> sum {0}
protected

◆ sum_tmp

Vector<float> sum_tmp {0}
protected

◆ tmp_in

RingBuffer<uint8_t> tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer<uint8_t> tmp_out {0}
protectedinherited

◆ volumes

Vector<float> volumes {0}
protected

◆ volumes_tmp

Vector<float> volumes_tmp {0}
protected

◆ write_buffer_size

int write_buffer_size = MAX_SINGLE_CHARS
protectedinherited

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