Skip to content

Commit 1b76652

Browse files
committed
fixed cue() function
Fixed the cue() function by: 1. correcting the offset formular 2. correcting the return parameter For the function to work reliably the plyback has to be paused before! The pause call and resume can be embeded in the function... But thats a decision for the Arduino Team! If it isnt embeded the documentation has to be updated!
1 parent ce85b71 commit 1b76652

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/SDWaveFile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ long SDWaveFile::currentTime()
141141
int SDWaveFile::cue(long time)
142142
{
143143
if (time < 0) {
144-
return 1;
144+
return 0;
145145
}
146146

147-
long offset = (time * _blockAlign) - _dataOffset;
147+
long offset = (time * _blockAlign * _sampleRate) + _dataOffset;
148148

149149
if (offset < 0) {
150150
offset = 0;
@@ -154,12 +154,12 @@ int SDWaveFile::cue(long time)
154154
offset = (offset / 512) * 512;
155155

156156
if ((uint32_t)offset > _file.size()) {
157-
return 1;
157+
return 0;
158158
}
159159

160160
_file.seek(offset);
161-
162-
return 0;
161+
162+
return 1;
163163
}
164164

165165
int SDWaveFile::begin()

0 commit comments

Comments
 (0)