|
arduino-audio-tools
|
High-level audio playback pipeline and controller. More...
#include <AudioPlayer.h>
Public Member Functions | |
| AudioPlayer () | |
| Default constructor. | |
| AudioPlayer (AudioPlayer const &)=delete | |
| Non-copyable: copy constructor is deleted. | |
| 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) |
| Adds/updates a listener notified on audio info changes. | |
| AudioInfo | audioInfo () override |
| Returns the current AudioInfo of the playback chain. | |
| virtual AudioInfo | audioInfoOut () |
| AudioSource & | audioSource () |
| Returns the active AudioSource. | |
| bool | begin (int index=0, bool isActive=true) |
| Starts or restarts playback from the first or given stream index. | |
| void | clearBuffers (bool drainSource=false) |
| size_t | copy () |
| size_t | copy (size_t bytes) |
| Copies the requested bytes from source to decoder (call in loop) | |
| size_t | copyAll () |
| Copies until source is exhausted (blocking) | |
| void | end () |
| Ends playback and resets decoder/intermediate stages. | |
| Stream * | getStream () |
| Returns the currently active input Stream (e.g., file) | |
| StreamCopy & | getStreamCopy () |
| VolumeStream & | getVolumeStream () |
| Returns the VolumeStream used by the player. | |
| bool | isActive () |
| Checks whether playback is active. | |
| bool | isAutoFade () |
| Checks whether automatic fade in/out is enabled. | |
| bool | isMuted () |
| Returns true if the player is currently muted. | |
| bool | isSilenceOnInactive () |
| Returns whether silence-on-inactive is enabled. | |
| bool | next (int offset=1) |
| Moves to the next/previous stream by offset (negative supported) | |
| operator bool () | |
| Boolean conversion returns isActive() | |
| AudioPlayer & | operator= (AudioPlayer const &)=delete |
| Non-assignable: assignment operator is deleted. | |
| void | play () |
| bool | playFile (const char *path) |
| Obsolete: use PlayPath! | |
| bool | playPath (const char *path) |
| bool | previous (int offset=1) |
| Moves back by offset streams (defaults to 1) | |
| void | setActive (bool isActive) |
| Toggles playback activity; triggers fade and optional silence. | |
| void | setAudioInfo (AudioInfo info) override |
| Receives and forwards updated AudioInfo to the chain. | |
| void | setAudioSource (AudioSource &source) |
| Sets or replaces the AudioSource. | |
| void | setAutoFade (bool active) |
| Enables/disables automatic fade in/out to prevent pops. | |
| void | setAutoNext (bool next) |
| Enables/disables auto-advance at end/timeout (overrides AudioSource) | |
| void | setBufferSize (int size) |
| Sets the internal copy buffer size (bytes) | |
| void | setDecoder (AudioDecoder &decoder) |
| Sets or replaces the AudioDecoder. | |
| void | setDelayIfOutputFull (int delayMs) |
| Sets delay (ms) to wait when output is full. | |
| bool | setIndex (int idx) |
| Selects stream by absolute index in the source. | |
| void | setMetadataCallback (void(*callback)(MetaDataType type, const char *str, int len), ID3TypeSelection sel=SELECT_ID3) |
| Defines the metadata callback. | |
| void | setMetaDataSize (int size) |
| Sets the maximum ID3 metadata buffer size (default 256) | |
| bool | setMuted (bool muted) |
| Mutes or unmutes the audio player. | |
| void | setOnEOFCallback (void(*callback)(AudioPlayer &player)) |
| void | setOnStreamChangeCallback (void(*callback)(Stream *stream_ptr, void *reference)) |
| Defines a callback that is called when the stream is changed. | |
| void | setOutput (AudioOutput &output) |
| Sets the final output to an AudioOutput (adds Volume/Fade for PCM) | |
| void | setOutput (AudioStream &output) |
| Sets the final output to an AudioStream (adds Volume/Fade for PCM) | |
| void | setOutput (Print &output) |
| Sets the final output to a Print (adds Volume/Fade for PCM) | |
| bool | setPath (const char *path) |
| Selects stream by path without changing the source iterator. | |
| void | setReference (void *ref) |
| Sets a user reference passed to the stream-change callback. | |
| void | setSilenceOnInactive (bool active) |
| When enabled, writes zeros while inactive to keep sinks alive. | |
| bool | setStream (Stream *input) |
| Activates the provided Stream as current input. | |
| bool | setVolume (float volume) override |
| Sets volume in range [0.0, 1.0]; updates VolumeStream. | |
| bool | setVolume (float volume, int channel) |
| Defines the volume for the indicated channel. | |
| void | setVolumeControl (VolumeControl &vc) |
| Sets a custom VolumeControl implementation. | |
| void | stop () |
| Halts playback; equivalent to setActive(false) | |
| float | volume () override |
| Returns the current volume [0.0, 1.0]. | |
| float | volume (int channel) |
| Returns the current volume for the indicated channel. | |
| void | writeSilence (size_t bytes) |
| Writes the requested number of zero bytes 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 |
| bool | eof_called = false |
| FadeStream | fade |
| AudioInfo | info |
| bool | is_auto_fade = true |
| bool | meta_active = false |
| MetaDataID3 | meta_out |
| float | muted_volume = 0.0f |
| CopyDecoder | no_decoder {true} |
| void(* | on_eof_callback )(AudioPlayer &player) = nullptr |
| void(* | on_stream_change_callback )(Stream *stream_ptr, void *reference) = nullptr |
| EncodedAudioOutput | out_decoding |
| AudioDecoder * | p_decoder = &no_decoder |
| AudioInfoSupport * | p_final_notify = nullptr |
| AudioOutput * | p_final_print = nullptr |
| AudioStream * | p_final_stream = nullptr |
| Stream * | p_input_stream = nullptr |
| void * | p_reference = nullptr |
| AudioSource * | p_source = nullptr |
| bool | silence_on_inactive = false |
| int | stream_increment = 1 |
| uint32_t | timeout = 0 |
| VolumeStream | volume_out |
| float | volume_value = 1.0f |
High-level audio playback pipeline and controller.
Provides pull-driven playback from an AudioSource through optional decoding, volume control and click-free fades to an AudioOutput/AudioStream/Print.
Features:
Pipeline: AudioSource → StreamCopy → EncodedAudioOutput → VolumeStream → FadeStream → Output.
Operation model: call copy() regularly (non-blocking) or copyAll() for blocking end-to-end playback.
|
inline |
Default constructor.
|
inline |
Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.
| source | |
| output | |
| decoder |
|
inline |
Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.
| source | |
| output | |
| decoder | |
| notify |
|
inline |
Construct a new Audio Player object. The processing chain is AudioSource -> Stream-copy -> EncodedAudioStream -> VolumeStream -> FadeStream -> Print.
| source | |
| output | |
| decoder |
|
delete |
Non-copyable: copy constructor is deleted.
|
inline |
Adds/updates a listener notified on audio info changes.
|
inlineoverridevirtual |
Returns the current AudioInfo of the playback chain.
Implements AudioInfoSupport.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in MP3EncoderShine, PureDataStream, PWMAudioOutput< PWMDriverT >, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, ResampleStreamT< TInterpolator >, and SupportedRatesStream.
|
inline |
Returns the active AudioSource.
|
inline |
Starts or restarts playback from the first or given stream index.
|
inline |
Resets the decoder's internal state (bit reservoir, frame buffers, etc.) without touching the current AudioSource/stream or its read position. Optionally also discards audio bytes that piled up in the input stream while paused (drainSource=true).
Use this between stop() and play() for a streaming source (internet radio, HTTP, ICY) where resuming should mean "continue from now", not "replay whatever arrived while paused". Call it either right after stop() (drains what came in during the pause) or right before play() (drains what accumulated since) - both work, since nothing is being actively read while inactive anyway.
Not needed for a local file: the default stop()/play() behavior (freeze position, resume exactly where you left off) is what you normally want there, and drainSource=true would just throw away audio you'd otherwise still hear.
| drainSource | if true, also discard bytes already buffered by the input stream (e.g. a live source's socket backlog) |
|
inline |
Copies DEFAULT_BUFFER_SIZE (=1024 bytes) from the source to the decoder: Call this method in the loop.
|
inline |
Copies the requested bytes from source to decoder (call in loop)
|
inline |
Copies until source is exhausted (blocking)
|
inlinestaticprotected |
Callback implementation which writes to metadata.
|
inline |
Ends playback and resets decoder/intermediate stages.
|
inline |
Provides access to StreamCopy to register additional callbacks callbacks
|
inline |
Returns the VolumeStream used by the player.
|
inline |
Checks whether playback is active.
|
inline |
Checks whether automatic fade in/out is enabled.
|
inline |
Returns true if the player is currently muted.
|
inline |
Returns whether silence-on-inactive is enabled.
|
inlineprotected |
|
inline |
Moves to the next/previous stream by offset (negative supported)
|
inline |
Boolean conversion returns isActive()
|
delete |
Non-assignable: assignment operator is deleted.
|
inline |
|
inline |
Obsolete: use PlayPath!
|
inline |
plays a complete audio file or url from start to finish (blocking call)
| path | path to the audio file or url to play (depending on source) |
|
inline |
Moves back by offset streams (defaults to 1)
|
inline |
Toggles playback activity; triggers fade and optional silence.
|
inlineoverridevirtual |
Receives and forwards updated AudioInfo to the chain.
Implements AudioInfoSupport.
|
inline |
Sets or replaces the AudioSource.
|
inline |
Enables/disables automatic fade in/out to prevent pops.
|
inline |
Enables/disables auto-advance at end/timeout (overrides AudioSource)
|
inline |
Sets the internal copy buffer size (bytes)
|
inline |
Sets or replaces the AudioDecoder.
|
inline |
Sets delay (ms) to wait when output is full.
|
inline |
Selects stream by absolute index in the source.
|
inline |
Defines the metadata callback.
|
inline |
Sets the maximum ID3 metadata buffer size (default 256)
|
inline |
Mutes or unmutes the audio player.
|
inline |
Defines a callback that is invoked exactly once when the current stream reaches EOF (no more bytes can be read from the input stream). Signature: void onEOF(AudioPlayer& player)
|
inline |
Defines a callback that is called when the stream is changed.
|
inline |
Sets the final output to an AudioOutput (adds Volume/Fade for PCM)
|
inline |
Sets the final output to an AudioStream (adds Volume/Fade for PCM)
|
inline |
Selects stream by path without changing the source iterator.
|
inline |
Sets a user reference passed to the stream-change callback.
|
inline |
When enabled, writes zeros while inactive to keep sinks alive.
|
inlineprotected |
|
inlineoverridevirtual |
Sets volume in range [0.0, 1.0]; updates VolumeStream.
Reimplemented from VolumeSupport.
|
inline |
Defines the volume for the indicated channel.
|
inline |
Sets a custom VolumeControl implementation.
|
inline |
Halts playback; equivalent to setActive(false)
|
inlineoverridevirtual |
Returns the current volume [0.0, 1.0].
Reimplemented from VolumeSupport.
|
inline |
Returns the current volume for the indicated channel.
|
inlineprotected |
|
inline |
Writes the requested number of zero bytes to the output.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protectedinherited |