arduino-audio-tools
Loading...
Searching...
No Matches
src
AudioTools
Communication
AudioPlayer
AudioPlayerProtocol.h
Go to the documentation of this file.
1
#pragma once
2
#include "
AudioTools/CoreAudio/AudioPlayer.h
"
3
4
namespace
audio_tools
{
5
11
class
AudioPlayerProtocol
{
12
public
:
15
virtual
bool
processCommand
(
const
char
* input,
Print
& result) = 0;
16
18
virtual
bool
processCommand
(
Stream
& input,
Print
& result) {
19
char
buffer[
max_input_buffer_size
];
20
int
len =
readLine
(input, buffer,
max_input_buffer_size
);
21
if
(len == 0)
return
false
;
22
return
processCommand
(buffer, result);
23
}
25
virtual
void
setPlayer
(
AudioPlayer
& player) {
p_player
= &player; }
26
28
void
setMaxInputBufferSize
(
int
size) {
max_input_buffer_size
= size; }
29
30
protected
:
31
AudioPlayer
*
p_player
=
nullptr
;
32
int
max_input_buffer_size
= 256;
33
35
int
readLine
(
Stream
& in,
char
* str,
int
max) {
36
int
index = 0;
37
if
(in.
available
() > 0) {
38
index = in.readBytesUntil(
'\n'
, str, max);
39
str[index] =
'\0'
;
// null termination character
40
}
41
return
index;
42
}
43
};
44
45
}
// namespace audio_tools
AudioPlayer.h
audio_tools::AudioPlayer
High-level audio playback pipeline and controller.
Definition
AudioPlayer.h:51
audio_tools::AudioPlayerProtocol
Abstract class for protocol to control the audio player.
Definition
AudioPlayerProtocol.h:11
audio_tools::AudioPlayerProtocol::setMaxInputBufferSize
void setMaxInputBufferSize(int size)
Defines the input buffer size used by the readLine function (default 256)
Definition
AudioPlayerProtocol.h:28
audio_tools::AudioPlayerProtocol::readLine
int readLine(Stream &in, char *str, int max)
Reads a line delimited by ' ' from the stream.
Definition
AudioPlayerProtocol.h:35
audio_tools::AudioPlayerProtocol::processCommand
virtual bool processCommand(const char *input, Print &result)=0
audio_tools::AudioPlayerProtocol::setPlayer
virtual void setPlayer(AudioPlayer &player)
Defines the player.
Definition
AudioPlayerProtocol.h:25
audio_tools::AudioPlayerProtocol::p_player
AudioPlayer * p_player
Definition
AudioPlayerProtocol.h:31
audio_tools::AudioPlayerProtocol::processCommand
virtual bool processCommand(Stream &input, Print &result)
Proceess commands passed by Stream (e.g. Serial)
Definition
AudioPlayerProtocol.h:18
audio_tools::AudioPlayerProtocol::max_input_buffer_size
int max_input_buffer_size
Definition
AudioPlayerProtocol.h:32
audio_tools::Print
Definition
NoArduino.h:62
audio_tools::Stream
Definition
NoArduino.h:142
audio_tools::Stream::available
virtual int available()
Definition
NoArduino.h:146
audio_tools
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition
AudioCodecsBase.h:10
Generated by
1.9.8