arduino-audio-tools
Loading...
Searching...
No Matches

Adjust the volume of the related input or output: To work properly the class needs to know the bits per sample and number of channels! AudioChanges are forwareded to the related Print or Stream class. More...

#include <VolumeStream.h>

Inheritance diagram for VolumeStream:
ModifyingStream VolumeSupport AudioStream AudioStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream AudioInfoSource AudioInfoSupport BaseStream

Public Member Functions

 VolumeStream ()=default
 Default Constructor.
 VolumeStream (AudioOutput &out)
 Constructor which assigns Print output.
 VolumeStream (AudioStream &io)
 Constructor which assigns Stream input or output.
 VolumeStream (Print &out)
 Constructor which assigns Print output.
 VolumeStream (Stream &in)
 Constructor which assigns Stream input or output.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
virtual int available () override
 Provides the nubmer of bytes we can write.
virtual int availableForWrite () override
 Provides the nubmer of bytes we can write.
bool begin () override
bool begin (AudioInfo cfg)
bool begin (VolumeStreamConfig cfg)
 starts the processing
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
VolumeStreamConfig defaultConfig ()
void end () override
virtual void flush () override
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
virtual operator bool ()
virtual operator bool ()
virtual size_t readBytes (uint8_t *data, size_t len) override
 Read raw PCM audio data, which will be the input for the volume control.
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
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.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
void resetVolumeControl ()
 Resets the volume control to use the standard logic.
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
void setAudioInfo (AudioInfo cfg) override
 Detines the Audio info - The bits_per_sample are critical to work properly!
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
virtual void setOutput (AudioOutput &out)
 Defines/Changes the output target and registers for audio change notifications.
void setOutput (Print &out) override
 Defines/Changes the output target.
void setOutput (Stream &in)
 same as setStream
virtual void setStream (AudioStream &io)
 Defines/Changes the input & output and registers for audio change notifications.
void setStream (Print &out)
 same as set Output
void setStream (Stream &in) override
 Defines/Changes the input & output.
bool setVolume (float vol) override
 Defines the volume for all channels: needs to be in the range of 0 to 1.0 (if allow boost has not been set).
bool setVolume (float vol, int channel)
 Sets the volume for one channel.
void setVolumeControl (VolumeControl &vc)
 Defines the volume control logic.
void setWriteBufferSize (int size)
void setWriteBufferSize (int size)
float volume () override
 Provides the current (avg) volume accross all channels.
float volume (int channel)
 Provides the current volume setting for the indicated channel.
virtual size_t write (uint8_t ch) override
virtual size_t write (const uint8_t *data, size_t len) override
 Writes raw PCM audio data, which will be the input for the volume control.
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).

Protected Member Functions

void applyVolume (const uint8_t *buffer, size_t size)
void applyVolume16 (int16_t *data, size_t size)
void applyVolume24 (int24_t *data, size_t size)
void applyVolume32 (int32_t *data, size_t size)
float factorForChannel (int channel)
bool isAllChannelsFullVolume ()
bool isVolumeUpdate ()
virtual int not_supported (int out, const char *msg="")
virtual int not_supported (int out, const char *msg="")
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().
void resizeVectors (int channels)
 Resizes the vectors.
void setVolumeStreamConfig (VolumeStreamConfig cfg)
 Stores the local variable and calculates some max values.
VolumeStreamConfig toVolumeStreamConfig (AudioInfo cfg)
 Provides a VolumeStreamConfig based on a AudioInfo.
VolumeControl & volumeControl ()
float volumeValue (float vol)

Protected Attributes

int _timeout = 10
CachedVolumeControl cached_volume {pot_vc}
Vector< float > factor_for_channel
VolumeStreamConfig info
bool is_notify_active = true
bool is_started = false
LinearVolumeControl linear_vc {true}
float max_value = 32767
Vector< AudioInfoSupport * > notify_vector
Stream * p_in =nullptr
Print * p_out =nullptr
SimulatedAudioPot pot_vc
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
float volume_value = 1.0f
Vector< float > volume_values
int write_buffer_size = 8

Detailed Description

Adjust the volume of the related input or output: To work properly the class needs to know the bits per sample and number of channels! AudioChanges are forwareded to the related Print or Stream class.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ VolumeStream() [1/5]

VolumeStream ( )
default

Default Constructor.

◆ VolumeStream() [2/5]

VolumeStream ( Print & out)
inline

Constructor which assigns Print output.

◆ VolumeStream() [3/5]

VolumeStream ( Stream & in)
inline

Constructor which assigns Stream input or output.

◆ VolumeStream() [4/5]

VolumeStream ( AudioOutput & out)
inline

Constructor which assigns Print output.

◆ VolumeStream() [5/5]

VolumeStream ( AudioStream & io)
inline

Constructor which assigns Stream input or output.

Member Function Documentation

