Skip to content

Commit 87eabf8

Browse files
committed
fix: clang-format
1 parent 68df535 commit 87eabf8

67 files changed

Lines changed: 6592 additions & 5167 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

StreamCore32/core/include/AudioControl.h

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#pragma once
22

3-
#include <stddef.h> // for size_t
4-
#include <stdint.h> // for uint8_t
5-
#include <atomic> // for atomic
6-
#include <memory> // for shared_ptr, unique_ptr
7-
#include <mutex> // for mutex
8-
#include <string> // for string
9-
#include <functional> // for function
3+
#include <stddef.h> // for size_t
4+
#include <stdint.h> // for uint8_t
5+
#include <atomic> // for atomic
6+
#include <functional> // for function
7+
#include <memory> // for shared_ptr, unique_ptr
8+
#include <mutex> // for mutex
9+
#include <string> // for string
1010
#include "freertos/FreeRTOS.h"
1111
#include "freertos/semphr.h"
1212
#ifdef CONFIG_AUDIO_SINK_VS1053
1313
#include "VS1053.h" // for VS1053
1414
#define _AudioSink VS1053
15-
#else
15+
#else
1616
#include "StreamOrientedAudioSink.h"
1717
#define _AudioSink StreamOrientedAudioSink
1818
#endif
1919

