@@ -70,8 +70,8 @@ class TimeInfoStream : public AudioStreamX {
70
70
// / Provides only data for the indicated start and end time
71
71
size_t readBytes (uint8_t *buffer, size_t length) override {
72
72
if (p_stream==nullptr ) return 0 ;
73
- calculateTime (length);
74
73
size_t result = p_stream->readBytes (buffer, length);
74
+ calculateTime (result);
75
75
return isPlaying ()?result : 0 ;
76
76
}
77
77
@@ -93,6 +93,11 @@ class TimeInfoStream : public AudioStreamX {
93
93
94
94
int availableForWrite () override { return p_print->availableForWrite (); }
95
95
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
+
96
101
protected:
97
102
Stream *p_stream=nullptr ;
98
103
Print *p_print=nullptr ;
@@ -101,6 +106,7 @@ class TimeInfoStream : public AudioStreamX {
101
106
long end_time = -1 ;
102
107
double current_time = 0 ;
103
108
double bytes_per_second = -1.0 ;
109
+ float compression_ratio = 1.0 ;
104
110
105
111
void calculateTime (int bytes){
106
112
if (bytes_per_second<0.0 ){
@@ -109,7 +115,7 @@ class TimeInfoStream : public AudioStreamX {
109
115
int bytes_per_sample = p_info->audioInfo ().bits_per_sample / 8 ;
110
116
bytes_per_second = sample_rate * channels * bytes_per_sample;
111
117
}
112
- current_time = static_cast <double >(bytes) / bytes_per_second;
118
+ current_time = ( static_cast <double >(bytes) / bytes_per_second) * compression_ratio ;
113
119
}
114
120
115
121
};
0 commit comments