◆ addNotifyAudioChange() [1/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ addNotifyAudioChange() [2/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ applyVolume()

void applyVolume ( const uint8_t * buffer,
size_t size )
inlineprotected

◆ applyVolume16()

void applyVolume16 ( int16_t * data,
size_t size )
inlineprotected

◆ applyVolume24()

void applyVolume24 ( int24_t * data,
size_t size )
inlineprotected

◆ applyVolume32()

void applyVolume32 ( int32_t * data,
size_t size )
inlineprotected

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ available()

virtual int available ( )
inlineoverridevirtual

Provides the nubmer of bytes we can write.

Reimplemented from BaseStream.

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtual

Provides the nubmer of bytes we can write.

Reimplemented from BaseStream.

◆ begin() [1/3]

bool begin ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ begin() [2/3]

bool begin ( AudioInfo cfg)
inline

◆ begin() [3/3]

bool begin ( VolumeStreamConfig cfg)
inline

starts the processing

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ defaultConfig()

VolumeStreamConfig defaultConfig ( )
inline

◆ end()

void end ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ factorForChannel()

float factorForChannel ( int channel)
inlineprotected

◆ flush()

virtual void flush ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ isAllChannelsFullVolume()

bool isAllChannelsFullVolume ( )
inlineprotected

◆ isNotifyActive() [1/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isNotifyActive() [2/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isVolumeUpdate()

bool isVolumeUpdate ( )
inlineprotected

◆ not_supported() [1/2]

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

◆ not_supported() [2/2]

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

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool() [1/2]

◆ operator bool() [2/2]

◆ readBytes()

virtual size_t readBytes ( uint8_t * data,
size_t len )
inlineoverridevirtual

Read raw PCM audio data, which will be the input for the volume control.

Reimplemented from AudioStream.

◆ readSilence() [1/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

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

◆ readSilence() [2/2]

virtual size_t readSilence ( uint8_t * buffer,
size_t length )
inlinevirtualinherited

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

◆ refillReadBuffer() [1/2]

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

◆ refillReadBuffer() [2/2]

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read().

◆ removeNotifyAudioChange() [1/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

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

◆ removeNotifyAudioChange() [2/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

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

◆ resetVolumeControl()

void resetVolumeControl ( )
inline

Resets the volume control to use the standard logic.

◆ resizeVectors()

void resizeVectors ( int channels)
inlineprotected

Resizes the vectors.

◆ setAudioInfo() [1/2]

◆ setAudioInfo() [2/2]

void setAudioInfo ( AudioInfo cfg)
inlineoverride

Detines the Audio info - The bits_per_sample are critical to work properly!

◆ setNotifyActive() [1/2]

void setNotifyActive ( bool flag)
inlineinherited

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

◆ setNotifyActive() [2/2]

void setNotifyActive ( bool flag)
inlineinherited

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

◆ setOutput() [1/3]

virtual void setOutput ( AudioOutput & out)
inlinevirtualinherited

Defines/Changes the output target and registers for audio change notifications.

Reimplemented in AudioInputMonitor, AudioInputMonitor, EncodedAudioStream, ReformatBaseStream, TimedStream, VolumeMeter, and VolumeMeter.

◆ setOutput() [2/3]

void setOutput ( Print & out)
inlineoverridevirtual

Defines/Changes the output target.

Implements ModifyingStream.

◆ setOutput() [3/3]

void setOutput ( Stream & in)
inline

same as setStream

◆ setStream() [1/3]

virtual void setStream ( AudioStream & io)
inlinevirtualinherited

Defines/Changes the input & output and registers for audio change notifications.

Reimplemented in AudioInputMonitor, AudioInputMonitor, EncodedAudioStream, ReformatBaseStream, TimedStream, VolumeMeter, and VolumeMeter.

◆ setStream() [2/3]

void setStream ( Print & out)
inline

same as set Output

◆ setStream() [3/3]

void setStream ( Stream & in)
inlineoverridevirtual

Defines/Changes the input & output.

Implements ModifyingStream.

◆ setVolume() [1/2]

bool setVolume ( float vol)
inlineoverridevirtual

Defines the volume for all channels: needs to be in the range of 0 to 1.0 (if allow boost has not been set).

Reimplemented from VolumeSupport.

◆ setVolume() [2/2]

bool setVolume ( float vol,
int channel )
inline

Sets the volume for one channel.

◆ setVolumeControl()

void setVolumeControl ( VolumeControl & vc)
inline

Defines the volume control logic.

◆ setVolumeStreamConfig()

void setVolumeStreamConfig ( VolumeStreamConfig cfg)
inlineprotected

Stores the local variable and calculates some max values.

◆ setWriteBufferSize() [1/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ setWriteBufferSize() [2/2]

void setWriteBufferSize ( int size)
inlineinherited

◆ toVolumeStreamConfig()

VolumeStreamConfig toVolumeStreamConfig ( AudioInfo cfg)
inlineprotected

Provides a VolumeStreamConfig based on a AudioInfo.

◆ volume() [1/2]

float volume ( )
inlineoverridevirtual

Provides the current (avg) volume accross all channels.

Reimplemented from VolumeSupport.

◆ volume() [2/2]

float volume ( int channel)
inline

Provides the current volume setting for the indicated channel.

◆ volumeControl()

VolumeControl & volumeControl ( )
inlineprotected

◆ volumeValue()

float volumeValue ( float vol)
inlineprotected

◆ write() [1/2]

◆ write() [2/2]

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

Writes raw PCM audio data, which will be the input for the volume control.

Reimplemented from AudioStream.

◆ writeSilence() [1/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

◆ writeSilence() [2/2]

virtual void writeSilence ( size_t len)
inlinevirtualinherited

Writes len bytes of silence (=0).

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ cached_volume

CachedVolumeControl cached_volume {pot_vc}
protected

◆ factor_for_channel

Vector<float> factor_for_channel
protected

◆ info

VolumeStreamConfig info
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ is_started

bool is_started = false
protected

◆ linear_vc

LinearVolumeControl linear_vc {true}
protected

◆ max_value

float max_value = 32767
protected

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ p_in

Stream* p_in =nullptr
protected

◆ p_out

Print* p_out =nullptr
protected

◆ pot_vc

SimulatedAudioPot pot_vc
protected

◆ tmp_in

RingBuffer< uint8_t > tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer< uint8_t > tmp_out {0}
protectedinherited

◆ volume_value

float volume_value = 1.0f
protectedinherited

◆ volume_values

Vector<float> volume_values
protected

◆ write_buffer_size

int write_buffer_size = 8
protectedinherited

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