Skip to content

Commit 873b7ff

Browse files
committed
A2DPStream provide access to buffer
1 parent 8ce4412 commit 873b7ff

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/AudioLibs/A2DPStream.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,34 @@ class A2DPStream : public AudioStream, public VolumeSupport {
258258
return result;
259259
}
260260

261+
/// Provides the number of bytes available to read
261262
int available() override {
262263
// only supported in tx mode
263264
if (config.mode!=RX_MODE) return 0;
264265
return a2dp_buffer.available();
265266
}
266267

268+
/// Provides the number of bytes available to write
267269
int availableForWrite() override {
268270
// only supported in tx mode
269271
if (config.mode!=TX_MODE ) return 0;
270272
// return infor from buffer
271273
return a2dp_buffer.availableForWrite();
272274
}
273275

274-
// Define the volme (values between 0.0 and 1.0)
276+
/// Define the volume (values between 0.0 and 1.0)
275277
bool setVolume(float volume) override {
276278
VolumeSupport::setVolume(volume);
277279
// 128 is max volume
278280
if (a2dp!=nullptr) a2dp->set_volume(volume * A2DP_MAX_VOL);
279281
return true;
280282
}
281283

284+
/// Provides access to the buffer
285+
BaseBuffer<uint8_t> &buffer() {
286+
return a2dp_buffer;
287+
}
288+
282289
protected:
283290
A2DPConfig config;
284291
BluetoothA2DPSource *a2dp_source = nullptr;

src/AudioTools/Buffers.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ class BaseBuffer {
144144

145145
virtual size_t size() = 0;
146146

147+
/// Returns the level of the buffer in %
148+
virtual float levelPercent() {
149+
// prevent div by 0.
150+
if (size()==0) return 0.0;
151+
return 100.0 * static_cast<float>(available()) / static_cast<float>(size());
152+
}
153+
147154
protected:
148155
void setWritePos(int pos){};
149156

0 commit comments

Comments
 (0)