Skip to content

Commit

Permalink
Merge pull request #3689 from yh-luo/fix_truncated_sound
Browse files Browse the repository at this point in the history
BF: fixed the bug that setSound() incorrectly truncate the sound file
  • Loading branch information
peircej committed Mar 19, 2021
2 parents b1d932e + 1b536af commit 49cf52e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion psychopy/sound/backend_ptb.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def _setSndFromArray(self, thisArray):
"stereo. Shape={}".format(self.sndArr.shape))
self._nSamples = thisArray.shape[0]
if self.stopTime == -1:
self.stopTime = self._nSamples / float(self.sampleRate)
self.duration = self._nSamples / float(self.sampleRate)
# set to run from the start:
self.seek(0)
self.sourceType = "array"
Expand Down
4 changes: 2 additions & 2 deletions psychopy/sound/backend_sounddevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def _setSndFromArray(self, thisArray):
"stereo. Shape={}".format(self.sndArr.shape))
self._nSamples = thisArray.shape[0]
if self.stopTime == -1:
self.stopTime = self._nSamples/float(self.sampleRate)
self.duration = self._nSamples/float(self.sampleRate)
# set to run from the start:
self.seek(0)
self.sourceType = "array"
Expand Down Expand Up @@ -508,7 +508,7 @@ def stop(self, reset=True):
def _nextBlock(self):
if self.status == STOPPED:
return
samplesLeft = int((self.stopTime - self.t) * self.sampleRate)
samplesLeft = int((self.duration - self.t) * self.sampleRate)
nSamples = min(self.blockSize, samplesLeft)
if self.sourceType == 'file' and self.preBuffer == 0:
# streaming sound block-by-block direct from file
Expand Down

0 comments on commit 49cf52e

Please sign in to comment.