Skip to content

Commit b701b7b

Browse files
committed
TimeInfoStream
1 parent 21c2462 commit b701b7b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Experiments/TimeInfoStream.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ class TimeInfoStream : public AudioStreamX {
2727
end_time = endSeconds;
2828
}
2929

30+
/// Defines the start time in seconds. The audio before the start time will be skipped
3031
void setStartTime(long startSeconds){
3132
start_time = startSeconds;
3233
}
3334

35+
/// Defines (an optional) the end time in seconds. After the end time no audio is played and available() will return 0
3436
void setEndTime(long endSeconds){
3537
end_time = endSeconds;
3638
}
@@ -63,18 +65,30 @@ class TimeInfoStream : public AudioStreamX {
6365
return isActive();
6466
}
6567

68+
/// Provides only data for the indicated start and end time
6669
size_t readBytes(uint8_t *buffer, size_t length) override {
6770
if (p_stream==nullptr) return 0;
6871
calculateTime(length);
69-
return isPlaying()?p_stream->readBytes(buffer, length):length;
72+
size_t result = p_stream->readBytes(buffer, length);
73+
return isPlaying()?result : 0;
7074
}
7175

76+
/// Plays only data for the indiated start and end time
7277
size_t write(const uint8_t *buffer, size_t length) override{
7378
calculateTime(length);
7479
return isPlaying()?p_print->write(buffer, length):length;
7580
}
7681

77-
int available() override { return p_stream!=nullptr ? p_stream->available():0; };
82+
/// Provides the available bytes until the end time has reached
83+
int available() override {
84+
if (p_stream==nullptr) return 0;
85+
return isActive() ? p_stream->available() : 0;
86+
}
87+
88+
void setAudioInfo(AudioBaseInfo info) override {
89+
p_info->setAudioInfo(info);
90+
}
91+
7892
int availableForWrite() override { return p_print->availableForWrite(); }
7993

8094
protected:

0 commit comments

Comments
 (0)