arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
AudioPlayer Class Reference

Implements a simple audio player which supports the following commands: More...

#include <AudioPlayer.h>

Inheritance diagram for AudioPlayer:
AudioInfoSupport VolumeSupport

Public Member Functions

 AudioPlayer ()
 Default constructor.
 
 AudioPlayer (AudioPlayer const &)=delete
 
 AudioPlayer (AudioSource &source, AudioOutput &output, AudioDecoder &decoder)
 Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.
 
 AudioPlayer (AudioSource &source, AudioStream &output, AudioDecoder &decoder)
 Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.
 
 AudioPlayer (AudioSource &source, Print &output, AudioDecoder &decoder, AudioInfoSupport *notify=nullptr)
 Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.
 
void addNotifyAudioChange (AudioInfoSupport *notify)
 (Re)defines the notify
 
AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
bool begin (int index=0, bool isActive=true)
 (Re)Starts the playing of the music (from the beginning or the indicated index)
 
size_t copy ()
 Copies DEFAULT_BUFFER_SIZE (=1024 bytes) from the source to the decoder: Call this method in the loop.
 
size_t copy (size_t bytes)
 Copies the indicated number of bytes from the source to the decoder: Call this method in the loop.
 
void end ()
 
StreamgetStream ()
 Provides the actual stream (=e.g.file)
 
StreamCopygetStreamCopy ()
 
VolumeStreamgetVolumeStream ()
 Provides the reference to the volume stream.
 
bool isActive ()
 determines if the player is active
 
bool isAutoFade ()
 
bool isSilenceOnInactive ()
 Checks if silence_on_inactive has been activated (default false)
 
bool next (int offset=1)
 
 operator bool ()
 determines if the player is active
 
AudioPlayeroperator= (AudioPlayer const &)=delete
 
void play ()
 starts / resumes the playing after calling stop(): same as setActive(true)
 
bool previous (int offset=1)
 moves to previous file
 
void setActive (bool isActive)
 The same like start() / stop()
 
void setAudioInfo (AudioInfo info) override
 Updates the audio info in the related objects.
 
void setAudioSource (AudioSource &source)
 (Re)defines the audio source
 
void setAutoFade (bool active)
 
void setAutoNext (bool next)
 
void setBufferSize (int size)
 Defines the number of bytes used by the copier.
 
void setDecoder (AudioDecoder &decoder)
 (Re)defines the decoder
 
void setDelayIfOutputFull (int delayMs)
 Defines the wait time in ms if the target output is full.
 
bool setIndex (int idx)
 moves to the selected file position
 
void setMetadataCallback (void(*callback)(MetaDataType type, const char *str, int len), ID3TypeSelection sel=SELECT_ID3)
 Defines the medatadata callback.
 
void setMetaDataSize (int size)
 Change the default ID3 max metadata size (256)
 
void setOutput (AudioOutput &output)
 
void setOutput (AudioStream &output)
 
void setOutput (Print &output)
 
bool setPath (const char *path)
 Moves to the selected file w/o updating the actual file position.
 
void setSilenceOnInactive (bool active)
 
bool setStream (Stream *input)
 start selected input stream
 
bool setVolume (float volume) override
 sets the volume - values need to be between 0.0 and 1.0
 
void setVolumeControl (VolumeControl &vc)
 Change the VolumeControl implementation.
 
void stop ()
 halts the playing: same as setActive(false)
 
float volume () override
 Determines the actual volume.
 
void writeSilence (size_t bytes)
 Sends the requested bytes as 0 values to the output.
 

Protected Member Functions

void moveToNextFileOnTimeout ()
 
void setupFade ()
 
void writeEnd ()
 

Static Protected Member Functions

static void decodeMetaData (void *obj, void *data, size_t len)
 Callback implementation which writes to metadata.
 

Protected Attributes

bool active = false
 
bool autonext = true
 
StreamCopy copier
 
float current_volume = -1.0f
 
int delay_if_full = 100
 
FadeStream fade
 
AudioInfo info
 
bool is_auto_fade = true
 
bool meta_active = false
 
MetaDataID3 meta_out
 
CopyDecoder no_decoder {true}
 
EncodedAudioOutput out_decoding
 
AudioDecoderp_decoder = &no_decoder
 
AudioInfoSupportp_final_notify = nullptr
 
AudioOutputp_final_print = nullptr
 
AudioStreamp_final_stream = nullptr
 
Streamp_input_stream = nullptr
 
AudioSourcep_source = nullptr
 
bool silence_on_inactive = false
 
int stream_increment = 1
 
uint32_t timeout = 0
 
VolumeStream volume_out
 
float volume_value = 1.0f
 

Detailed Description

Implements a simple audio player which supports the following commands:

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ AudioPlayer() [1/3]

AudioPlayer ( AudioSource source,
AudioOutput output,
AudioDecoder decoder 
)
inline

Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.

Parameters
source
output
decoder

◆ AudioPlayer() [2/3]

AudioPlayer ( AudioSource source,
Print output,
AudioDecoder decoder,
AudioInfoSupport notify = nullptr 
)
inline

Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.

Parameters
source
output
decoder
notify

◆ AudioPlayer() [3/3]

AudioPlayer ( AudioSource source,
AudioStream output,
AudioDecoder decoder 
)
inline

Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.

Parameters
source
output
decoder

Member Function Documentation

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtual

provides the actual input AudioInfo

Implements AudioInfoSupport.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ getStreamCopy()

StreamCopy & getStreamCopy ( )
inline

Provides access to the StreamCopy, so that we can register additinal callbacks

◆ next()

bool next ( int  offset = 1)
inline

moves to next file or nth next file when indicating an offset. Negative values are supported to move back.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  info)
inlineoverridevirtual

Updates the audio info in the related objects.

Implements AudioInfoSupport.

◆ setAutoFade()

void setAutoFade ( bool  active)
inline

Activates/deactivates the automatic fade in and fade out to prevent popping sounds: default is active

◆ setAutoNext()

void setAutoNext ( bool  next)
inline

Set automatically move to next file and end of current file: This is determined from the AudioSource. If you want to override it call this method after calling begin()!

◆ setSilenceOnInactive()

void setSilenceOnInactive ( bool  active)
inline

If set to true the player writes 0 values instead of no data if the player is inactive

◆ setVolume()

bool setVolume ( float  volume)
inlineoverridevirtual

sets the volume - values need to be between 0.0 and 1.0

Reimplemented from VolumeSupport.

◆ volume()

float volume ( )
inlineoverridevirtual

Determines the actual volume.

Reimplemented from VolumeSupport.


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