Skip to content

Commit 10e5877

Browse files
authored
Corrections to 1.2.0 (#2180)
* Move to Communication from AudioLibs * bump to 1.2.0 * move HTTP to v1.2.0 (#2176) * move HTTP to Communication * RTSP corrections * Move to Communication from AudioLibs * bump to 1.2.0 * move Player Remote Control to Communication * AudioPlayerContro.h * A2DPStream to Communication * Delete AudioLibs/All.h * USE_RTSP_LOGIN * USE_RTSP_LOGIN * RTSPClient: error corrections * RTSP corrections * examples: correct build errors * AudioPlayer: improve comments * Documentation: public methods * Documentation
1 parent f6ae680 commit 10e5877

File tree

3 files changed

+68
-58
lines changed

3 files changed

+68
-58
lines changed

src/AudioTools/CoreAudio/AudioPlayer.h

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,27 @@
2323
namespace audio_tools {
2424

2525
/**
26-
* @brief Implements a simple audio player which supports the following
27-
* commands:
28-
* - begin
29-
* - play
30-
* - stop
31-
* - next
32-
* - set Volume
26+
* @brief High-level audio playback pipeline and controller.
27+
*
28+
* Provides pull-driven playback from an AudioSource through optional decoding,
29+
* volume control and click-free fades to an AudioOutput/AudioStream/Print.
30+
*
31+
* Features:
32+
* - Playback control: begin, play, stop, next, previous, setIndex
33+
* - PCM and encoded formats via AudioDecoder with dynamic audio info updates
34+
* - Volume management (0.0–1.0) with pluggable VolumeControl
35+
* - Auto-fade in/out to avoid pops; optional silence while inactive
36+
* - Auto-advance on timeout with forward/backward navigation
37+
* - Metadata: ICY (via source) or ID3 (internal MetaDataID3)
38+
* - Callbacks: metadata updates and stream-change notification
39+
* - Flow control: adjustable copy buffer and optional delay when output is full
40+
*
41+
* Pipeline: AudioSource → StreamCopy → EncodedAudioOutput → VolumeStream →
42+
* FadeStream → Output.
43+
*
44+
* Operation model: call copy() regularly (non-blocking) or copyAll() for
45+
* blocking end-to-end playback.
46+
*
3347
* @ingroup player
3448
* @author Phil Schatzmann
3549
* @copyright GPLv3
@@ -94,10 +108,13 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
94108
decoder.addNotifyAudioChange(*this);
95109
}
96110

111+
/// Non-copyable: copy constructor is deleted
97112
AudioPlayer(AudioPlayer const &) = delete;
98113

114+
/// Non-assignable: assignment operator is deleted
99115
AudioPlayer &operator=(AudioPlayer const &) = delete;
100116

117+
/// Sets the final output to an AudioOutput (adds Volume/Fade for PCM)
101118
void setOutput(AudioOutput &output) {
102119
if (p_decoder->isResultPCM()) {
103120
this->fade.setOutput(output);
@@ -112,6 +129,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
112129
this->p_final_stream = nullptr;
113130
}
114131

132+
/// Sets the final output to a Print (adds Volume/Fade for PCM)
115133
void setOutput(Print &output) {
116134
if (p_decoder->isResultPCM()) {
117135
this->fade.setOutput(output);
@@ -126,6 +144,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
126144
this->p_final_stream = nullptr;
127145
}
128146

147+
/// Sets the final output to an AudioStream (adds Volume/Fade for PCM)
129148
void setOutput(AudioStream &output) {
130149
if (p_decoder->isResultPCM()) {
131150
this->fade.setOutput(output);
@@ -140,11 +159,10 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
140159
this->p_final_stream = &output;
141160
}
142161

143-
/// Defines the number of bytes used by the copier
162+
/// Sets the internal copy buffer size (bytes)
144163
void setBufferSize(int size) { copier.resize(size); }
145164

146-
/// (Re)Starts the playing of the music (from the beginning or the indicated
147-
/// index)
165+
/// Starts or restarts playback from the first or given stream index
148166
bool begin(int index = 0, bool isActive = true) {
149167
TRACED();
150168
bool result = false;
@@ -200,6 +218,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
200218
return result;
201219
}
202220

221+
/// Ends playback and resets decoder/intermediate stages
203222
void end() {
204223
TRACED();
205224
active = false;
@@ -213,19 +232,19 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
213232
}
214233
}
215234

216-
/// Provides the actual audio source
235+
/// Returns the active AudioSource
217236
AudioSource &audioSource() { return *p_source; }
218237

219-
/// (Re)defines the audio source
238+
/// Sets or replaces the AudioSource
220239
void setAudioSource(AudioSource &source) { this->p_source = &source; }
221240

222-
/// (Re)defines the decoder
241+
/// Sets or replaces the AudioDecoder
223242
void setDecoder(AudioDecoder &decoder) {
224243
this->p_decoder = &decoder;
225244
out_decoding.setDecoder(p_decoder);
226245
}
227246

228-
/// (Re)defines the notify
247+
/// Adds/updates a listener notified on audio info changes
229248
void addNotifyAudioChange(AudioInfoSupport *notify) {
230249
this->p_final_notify = notify;
231250
// notification for audio configuration
@@ -234,7 +253,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
234253
}
235254
}
236255

237-
/// Updates the audio info in the related objects
256+
/// Receives and forwards updated AudioInfo to the chain
238257
void setAudioInfo(AudioInfo info) override {
239258
TRACED();
240259
LOGI("sample_rate: %d", (int)info.sample_rate);
@@ -250,9 +269,11 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
250269
if (p_final_notify != nullptr) p_final_notify->setAudioInfo(info);
251270
};
252271

272+
/// Returns the current AudioInfo of the playback chain
253273
AudioInfo audioInfo() override { return info; }
254274

255275
/// starts / resumes the playing after calling stop(): same as setActive(true)
276+
/// Resumes playback after stop(); equivalent to setActive(true)
256277
void play() {
257278
TRACED();
258279
setActive(true);
@@ -278,18 +299,17 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
278299
return true;
279300
}
280301

281-
/// Obsolete: use PlayPath!
302+
/// Obsolete: use PlayPath!
282303
bool playFile(const char *path) { return playPath(path); }
283304

284305

285-
/// halts the playing: same as setActive(false)
306+
/// Halts playback; equivalent to setActive(false)
286307
void stop() {
287308
TRACED();
288309
setActive(false);
289310
}
290311

291-
/// moves to next file or nth next file when indicating an offset. Negative
292-
/// values are supported to move back.
312+
/// Moves to the next/previous stream by offset (negative supported)
293313
bool next(int offset = 1) {
294314
TRACED();
295315
writeEnd();
@@ -298,7 +318,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
298318
return active;
299319
}
300320

301-
/// moves to the selected file position
321+
/// Selects stream by absolute index in the source
302322
bool setIndex(int idx) {
303323
TRACED();
304324
writeEnd();
@@ -307,7 +327,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
307327
return active;
308328
}
309329

310-
/// Moves to the selected file w/o updating the actual file position
330+
/// Selects stream by path without changing the source iterator
311331
bool setPath(const char *path) {
312332
TRACED();
313333
writeEnd();
@@ -316,7 +336,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
316336
return active;
317337
}
318338

319-
/// moves to previous file
339+
/// Moves back by offset streams (defaults to 1)
320340
bool previous(int offset = 1) {
321341
TRACED();
322342
writeEnd();
@@ -325,7 +345,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
325345
return active;
326346
}
327347

328-
/// start selected input stream
348+
/// Activates the provided Stream as current input
329349
bool setStream(Stream *input) {
330350
end();
331351
out_decoding.begin();
@@ -341,16 +361,16 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
341361
return p_input_stream != nullptr;
342362
}
343363

344-
/// Provides the actual stream (=e.g.file)
364+
/// Returns the currently active input Stream (e.g., file)
345365
Stream *getStream() { return p_input_stream; }
346366

347-
/// determines if the player is active
367+
/// Checks whether playback is active
348368
bool isActive() { return active; }
349369

350-
/// determines if the player is active
370+
/// Boolean conversion returns isActive()
351371
operator bool() { return isActive(); }
352372

353-
/// The same like start() / stop()
373+
/// Toggles playback activity; triggers fade and optional silence
354374
void setActive(bool isActive) {
355375
if (is_auto_fade) {
356376
if (isActive) {
@@ -364,7 +384,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
364384
active = isActive;
365385
}
366386

367-
/// sets the volume - values need to be between 0.0 and 1.0
387+
/// Sets volume in range [0.0, 1.0]; updates VolumeStream
368388
bool setVolume(float volume) override {
369389
bool result = true;
370390
if (volume >= 0.0f && volume <= 1.0f) {
@@ -380,22 +400,20 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
380400
return result;
381401
}
382402

383-
/// Determines the actual volume
403+
/// Returns the current volume [0.0, 1.0]
384404
float volume() override { return current_volume; }
385405

386-
/// Set automatically move to next file and end of current file: This is
387-
/// determined from the AudioSource. If you want to override it call this
388-
/// method after calling begin()!
406+
/// Enables/disables auto-advance at end/timeout (overrides AudioSource)
389407
void setAutoNext(bool next) { autonext = next; }
390408

391-
/// Defines the wait time in ms if the target output is full
409+
/// Sets delay (ms) to wait when output is full
392410
void setDelayIfOutputFull(int delayMs) { delay_if_full = delayMs; }
393411

394412
/// Copies DEFAULT_BUFFER_SIZE (=1024 bytes) from the source to the decoder:
395413
/// Call this method in the loop.
396414
size_t copy() { return copy(copier.bufferSize()); }
397415

398-
/// Copies all the data
416+
/// Copies until source is exhausted (blocking)
399417
size_t copyAll() {
400418
size_t result = 0;
401419
size_t step = copy();
@@ -406,8 +424,7 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
406424
return result;
407425
}
408426

409-
/// Copies the indicated number of bytes from the source to the decoder: Call
410-
/// this method in the loop.
427+
/// Copies the requested bytes from source to decoder (call in loop)
411428
size_t copy(size_t bytes) {
412429
size_t result = 0;
413430
if (active) {
@@ -444,21 +461,20 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
444461
return result;
445462
}
446463

447-
/// Change the VolumeControl implementation
464+
/// Sets a custom VolumeControl implementation
448465
void setVolumeControl(VolumeControl &vc) { volume_out.setVolumeControl(vc); }
449466

450-
/// Provides access to the StreamCopy, so that we can register additinal
467+
/// Provides access to StreamCopy to register additional callbacks
451468
/// callbacks
452469
StreamCopy &getStreamCopy() { return copier; }
453470

454-
/// If set to true the player writes 0 values instead of no data if the player
455-
/// is inactive
471+
/// When enabled, writes zeros while inactive to keep sinks alive
456472
void setSilenceOnInactive(bool active) { silence_on_inactive = active; }
457473

458-
/// Checks if silence_on_inactive has been activated (default false)
474+
/// Returns whether silence-on-inactive is enabled
459475
bool isSilenceOnInactive() { return silence_on_inactive; }
460476

461-
/// Sends the requested bytes as 0 values to the output
477+
/// Writes the requested number of zero bytes to the output
462478
void writeSilence(size_t bytes) {
463479
TRACEI();
464480
if (p_final_print != nullptr) {
@@ -468,25 +484,22 @@ class AudioPlayer : public AudioInfoSupport, public VolumeSupport {
468484
}
469485
}
470486

471-
// /// Provides the Print object to which we send the decoding result
472-
// Print *getVolumeOutput() { return &volume_out; }
473-
474-
/// Provides the reference to the volume stream
487+
/// Returns the VolumeStream used by the player
475488
VolumeStream &getVolumeStream() { return volume_out; }
476489

477-
/// Activates/deactivates the automatic fade in and fade out to prevent
478-
/// popping sounds: default is active
490+
/// Enables/disables automatic fade in/out to prevent pops
479491
void setAutoFade(bool active) { is_auto_fade = active; }
480492

493+
/// Checks whether automatic fade in/out is enabled
481494
bool isAutoFade() { return is_auto_fade; }
482495

483-
/// Change the default ID3 max metadata size (256)
496+
/// Sets the maximum ID3 metadata buffer size (default 256)
484497
void setMetaDataSize(int size) { meta_out.resize(size); }
485498

486-
/// this is used to set the reference for the stream change callback
499+
/// Sets a user reference passed to the stream-change callback
487500
void setReference(void *ref) { p_reference = ref; }
488501

489-
/// Defines the medatadata callback
502+
/// Defines the metadata callback
490503
void setMetadataCallback(void (*callback)(MetaDataType type, const char *str,
491504
int len),
492505
ID3TypeSelection sel = SELECT_ID3) {

src/AudioTools/CoreAudio/AudioRuntime.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88

99
namespace audio_tools {
1010

11-
/**
12-
* @brief Public generic methods
13-
* @author Phil Schatzmann
14-
* @copyright GPLv3
15-
*/
16-
1711
/// stops any further processing by spinning in an endless loop @ingroup basic
1812
inline void stop() {
1913
#ifdef EXIT_ON_STOP
@@ -34,6 +28,8 @@ inline static void checkMemory(bool printMemory=false) {
3428
}
3529

3630
#ifdef ARDUINO
31+
32+
/// prints n times the character ch and a new line @ingroup basic
3733
inline void printNChar(char ch, int n){
3834
for (int j=0;j<n;j++) Serial.print(ch);
3935
Serial.println();

src/AudioTools/Sandbox/BLE/AudioBLEStream.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
namespace audio_tools {
1010

1111
/**
12-
* @ingroup main
1312
* @brief Transmit and receive data via BLE using a Serial API.
1413
* The following additional experimental features are offered:
1514
* setFramed(true) tries to keep the original write sizes;
1615
* setAudioInfoActive(true) informs about changes in the audio info
16+
* @ingroup communications
17+
* @author Phil Schatzmann
1718
*/
1819

1920
class AudioBLEStream : public AudioStream {

0 commit comments

Comments
 (0)