update audio files

This commit is contained in:
NP v/d Spek 2024-10-28 19:54:03 +01:00
parent b67adcd202
commit 5a942247a7
2 changed files with 8 additions and 11 deletions

View file

@ -5,11 +5,11 @@ namespace audio {
/* *************** AudioListener **************** */ /* *************** AudioListener **************** */
AudioStreamer *AudioListener::start(AudioStreamInfo &info) { AudioStreamer *AudioListener::start(const AudioStreamInfo &audio_stream_info) {
if (current_streamer_ != nullptr) { if (current_streamer_ != nullptr) {
return nullptr; return nullptr;
} }
if (this->starting(info)) { if (this->starting(audio_stream_info)) {
this->current_streamer_ = new AudioStreamer(); this->current_streamer_ = new AudioStreamer();
this->current_streamer_->set_parent(this); this->current_streamer_->set_parent(this);
} }
@ -19,7 +19,7 @@ AudioStreamer *AudioListener::start(AudioStreamInfo &info) {
AudioStreamer *AudioListener::start() { AudioStreamer *AudioListener::start() {
AudioStreamInfo info; AudioStreamInfo info;
this->get_default_audio_stream_info(info); this->get_default_audio_stream_info(info);
this->start(info); return this->start(info);
} }
bool AudioListener::can_stream(AudioStreamer *streamer) { bool AudioListener::can_stream(AudioStreamer *streamer) {
@ -38,8 +38,8 @@ AudioStreamer::~AudioStreamer() {
bool AudioStreamer::is_running() { return (this->parent_ == nullptr) ? false : this->parent_->can_stream(this); } bool AudioStreamer::is_running() { return (this->parent_ == nullptr) ? false : this->parent_->can_stream(this); }
size_t AudioStreamer::stream(const uint8_t *data, const size_t size, TickType_t ticks_to_wait) { size_t AudioStreamer::stream(const uint8_t *data, size_t size, TickType_t ticks_to_wait) {
if (!this->is_running(this)) if (!this->is_running())
return 0; return 0;
return this->parent_->streaming(data, size, ticks_to_wait); return this->parent_->streaming(data, size, ticks_to_wait);
} }

View file

@ -39,7 +39,7 @@ class AudioStreamer : public Parented<AudioListener> {
/// @param length The length of the audio data in bytes. /// @param length The length of the audio data in bytes.
/// @return The number of bytes that were actually written to the speaker's internal buffer. /// @return The number of bytes that were actually written to the speaker's internal buffer.
size_t stream(const uint8_t *data, const size_t size, TickType_t ticks_to_wait = 0); size_t stream(const uint8_t *data, size_t size, TickType_t ticks_to_wait = 0);
bool is_running(); bool is_running();
}; };
@ -54,11 +54,7 @@ class AudioListener {
AudioStreamer *start(const AudioStreamInfo &audio_stream_info); AudioStreamer *start(const AudioStreamInfo &audio_stream_info);
AudioStreamer *start(); AudioStreamer *start();
void stop() { void stop() { delete this->current_streamer_; }
if (this->current_streamer_ != nullptr) {
delete this->current_streamer_;
}
}
virtual bool can_stream(AudioStreamer *streamer); virtual bool can_stream(AudioStreamer *streamer);
@ -69,6 +65,7 @@ class AudioListener {
virtual void get_default_audio_stream_info(AudioStreamInfo &audio_stream_info) {} virtual void get_default_audio_stream_info(AudioStreamInfo &audio_stream_info) {}
protected: protected:
friend class AudioStreamer;
virtual bool starting(const AudioStreamInfo &audio_stream_info) = 0; virtual bool starting(const AudioStreamInfo &audio_stream_info) = 0;
virtual size_t streaming(const uint8_t *data, size_t size, TickType_t ticks_to_wait) = 0; virtual size_t streaming(const uint8_t *data, size_t size, TickType_t ticks_to_wait) = 0;
virtual void stopping(){}; virtual void stopping(){};