Skip to content

Commit ddf2c5e

Browse files
authored
Update 0.4.0 (#10)
- Fixed an error that occurs when a track segment is smaller than the required size
2 parents 482e6d9 + 4af4152 commit ddf2c5e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "seaplayer-audio"
3-
version = "0.3.10"
3+
version = "0.4.0"
44
description = "A library for async/sync playback audio."
55
repository = "https://github.com/romanin-rf/seaplayer-audio"
66
authors = ["Romanin <60302782+romanin-rf@users.noreply.github.com>"]

seaplayer_audio/streamers/callbackstreamersnd.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ def __callback__(self, outdata: ndarray, frames: int, time, status):
3939
d = self.queue.get_nowait()
4040
except:
4141
return
42-
wdata = d[:frames]
43-
self.buffer = d[frames:]
42+
if len(d) >= frames:
43+
wdata = d[:frames]
44+
self.buffer = d[frames:]
45+
else:
46+
wdata = npvstack([d, npzeros((frames - len(d), self.channels), dtype=outdata.dtype)])
4447
elif len(self.buffer) >= frames:
4548
wdata = self.buffer[:frames]
4649
self.buffer = self.buffer[frames:]
@@ -54,6 +57,8 @@ def __callback__(self, outdata: ndarray, frames: int, time, status):
5457
needed = frames - len(wdata)
5558
wdata = npvstack([wdata, d[:needed]])
5659
self.buffer = d[needed:]
60+
if len(wdata) < frames:
61+
wdata = npvstack([wdata, npzeros((frames - len(wdata), self.channels), dtype=outdata.dtype)])
5762
elif (len(self.buffer) < frames) and self.queue.empty():
5863
wdata = self.buffer.copy()
5964
self.buffer = None
@@ -130,8 +135,11 @@ def __callback__(self, outdata: ndarray, frames: int, time, status):
130135
d = asyncio.run_coroutine_threadsafe(self.queue.get_nowait(), self.loop).result()
131136
except:
132137
return
133-
wdata = d[:frames]
134-
self.buffer = d[frames:]
138+
if len(d) >= frames:
139+
wdata = d[:frames]
140+
self.buffer = d[frames:]
141+
else:
142+
wdata = npvstack([d, npzeros((frames - len(d), self.channels), dtype=outdata.dtype)])
135143
elif len(self.buffer) >= frames:
136144
wdata = self.buffer[:frames]
137145
self.buffer = self.buffer[frames:]
@@ -145,6 +153,8 @@ def __callback__(self, outdata: ndarray, frames: int, time, status):
145153
needed = frames - len(wdata)
146154
wdata = npvstack([wdata, d[:needed]])
147155
self.buffer = d[needed:]
156+
if len(wdata) < frames:
157+
wdata = npvstack([wdata, npzeros((frames - len(wdata), self.channels), dtype=outdata.dtype)])
148158
elif (len(self.buffer) < frames) and self.queue.empty():
149159
wdata = self.buffer.copy()
150160
self.buffer = None

0 commit comments

Comments
 (0)