Skip to content

Commit 5f6ac2c

Browse files
committed
TimeInfoStream compressionRatio
1 parent c84e36e commit 5f6ac2c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Experiments/TimeInfoStream.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class TimeInfoStream : public AudioStreamX {
7070
/// Provides only data for the indicated start and end time
7171
size_t readBytes(uint8_t *buffer, size_t length) override {
7272
if (p_stream==nullptr) return 0;
73-
calculateTime(length);
7473
size_t result = p_stream->readBytes(buffer, length);
74+
calculateTime(result);
7575
return isPlaying()?result : 0;
7676
}
7777

@@ -93,6 +93,11 @@ class TimeInfoStream : public AudioStreamX {
9393

9494
int availableForWrite() override { return p_print->availableForWrite(); }
9595

96+
/// Experimental: if used on mp3 you can set the ratio e.g. to 11
97+
void setCompressionRatio(float ratio){
98+
compression_ratio = ratio;
99+
}
100+
96101
protected:
97102
Stream *p_stream=nullptr;
98103
Print *p_print=nullptr;
@@ -101,6 +106,7 @@ class TimeInfoStream : public AudioStreamX {
101106
long end_time = -1;
102107
double current_time = 0;
103108
double bytes_per_second = -1.0;
109+
float compression_ratio = 1.0;
104110

105111
void calculateTime(int bytes){
106112
if (bytes_per_second<0.0){
@@ -109,7 +115,7 @@ class TimeInfoStream : public AudioStreamX {
109115
int bytes_per_sample = p_info->audioInfo().bits_per_sample / 8;
110116
bytes_per_second = sample_rate * channels * bytes_per_sample;
111117
}
112-
current_time = static_cast<double>(bytes) / bytes_per_second;
118+
current_time = (static_cast<double>(bytes) / bytes_per_second) * compression_ratio;
113119
}
114120

115121
};

0 commit comments

Comments
 (0)