-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dc149e
commit 17f901b
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include "AudioCodecs/AudioEncoded.h" | ||
#include "AudioTools/Buffers.h" | ||
#include "AudioTools/AudioStreams.h" | ||
|
||
namespace audio_tools { | ||
|
||
/** | ||
* @brief Adapter class which allows the AudioDecoder API on a StreamingDecoder | ||
* @ingroup codecs | ||
* @ingroup decoder | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
*/ | ||
class DecoderFromStreaming : public AudioDecoder { | ||
public: | ||
/** | ||
* @brief Constructor for a new DecoderBase64 object | ||
* | ||
* @param out_buffeream Output Stream to which we write the decoded result | ||
*/ | ||
DecoderFromStreaming(StreamingDecoder &dec, int bufferSize) { | ||
TRACED(); | ||
p_dec = &dec; | ||
resize(bufferSize); | ||
} | ||
|
||
/// Defines the output Stream | ||
void setOutput(Print &out) override { | ||
p_dec->setInputStream(queue); | ||
p_dec->setOutput(out); | ||
} | ||
|
||
void begin() override { | ||
TRACED(); | ||
active = true; | ||
} | ||
|
||
void end() override { | ||
TRACED(); | ||
active = false; | ||
} | ||
|
||
/// resize the buffer | ||
void resize(int size){ | ||
rbuffer.resize(size); | ||
} | ||
|
||
size_t write(const void *data, size_t byteCount) override { | ||
if (p_out == nullptr) | ||
return 0; | ||
TRACED(); | ||
size_t result = queue.write((uint8_t *)data, byteCount); | ||
// trigger processing | ||
while(p_dec->copy()) delay(1); | ||
return result; | ||
} | ||
|
||
operator bool() override { return active; } | ||
|
||
protected: | ||
bool active = false; | ||
StreamingDecoder *p_dec = nullptr; | ||
RingBuffer<uint8_t> rbuffer{0}; | ||
QueueStream<uint8_t> queue{rbuffer}; // convert Buffer to Stream | ||
Print *p_out = nullptr; | ||
}; | ||
|
||
} // namespace audio_tools |