@@ -1100,6 +1100,16 @@ class MeasuringStream : public AudioStream {
1100
1100
}
1101
1101
};
1102
1102
1103
+ /* *
1104
+ * @brief Configuration for ProgressStream
1105
+ * @author Phil Schatzmann
1106
+ * @copyright GPLv3
1107
+ *
1108
+ */
1109
+ class ProgressStreamInfo : public AudioInfo {
1110
+ public:
1111
+ size_t total_size = 0 ;
1112
+ };
1103
1113
/* *
1104
1114
* @brief Generic calss to measure the the total bytes which were processed in order to
1105
1115
* calculate the progress as a percentage of the total size.
@@ -1119,6 +1129,15 @@ class ProgressStream : public AudioStream {
1119
1129
setStream (stream);
1120
1130
}
1121
1131
1132
+ ProgressStreamInfo& defaultConfig () {
1133
+ return progress_info;
1134
+ }
1135
+
1136
+ void setAudioInfo (AudioInfo info) override {
1137
+ AudioStream::setAudioInfo (info);
1138
+ progress_info.copyFrom (info);
1139
+ }
1140
+
1122
1141
void setStream (Stream &stream){
1123
1142
p_stream =&stream;
1124
1143
p_print = &stream;
@@ -1138,26 +1157,43 @@ class ProgressStream : public AudioStream {
1138
1157
return AudioStream::begin ();
1139
1158
}
1140
1159
1160
+ bool begin (ProgressStreamInfo info){
1161
+ progress_info = info;
1162
+ setAudioInfo (info);
1163
+ return AudioStream::begin ();
1164
+ }
1165
+
1141
1166
// / Updates the total size and restarts the percent calculation
1142
1167
void setSize (size_t len){
1143
1168
total_processed = 0 ;
1144
- total_size = len;
1169
+ progress_info. total_size = len;
1145
1170
}
1146
1171
1147
1172
// / Provides the current total size (defined by setSize)
1148
1173
size_t size (){
1149
- return total_size;
1174
+ return progress_info. total_size ;
1150
1175
}
1151
1176
1152
1177
// / Provides the number of processed bytes
1153
- size_t processed () {
1178
+ size_t processedBytes () {
1154
1179
return total_processed;
1155
1180
}
1156
1181
1182
+ // / Provides the number of processed seconds
1183
+ size_t processedSecs () {
1184
+ AudioInfo info = audioInfo ();
1185
+ int byte_rate = info.sample_rate * info.bits_per_sample * info.channels / 8 ;
1186
+ if (byte_rate==0 ){
1187
+ LOGE (" Audio Info not defined" );
1188
+ return 0 ;
1189
+ }
1190
+ return total_processed / byte_rate;
1191
+ }
1192
+
1157
1193
// / Provides the processed percentage: If no size has been defined we return 0
1158
1194
float percentage () {
1159
- if (total_size==0 ) return 0 ;
1160
- return 100.0 * total_processed / total_size;
1195
+ if (progress_info. total_size ==0 ) return 0 ;
1196
+ return 100.0 * total_processed / progress_info. total_size ;
1161
1197
}
1162
1198
1163
1199
// / Provides the data from all streams mixed together
@@ -1184,10 +1220,10 @@ class ProgressStream : public AudioStream {
1184
1220
}
1185
1221
1186
1222
protected:
1223
+ ProgressStreamInfo progress_info;
1187
1224
Stream *p_stream=nullptr ;
1188
1225
Print *p_print=nullptr ;
1189
1226
size_t total_processed = 0 ;
1190
- size_t total_size = 0 ;
1191
1227
1192
1228
size_t measure (size_t len) {
1193
1229
total_processed += len;
0 commit comments