2020
class AudioControl {
21-
public:
21+
public:
2222
enum CommandType {
2323
PLAY,
2424
PAUSE,
@@ -30,92 +30,96 @@ class AudioControl {
3030
VOLUME_LOGARITHMIC
3131
};
3232
class FeedControl {
33-
public:
33+
public:
3434
FeedControl(std::shared_ptr<AudioControl> audioController) {
3535
this->audioController = audioController;
3636
this->audioSink = audioController->audioSink;
3737
};
3838
std::shared_ptr<_AudioSink> audioSink = NULL;
3939
std::shared_ptr<AudioControl> audioController;
4040
size_t feedData(uint8_t* data, size_t bytes, size_t trackId,
41-
bool STORAGE_VOLATILE = 0);
41+
bool STORAGE_VOLATILE = 0);
4242
template <class T>
43-
void feedCommand(CommandType command, T value, std::optional<T> limit = std::nullopt) {
44-
if(command != CommandType::VOLUME_LINEAR && command != CommandType::VOLUME_LOGARITHMIC){
45-
if(!this->audioSink->streams.size()) return;
43+
void feedCommand(CommandType command, T value,
44+
std::optional<T> limit = std::nullopt) {
45+
if (command != CommandType::VOLUME_LINEAR &&
46+
command != CommandType::VOLUME_LOGARITHMIC) {
47+
if (!this->audioSink->streams.size())
48+
return;
4649
}
47-
switch (command)
48-
{
49-
case CommandType::PLAY:
50-
if (this->audioSink->streams[0]->state != _AudioSink::Stream::State::Stopped)
51-
this->audioSink->new_state(this->audioSink->streams[0], _AudioSink::Stream::State::Playback);
52-
break;
50+
switch (command) {
51+
case CommandType::PLAY:
52+
if (this->audioSink->streams[0]->state !=
53+
_AudioSink::Stream::State::Stopped)
54+
this->audioSink->new_state(this->audioSink->streams[0],
55+
_AudioSink::Stream::State::Playback);
56+
break;
5357

54-
case CommandType::PAUSE:
55-
if (this->audioSink->streams[0]->state != _AudioSink::Stream::State::Stopped)
56-
this->audioSink->new_state(this->audioSink->streams[0], _AudioSink::Stream::State::PlaybackPaused);
57-
break;
58+
case CommandType::PAUSE:
59+
if (this->audioSink->streams[0]->state !=
60+
_AudioSink::Stream::State::Stopped)
61+
this->audioSink->new_state(
62+
this->audioSink->streams[0],
63+
_AudioSink::Stream::State::PlaybackPaused);
64+
break;
5865

59-
case CommandType::DISC:
60-
{
61-
printf("DISC\n");
62-
auto& v = this->audioSink->streams;
63-
if (!v.size()) break;
64-
if (v.size() > 1) {
65-
auto it = v.begin() + 1; // start after index 0
66-
while (it != v.end()) {
67-
// adapt *it access to your actual element type (ptr/unique_ptr/object)
68-
auto* src = static_cast<FeedControl*>((*it)->source);
69-
if (src == this) {
70-
it = v.erase(it); // erase returns the next iterator
71-
}
72-
else {
73-
++it;
66+
case CommandType::DISC: {
67+
printf("DISC\n");
68+
auto& v = this->audioSink->streams;
69+
if (!v.size())
70+
break;
71+
if (v.size() > 1) {
72+
auto it = v.begin() + 1; // start after index 0
73+
while (it != v.end()) {
74+
// adapt *it access to your actual element type (ptr/unique_ptr/object)
75+
auto* src = static_cast<FeedControl*>((*it)->source);
76+
if (src == this) {
77+
it = v.erase(it); // erase returns the next iterator
78+
} else {
79+
++it;
80+
}
7481
}
7582
}
76-
}
77-
if (!v.empty() && v[0]->source == this) { // guard against empty
78-
printf("DISC stop\n");
79-
this->audioSink->stop_feed();
80-
}
81-
}
82-
break;
83+
if (!v.empty() && v[0]->source == this) { // guard against empty
84+
printf("DISC stop\n");
85+
this->audioSink->stop_feed();
86+
}
87+
} break;
8388

84-
case CommandType::FLUSH:
85-
if(this->audioSink->streams.size() > 0)
86-
this->audioSink->streams[0]->empty_feed();
87-
break;
89+
case CommandType::FLUSH:
90+
if (this->audioSink->streams.size() > 0)
91+
this->audioSink->streams[0]->empty_feed();
92+
break;
8893

89-
case CommandType::SKIP:
90-
this->audioSink->stop_feed();
91-
break;
94+
case CommandType::SKIP:
95+
this->audioSink->stop_feed();
96+
break;
9297

93-
case CommandType::VOLUME_LINEAR:{
94-
uint8_t lin = limit.has_value()
95-
? this->audioSink->to_linear_volume(value, limit)
96-
: this->audioSink->to_linear_volume(value);
97-
this->audioController->volume.store(lin);
98-
printf("VOLUME_LINEAR %d\n", this->audioController->volume.load());
99-
this->audioSink->feed_command([this](uint8_t) {
100-
this->audioSink->set_volume(this->audioController->volume.load());
98+
case CommandType::VOLUME_LINEAR: {
99+
uint8_t lin = limit.has_value()
100+
? this->audioSink->to_linear_volume(value, limit)
101+
: this->audioSink->to_linear_volume(value);
102+
this->audioController->volume.store(lin);
101103
printf("VOLUME_LINEAR %d\n", this->audioController->volume.load());
104+
this->audioSink->feed_command([this](uint8_t) {
105+
this->audioSink->set_volume(this->audioController->volume.load());
106+
printf("VOLUME_LINEAR %d\n", this->audioController->volume.load());
102107
});
103-
}
104-
break;
105-
case CommandType::VOLUME_LOGARITHMIC:{
106-
this->audioController->volume.store(this->audioSink->to_logarithmic_volume(value));
107-
this->audioSink->feed_command([this, value](uint8_t) {
108-
this->audioSink->set_volume(this->audioController->volume.load());
108+
} break;
109+
case CommandType::VOLUME_LOGARITHMIC: {
110+
this->audioController->volume.store(
111+
this->audioSink->to_logarithmic_volume(value));
112+
this->audioSink->feed_command([this, value](uint8_t) {
113+
this->audioSink->set_volume(this->audioController->volume.load());
109114
});
110-
}
111-
break;
115+
} break;
112116

113-
default:
114-
break;
117+
default:
118+
break;
115119
}
116120
}
117-
std::function<void(uint8_t)> state_callback = [](uint8_t state) {};
118-
121+
std::function<void(uint8_t)> state_callback = [](uint8_t state) {
122+
};
119123
};
120124
AudioControl();
121125
size_t getHeaderOffset(size_t trackId);
@@ -131,7 +135,7 @@ class AudioControl {
131135
std::atomic<size_t> volume = 90;
132136
SemaphoreHandle_t SPI_semaphore;
133137

134-
private:
138+
private:
135139
size_t trackId = 0;
136140
std::shared_ptr<_AudioSink> audioSink;
137141

StreamCore32/core/include/EspRandomEngine.h

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,44 @@
33
#include <cstdint>
44
#include <random>
55
#if __has_include("esp_random.h")
6-
#include "esp_random.h"
6+
#include "esp_random.h"
77
#else
8-
#include "esp_system.h"
8+
#include "esp_system.h"
99
#endif
1010

1111
namespace streamcore {
1212

1313
// A replacement for std::random_device using ESP32's hardware RNG
1414
class esp_random_device {
15-
public:
16-
using result_type = uint32_t;
15+
public:
16+
using result_type = uint32_t;
1717

18-
static constexpr result_type min() {
19-
return 0;
20-
}
18+
static constexpr result_type min() { return 0; }
2119

22-
static constexpr result_type max() {
23-
return UINT32_MAX;
24-
}
20+
static constexpr result_type max() { return UINT32_MAX; }
2521

26-
result_type operator()() {
27-
return esp_random();
28-
}
22+
result_type operator()() { return esp_random(); }
2923
};
3024

3125
// A random engine using esp_random_device under the hood
3226
class esp_random_engine {
33-
public:
34-
using result_type = uint32_t;
27+
public:
28+
using result_type = uint32_t;
3529

36-
esp_random_engine() = default;
37-
explicit esp_random_engine(result_type /*seed*/) { /* No-op: seeded externally */ }
30+
esp_random_engine() = default;
31+
explicit esp_random_engine(
32+
result_type /*seed*/) { /* No-op: seeded externally */ }
3833

39-
static constexpr result_type min() {
40-
return 0;
41-
}
34+
static constexpr result_type min() { return 0; }
4235

43-
static constexpr result_type max() {
44-
return UINT32_MAX;
45-
}
36+
static constexpr result_type max() { return UINT32_MAX; }
4637

47-
void seed(result_type /*seed*/) {
48-
// Optionally reseed logic can go here if needed.
49-
// esp_random() doesn't allow seeding manually, so we ignore this.
50-
}
38+
void seed(result_type /*seed*/) {
39+
// Optionally reseed logic can go here if needed.
40+
// esp_random() doesn't allow seeding manually, so we ignore this.
41+
}
5142

52-
result_type operator()() {
53-
return esp_random();
54-
}
43+
result_type operator()() { return esp_random(); }
5544
};
5645

57-
} // namespace esp_random_ns
46+
} // namespace streamcore

StreamCore32/core/include/Heartbeat.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@
22
#pragma once
33
#include <atomic>
44
#include <functional>
5-
#include "BellTask.h" // bell::task(...)
6-
#include "BellLogger.h" // optional
5+
#include "BellLogger.h" // optional
6+
#include "BellTask.h" // bell::task(...)
77
#include "BellUtils.h"
88

99
class Heartbeat : public bell::Task {
10-
public:
10+
public:
1111
using SendFn = std::function<void()>;
1212

13-
explicit Heartbeat(SendFn send, uint32_t timeout_ms = 10000) : bell::Task("Heartbeat", 1024 * 8, 1, 1, 1), send_(std::move(send)), timeout_ms_(timeout_ms) {}
14-
~Heartbeat() {
15-
stop();
16-
}
13+
explicit Heartbeat(SendFn send, uint32_t timeout_ms = 10000)
14+
: bell::Task("Heartbeat", 1024 * 8, 1, 1, 1),
15+
send_(std::move(send)),
16+
timeout_ms_(timeout_ms) {}
17+
~Heartbeat() { stop(); }
1718

1819
void start() {
19-
if (running_.exchange(true)) return; // already running
20+
if (running_.exchange(true))
21+
return; // already running
2022
stopFlag_.store(false);
2123
startTask();
2224
}
2325

2426
void stop() {
2527
stopFlag_.store(true);
26-
while (running_.load()) BELL_SLEEP_MS(100);
27-
// if your Bell has a cancel, you can also:
28-
// bell::cancel(taskId_);
28+
while (running_.load())
29+
BELL_SLEEP_MS(100);
2930
}
3031

3132
void delay(uint32_t ms = 10000) {
@@ -45,16 +46,17 @@ class Heartbeat : public bell::Task {
4546
BELL_SLEEP_MS(100);
4647
std::scoped_lock lock(delay_mutex_);
4748
delay_ -= 100;
48-
if (stopFlag_.load()) break;
49+
if (stopFlag_.load())
50+
break;
4951
}
5052
}
5153
running_.store(false);
5254
}
5355

54-
private:
56+
private:
5557
SendFn send_;
56-
std::atomic<bool> stopFlag_{ false };
57-
std::atomic<bool> running_{ false };
58+
std::atomic<bool> stopFlag_{false};
59+
std::atomic<bool> running_{false};
5860
std::mutex delay_mutex_;
5961
uint32_t delay_ = 0;
6062
uint32_t timeout_ms_ = 10000;

0 commit comments

Comments
 (0)