fix stereo timeline
This commit is contained in:
parent
716612999c
commit
79541dc38e
1 changed files with 35 additions and 37 deletions
|
@ -13,8 +13,8 @@ import gst
|
|||
|
||||
|
||||
class Audio(gst.Pipeline):
|
||||
_left = []
|
||||
_right = []
|
||||
left = []
|
||||
right = []
|
||||
position = 0
|
||||
|
||||
def __init__(self, uri, samplerate=22050, channels=2):
|
||||
|
@ -66,51 +66,49 @@ class Audio(gst.Pipeline):
|
|||
samples = int(buff.size // 2 / self.channels)
|
||||
fmt = "<" + str(samples) + "h"
|
||||
|
||||
left = unpack(fmt, buff.data[:2*samples])
|
||||
left = self._left + list(left)
|
||||
|
||||
right = unpack(fmt, buff.data[2*samples:])
|
||||
right = self._right + list(right)
|
||||
data = unpack(fmt, buff.data[:2*samples]) + unpack(fmt, buff.data[2*samples:])
|
||||
n = 0
|
||||
for i in data:
|
||||
if n%2 == 0:
|
||||
self.left.append(i)
|
||||
else:
|
||||
self.right.append(i)
|
||||
n += 1
|
||||
|
||||
samples_per_pixel = int(self.samplerate / self.framerate)
|
||||
while len(left) > samples_per_pixel:
|
||||
pixel = left[:samples_per_pixel]
|
||||
pixel = np.asarray(pixel)
|
||||
left = left[samples_per_pixel:]
|
||||
|
||||
l = np.sum(np.abs(pixel)) / samples_per_pixel
|
||||
l = int(l / 256)
|
||||
lheight = int((l * self.tile_height) / 256) * 2
|
||||
if l: l += 20
|
||||
l = (l, l, l, 255)
|
||||
|
||||
pixel = right[:samples_per_pixel]
|
||||
pixel = np.asarray(pixel)
|
||||
right = right[samples_per_pixel:]
|
||||
|
||||
r = np.sum(np.abs(pixel)) / samples_per_pixel
|
||||
r = int(r / 256)
|
||||
rheight = int((r * self.tile_height) / 256) * 2
|
||||
if r: r += 20
|
||||
r = (r, r, r, 255)
|
||||
|
||||
while len(self.left) > samples_per_pixel:
|
||||
tile = int(math.floor(float(self.position) / self.input_tile_width))
|
||||
tilePos = int(self.position - (tile * self.input_tile_width))
|
||||
|
||||
lcrop = int((self.tile_height-lheight) / 2)
|
||||
rcrop = int((self.tile_height-rheight) / 2)
|
||||
def plot(p, start):
|
||||
p = int(p / 256)
|
||||
height = int((p * self.tile_height) / 256) * 2
|
||||
crop = int((self.tile_height-height) / 2)
|
||||
if p: p += 20
|
||||
p = (p, p, p, 255)
|
||||
|
||||
for i in range(lcrop, int(self.tile_height/2)):
|
||||
self.tiles[tile].putpixel((tilePos, i), l)
|
||||
if start:
|
||||
end = self.tile_height - crop
|
||||
else:
|
||||
start = crop
|
||||
end = int(self.tile_height/2)
|
||||
for i in range(start, end):
|
||||
self.tiles[tile].putpixel((tilePos, i), p)
|
||||
|
||||
for i in range(int(self.tile_height/2), self.tile_height-rcrop):
|
||||
self.tiles[tile].putpixel((tilePos, i), r)
|
||||
#left
|
||||
pixel = np.asarray(self.left[:samples_per_pixel])
|
||||
self.left = self.left[samples_per_pixel:]
|
||||
p = np.sum(np.abs(pixel)) / samples_per_pixel
|
||||
plot(p, 0)
|
||||
|
||||
#right
|
||||
pixel = np.asarray(self.right[:samples_per_pixel])
|
||||
self.right = self.right[samples_per_pixel:]
|
||||
p = np.sum(np.abs(pixel)) / samples_per_pixel
|
||||
plot(p, int(self.tile_height/2))
|
||||
|
||||
self.position += 1
|
||||
|
||||
self._left = left
|
||||
self._right = right
|
||||
|
||||
if self.mainloop and timestamp >= self.duration:
|
||||
self.done()
|
||||
|
||||
|
|
Loading…
Reference in a new issue