Skip to content

Commit

Permalink
[databrowser] handle negative region starts
Browse files Browse the repository at this point in the history
  • Loading branch information
janscience committed Jul 17, 2024
1 parent 87ec9b3 commit d42f567
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHNAGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v2.2

- Fixed clearing of analysis data
- Handle selected regions that start at negative times or end beyond the data


## v2.1 - 2024.07.04
Expand Down
13 changes: 13 additions & 0 deletions src/audian/databrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,9 @@ def play_region(self, t0, t1):
rate = data.rate
i0 = int(np.round(t0*rate))
i1 = int(np.round(t1*rate))
if i0 < 0:
i0 = 0
t0 = 0.0
if i1 > len(data):
i1 = len(data)
t1 = i1/rate
Expand Down Expand Up @@ -1687,6 +1690,10 @@ def mark_audio(self):


def analyze_region(self, t0, t1, channel):
if t0 < 0:
t0 = 0
if t1 > self.data.data.frames/self.data.data.rate:
t1 = self.data.data.frames/self.data.data.rate
traces = self.data.get_region(t0, t1, channel)
for a in self.analyzers:
a.analyze(t0, t1, channel, traces)
Expand Down Expand Up @@ -1789,6 +1796,12 @@ def secs_to_str(time):

i0 = int(np.round(t0*self.data.rate))
i1 = int(np.round(t1*self.data.rate))
if i0 < 0:
i0 = 0
t0 = 0.0
if i1 > len(self.data.data):
i1 = len(self.data.data)
t1 = i1/rate
name = os.path.splitext(os.path.basename(self.data.file_path))[0]
#if self.channel > 0:
# filename = f'{name}-{channel:d}-{t0:.4g}s-{t1s:.4g}s.wav'
Expand Down

0 comments on commit d42f567

Please sign in to comment.