audio.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:bubblesub 作者: rr- 项目源码 文件源码
def _draw_spectrogram(self, painter, _event):
        width = painter.viewport().width()
        height = (1 << DERIVATION_SIZE) + 1

        pixels = np.zeros([width, height], dtype='byte')
        horizontal_res = (
            self._api.opt.general['audio']['spectrogram_resolution'])

        # since the task queue is a LIFO queue, in order to render the columns
        # left-to-right, they need to be iterated backwards (hence reversed()).
        for x in reversed(range(width)):
            pts = self._pts_from_x(x)
            pts = (pts // horizontal_res) * horizontal_res
            column = self._spectrum_cache.get(pts, NOT_CACHED)
            if column is NOT_CACHED:
                self._spectrum_provider.schedule_task(pts)
                self._spectrum_cache[pts] = CACHING
                continue
            if column is CACHING:
                continue
            pixels[x] = column

        pixels = pixels.transpose().copy()
        image = QtGui.QImage(
            pixels.data,
            pixels.shape[1],
            pixels.shape[0],
            pixels.strides[0],
            QtGui.QImage.Format_Indexed8)
        image.setColorTable(self._color_table)
        painter.save()
        painter.scale(1, painter.viewport().height() / (height - 1))
        painter.drawPixmap(0, 0, QtGui.QPixmap.fromImage(image))
        painter.restore()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号