使用 PyOpenAL 时正确的清理方法是什么?

发布于 2024-07-17 06:24:48 字数 669 浏览 7 评论 0原文

我正在寻找 PyOpenAL 来满足 Python 的一些声音需求(显然)。 文档很少(由演示脚本组成,未经修改就无法工作),但据我所知,有两层。 直接包装 OpenAL 调用和轻量级“pythonic”包装器 - 我关心的是后者。 具体来说,如何正确清理呢? 如果我们举一个小例子:

import time

import pyopenal

pyopenal.init(None)

l = pyopenal.Listener(22050)

b = pyopenal.WaveBuffer("somefile.wav")
s = pyopenal.Source()
s.buffer = b
s.looping = False

s.play()

while s.get_state() == pyopenal.AL_PLAYING:
    time.sleep(1)

pyopenal.quit()

事实上,一条消息被打印到终端上,内容是“一个源未删除,一个缓冲区未删除”。 但我假设我们无法对这些对象使用本机 OpenAL 调用,那么如何正确清理呢?

编辑:

我最终放弃了 pyopenal,并在 OpenAL 和 alure 上编写了一个小的 ctypes 包装器(pyopenal 公开了直接的 OpenAL 函数,但我不断收到 SIGFPE)。 仍然好奇我应该在这里做什么。

I'm looking at PyOpenAL for some sound needs with Python (obviously). Documentation is sparse (consisting of a demo script, which doesn't work unmodified) but as far as I can tell, there are two layers. Direct wrapping of OpenAL calls and a lightweight 'pythonic' wrapper - it is the latter I'm concerned with. Specifically, how do you clean up correctly? If we take a small example:

import time

import pyopenal

pyopenal.init(None)

l = pyopenal.Listener(22050)

b = pyopenal.WaveBuffer("somefile.wav")
s = pyopenal.Source()
s.buffer = b
s.looping = False

s.play()

while s.get_state() == pyopenal.AL_PLAYING:
    time.sleep(1)

pyopenal.quit()

As it is, a message is printed on to the terminal along the lines of "one source not deleted, one buffer not deleted". But I am assuming the we can't use the native OpenAL calls with these objects, so how do I clean up correctly?

EDIT:

I eventually just ditched pyopenal and wrote a small ctypes wrapper over OpenAL and alure (pyopenal exposes the straight OpenAL functions, but I kept getting SIGFPE). Still curious as to what I was supposed to do here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-07-24 06:24:48
#relese reference to l b and s
del l
del b
del s 
#now the WaveBuffer and Source should be destroyed, so we could:
pyopenal.quit()

pyopenal 的析构函数可能在退出之前调用 quit() ,因此您不需要自己调用它。

#relese reference to l b and s
del l
del b
del s 
#now the WaveBuffer and Source should be destroyed, so we could:
pyopenal.quit()

Probably de destructor of pyopenal calls quit() before exit so you dont need to call it yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文