arduino-audio-tools
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. More...
 
 AudioPlayer (AudioSource &source, AudioStream &output, AudioDecoder &decoder)
 Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print. More...
 
 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. More...
 
void addNotifyAudioChange (AudioInfoSupport *notify)
 (Re)defines the notify
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
 
virtual bool begin (int index=0, bool isActive=true)
 (Re)Starts the playing of the music (from the beginning)
 
virtual size_t copy ()
 Call this method in the loop.
 
virtual void end ()
 
virtual StreamgetStream ()
 Provides the actual stream (=e.g.file)
 
StreamCopygetStreamCopy ()
 
PrintgetVolumeOutput ()
 Provides the Print object to which we send the decoding result.
 
virtual bool isActive ()
 determines if the player is active
 
bool isAutoFade ()
 
bool isSilenceOnInactive ()
 Checks if silence_on_inactive has been activated (default false)
 
virtual bool next (int offset=1)
 
 operator bool ()
 determines if the player is active
 
AudioPlayeroperator= (AudioPlayer const &)=delete
 
virtual void play ()
 starts / resumes the playing after calling stop()
 
virtual bool previous (int offset=1)
 moves to previous file
 
virtual void setActive (bool isActive)
 The same like start() / stop()
 
virtual 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)
 
virtual void setAutoNext (bool next)
 
virtual void setBufferSize (int size)
 Defines the number of bytes used by the copier.
 
void setDecoder (AudioDecoder &decoder)
 (Re)defines the decoder
 
virtual void setDelayIfOutputFull (int delayMs)
 Defines the wait time in ms if the target output is full.
 
virtual bool setIndex (int idx)
 moves to selected file
 
virtual void setMetadataCallback (void(*callback)(MetaDataType type, const char *str, int len), ID3TypeSelection sel=SELECT_ID3)
 Defines the medatadata callback.
 
void setOutput (AudioOutput &output)
 
void setOutput (AudioStream &output)
 
void setOutput (Print &output)
 
virtual bool setPath (const char *path)
 moves to selected file
 
void setSilenceOnInactive (bool active)
 
virtual 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
 
virtual void setVolumeControl (VolumeControl &vc)
 Change the VolumeControl implementation.
 
virtual void stop ()
 halts the playing
 
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

virtual 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

◆ getStreamCopy()

StreamCopy& getStreamCopy ( )
inline

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

◆ next()

virtual bool next ( int  offset = 1)
inlinevirtual

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

◆ setAutoFade()

void setAutoFade ( bool  active)
inline

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

◆ setAutoNext()

virtual void setAutoNext ( bool  next)
inlinevirtual

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


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