@@ -24,26 +24,25 @@ namespace audio_tools {
24
24
template <class FileType > class FileLoopT : public BaseStream {
25
25
public:
26
26
FileLoopT () = default ;
27
- FileLoopT (FileType file, int count = -1 , int rewindPos = -1 ) {
27
+ FileLoopT (FileType file, int count = -1 , int rewindPos = -1 , int startPos = 0 ) {
28
28
setFile (file);
29
29
setLoopCount (count);
30
- setStartPos (rewindPos);
30
+ setRewindPos (rewindPos);
31
+ setStartPos (startPos);
31
32
}
32
33
33
34
// restarts the file from the beginning
34
35
bool begin () {
35
36
TRACEI ();
36
- // automatic determination of start pos
37
- if (start_pos <= 0 ){
37
+ // automatic determination of rewind pos
38
+ if (rewind_pos <= 0 ){
38
39
current_file.seek (0 );
39
40
char tmp[5 ] = {0 };
40
41
current_file.readBytes (tmp, 4 );
41
42
// for wav files remove header
42
- start_pos = StrView (tmp).equals (" RIFF" ) ? 44 : 0 ;
43
- current_file.seek (0 );
44
- } else {
45
- current_file.seek (start_pos);
43
+ rewind_pos = StrView (tmp).equals (" RIFF" ) ? 44 : 0 ;
46
44
}
45
+ current_file.seek (start_pos);
47
46
size_open = total_size;
48
47
return current_file;
49
48
}
@@ -63,6 +62,9 @@ template <class FileType> class FileLoopT : public BaseStream {
63
62
}
64
63
65
64
// / defines the start position after the rewind. E.g. for wav files this should be 44
65
+ void setRewindPos (int pos) { rewind_pos = pos; }
66
+
67
+ // / defines the start position at the beginning
66
68
void setStartPos (int pos) { start_pos = pos; }
67
69
68
70
// / optionally defines the requested playing size in bytes
@@ -107,10 +109,10 @@ template <class FileType> class FileLoopT : public BaseStream {
107
109
int result2 = 0 ;
108
110
int open = copy_len - result1;
109
111
if (isLoopActive () && open > 0 ) {
110
- if (start_pos < 0 ) start_pos = 0 ;
111
- LOGI (" seek %d" , start_pos );
112
+ if (rewind_pos < 0 ) rewind_pos = 0 ;
113
+ LOGI (" seek %d" , rewind_pos );
112
114
// looping logic -> rewind to beginning: read step 2
113
- current_file.seek (start_pos );
115
+ current_file.seek (rewind_pos );
114
116
// notify user
115
117
if (callback!=nullptr ){
116
118
callback (*this );
@@ -139,7 +141,8 @@ template <class FileType> class FileLoopT : public BaseStream {
139
141
size_t write (const uint8_t * data, size_t len) { return current_file.write (data, len);}
140
142
141
143
protected:
142
- int start_pos = -1 ;
144
+ int rewind_pos = -1 ;
145
+ int start_pos = 0 ;
143
146
int loop_count = -1 ;
144
147
int size_open = -1 ;
145
148
int total_size = -1 ;
0 commit comments