Closed GoogleCodeExporter closed 9 years ago
Can't replicate it here (I have a Creative Audigy 4); I suspect there's a
hardware
limitation on buffer size.
See if you can get past the error (audio will be broken) by changing the value
of
int(self._buffer_time * audio_format.sample_rate)
at pyglet/media/drivers/alsa/__init__.py:97. I imagine the number needs to be
either
smaller, larger, or aligned to some number (for example, a multiple of 4).
If this is the case, we need to find the appropriate ALSA magic that gives the
constraints.
Original comment by Alex.Hol...@gmail.com
on 2 Oct 2007 at 1:02
8192 gets passed it. I get about 4-6 ball bounce sounds before I get the
following trace.
4096 also works but only get 1 bounce.
16384 gives the original trace.
Traceback (most recent call last):
File "noisy.py", line 85, in <module>
ball.update(dt)
File "noisy.py", line 47, in update
sound.play()
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 377, in play
player.queue(self)
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 692, in queue
self._begin_source()
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 775, in _begin_source
self._fill_audio()
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 628, in _fill_audio
self._audio.write(audio_data)
File "/home/ajones/dev/pyglet/pyglet/media/drivers/alsa/__init__.py", line 146, in
write
check(asound.snd_pcm_delay(self.pcm, delay))
File "/home/ajones/dev/pyglet/pyglet/media/drivers/alsa/__init__.py", line 56, in check
raise ALSAException(asound.snd_strerror(err))
pyglet.media.drivers.alsa.ALSAException: Broken pipe
Original comment by andy.lar...@gmail.com
on 2 Oct 2007 at 1:45
Also the value I was getting for int(self._buffer_time *
audio_format.sample_rate)
was 13230
Original comment by andy.lar...@gmail.com
on 2 Oct 2007 at 1:48
This is the error that I was getting too (see
http://groups.google.com/group/pyglet-users/web/sound-under-ubuntu-feisty for
details
on switching to openal). I can have a dig around when I get home tonight and
see if I
can shed more light.
Original comment by anthony....@gmail.com
on 3 Oct 2007 at 12:34
My error is actually on the line above (95), but they may be related. I put the
following debug statements into pyglet/media/drivers/alsa/__init__.py:95:
print "Sample rate is:", audio_format.sample_rate
print asound.snd_pcm_hw_params_set_rate(self.pcm, self.hwparams,
audio_format.sample_rate, 0)
check(asound.snd_pcm_hw_params_set_rate(self.pcm, self.hwparams,
audio_format.sample_rate, 0))
And got the following output:
Sample rate is: 44100
-22
Traceback (most recent call last):
File "./test.py", line 6, in <module>
bullet_sound.play()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 377, in play
player.queue(self)
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 692, in queue
self._begin_source()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 774, in
_begin_source
self._create_audio()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 607, in
_create_audio
self._audio = audio_player_class(source.audio_format)
File "/usr/lib/python2.5/site-packages/pyglet/media/drivers/alsa/__init__.py", line
97, in __init__
audio_format.sample_rate, 0))
File "/usr/lib/python2.5/site-packages/pyglet/media/drivers/alsa/__init__.py", line
56, in check
raise ALSAException(asound.snd_strerror(err))
pyglet.media.drivers.alsa.ALSAException: Invalid argument
Other factors:
This is against the latest release (r1308), running on Ubuntu Feisty.
My sound card is also quite old, so your earlier hunch about buffer size may be
right:
00:08.0 Multimedia audio controller: Ensoniq 5880 AudioPCI (rev 02)
Subsystem: Ensoniq Creative SoundBlaster AudioPCI 128
Flags: bus master, slow devsel, latency 64, IRQ 11
I/O ports at e800 [size=64]
Capabilities: [dc] Power Management version 1
Hope that helps track down what's going on -- let me know if you need any more
info.
Original comment by anthony....@gmail.com
on 3 Oct 2007 at 1:27
I've added some commented experimental code to r1309 to address both the buffer
size
and the sample rate problems. Before starting, set an environment variable
PYGLET_DEBUG_MEDIA to 1; this will print some things to stdout as well as
create an
alsa.log file.
Try commenting/uncommenting code in pyglet/media/drivers/alsa/__init__.py around
lines 97 and 122 according to the comments and log what happens.
Apologies for the experimental nature of this... experiment!
Original comment by Alex.Hol...@gmail.com
on 3 Oct 2007 at 3:15
Well, the change seems to work for me (I can hear sound with ALSA), although
from the
output and looking at the new code I'm not sure what it's changing:
anthony@anthony:~/pyglet/pyglet/examples/astraea$ python test.py
Requested sample rate 44100
Actual sample rate 44100
Requested buffer size 13230
Actual buffer size 13230
That's the same sample rate that I had before, but
asound.snd_pcm_hw_params_set_rate_near(...) obviously isn't returning an error
code.
I've played around with the commented out code, but both
asound.snd_pcm_hw_params_set_rate and
asound.snd_pcm_hw_params_set_rate_resample both
cause errors.
I've attached my test file - I've been running it from within the astraea
directory.
Original comment by anthony....@gmail.com
on 4 Oct 2007 at 9:14
Attachments:
Ok, sounds promising. Can you attach the alsa.log file (from the set_rate_near
run) as well?
Original comment by Alex.Hol...@gmail.com
on 4 Oct 2007 at 9:22
I updated to r1309 and now I'm getting this:
ajones@dill ~/dev/pyglet/examples/noisy $ python noisy.py
Traceback (most recent call last):
File "noisy.py", line 85, in <module>
ball.update(dt)
File "noisy.py", line 47, in update
sound.play()
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 377, in play
player.queue(self)
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 692, in queue
self._begin_source()
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 774, in _begin_source
self._create_audio()
File "/home/ajones/dev/pyglet/pyglet/media/__init__.py", line 607, in _create_audio
self._audio = audio_player_class(source.audio_format)
File "/home/ajones/dev/pyglet/pyglet/media/drivers/alsa/__init__.py", line 85, in
__init__
asound.SND_PCM_NONBLOCK))
File "/home/ajones/dev/pyglet/pyglet/media/drivers/alsa/__init__.py", line 58, in check
raise ALSAException(asound.snd_strerror(err))
pyglet.media.drivers.alsa.ALSAException: Device or resource busy
python: pcm.c:695: snd_pcm_close: Assertion `pcm' failed.
Aborted (core dumped)
Original comment by andy.lar...@gmail.com
on 4 Oct 2007 at 9:37
Attached alsa.log file
Original comment by anthony....@gmail.com
on 4 Oct 2007 at 9:56
Attachments:
Hmm, spoke too soon. I get the same error message that Larry's getting. It
seems to
happen if more than one sound tries to play at the same time. It's repeatable -
I can
trigger it by either adding lots of balls, or waiting until the ball hits the
corner
(strikes two walls in quick succession).
Here's my traceback:
anthony@anthony:~/pyglet/pyglet/examples/noisy$ python noisy.py
Traceback (most recent call last):
File "noisy.py", line 85, in <module>
ball.update(dt)
File "noisy.py", line 44, in update
sound.play()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 377, in play
player.queue(self)
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 692, in queue
self._begin_source()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 774, in
_begin_source
self._create_audio()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 607, in
_create_audio
self._audio = audio_player_class(source.audio_format)
File "/usr/lib/python2.5/site-packages/pyglet/media/drivers/alsa/__init__.py", line
85, in __init__
asound.SND_PCM_NONBLOCK))
File "/usr/lib/python2.5/site-packages/pyglet/media/drivers/alsa/__init__.py", line
58, in check
raise ALSAException(asound.snd_strerror(err))
pyglet.media.drivers.alsa.ALSAException: Device or resource busy
python: pcm.c:695: snd_pcm_close: Assertion `pcm' failed.
Aborted (core dumped)
Original comment by anthony....@gmail.com
on 4 Oct 2007 at 10:15
Ok, Anthony's alsa.log shows that the sample rate that's actually being used is
44101
instead of the 44100 that we requested. So it seems that using *_near() is a
good
solution that fixes this problem (at least).
Device/resource busy at that point (line 85) can only occur when there are no
more
audio buffers. I was under the impression that the plug:front device creates
software-mixed buffers when there are no more hardware buffers available (it's
clear
that both of your audio cards have only a single audio buffer) -- it seems I was
mistaken. (Incidentally, I would guess that you're unable to play sound from
two
ALSA applications at a time?)
Andy: you should at least be able to play a single file now, am I correct?
(Since
this new failure is occurring at a point in the source before any of the
changes I
introduced).
Unless either of you has any additional information, I will look into
suppressing the
error when the buffer cannot be created (thus muting sounds when there's
insufficient
resources) and "locking-in" the changes to use *_near().
Original comment by Alex.Hol...@gmail.com
on 4 Oct 2007 at 10:40
> (Incidentally, I would guess that you're unable to play sound
> from two ALSA applications at a time?)
That seems to be the case - If you have a good way of determining that for sure
(and
it's worthwhile), I can try it.
Original comment by anthony....@gmail.com
on 4 Oct 2007 at 11:41
You could run aplay from two different terminals.
Original comment by Alex.Hol...@gmail.com
on 4 Oct 2007 at 12:03
I've run the following command in three terminal windows at once:
for ITEM in `ls`; do aplay res/27504.wav; done
And got multiple channels all going at once.
I tried to do the same thing with pyglet (see test.py), I get the same "python:
pcm.c:695: snd_pcm_close: Assertion `pcm' failed" error if I try and run the
sounds
too close together.
If I run test.py in a second window while the first is running, I also get the
same
Assertion error.
Original comment by anthony....@gmail.com
on 5 Oct 2007 at 12:00
Attachments:
Ok, try replacing "plug:front" on line 62 with "default" (this is the default
device
alsaplayer uses, according to the latest source).
Original comment by Alex.Hol...@gmail.com
on 5 Oct 2007 at 2:04
Can you let me know if replacing "plug:front" with "default" makes any
difference in playback of multiple audio
sources?
Original comment by Alex.Hol...@gmail.com
on 23 Oct 2007 at 1:58
Sorry, I have been a bit quiet - mostly RL issues -- standard excuse, I know :)
Changing to 'default' allows me to play multiple sounds - I have three going at
the
moment. I'll leave them running for the next little while and see if any of them
explode, but they've been going for a minute or two so far.
The sounds aren't 'syncronised', in that if I play two test.py scripts they'll
go in
and out of sync, but I don't think that's such a big deal :)
Original comment by anthony....@gmail.com
on 25 Oct 2007 at 9:45
Ok, I fixed up the bug in the previous test.py version (don't load your media
over
and over again in the main game loop) which seems to make it more stable.
However,
after a while I get the error below - 'Too many open files'. I've put in a
counter to
check when it happens - I've got 508 for the first run, and I'll run it again
and see
if that changes.
anthony@anthony:~/pyglet/pyglet-old/examples/astraea$ ./test.py
Playing sound...
ALSA lib pcm_dmix.c:914:(snd_pcm_dmix_open) unable to open slave
Error in sys.excepthook:
Traceback (most recent call last):
File "/var/lib/python-support/python2.5/apport_python_hook.py", line 30, in
apport_excepthook
import apport.report, apport.fileutils
File "/var/lib/python-support/python2.5/apport/__init__.py", line 1, in <module>
from apport.report import Report
ImportError: No module named report
Original exception was:
Traceback (most recent call last):
File "./test.py", line 15, in <module>
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 377, in play
player.queue(self)
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 695, in queue
self._begin_source()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 784, in
_begin_source
self._create_audio()
File "/usr/lib/python2.5/site-packages/pyglet/media/__init__.py", line 610, in
_create_audio
self._audio = audio_player_class(source.audio_format)
File "/usr/lib/python2.5/site-packages/pyglet/media/drivers/alsa/__init__.py", line
85, in __init__
asound.SND_PCM_NONBLOCK))
File "/usr/lib/python2.5/site-packages/pyglet/media/drivers/alsa/__init__.py", line
58, in check
raise ALSAException(asound.snd_strerror(err))
pyglet.media.drivers.alsa.ALSAException: Too many open files
python: pcm.c:695: snd_pcm_close: Assertion `pcm' failed.
Aborted (core dumped)
anthony@anthony:~/pyglet/pyglet-old/examples/astraea$
Original comment by anthony....@gmail.com
on 25 Oct 2007 at 10:33
Happened at 508 again, so I guess there's something not being closed properly in
ALSA/pyglet? I've attached my test script.
...
504
505
506
507
ALSA lib pcm_dmix.c:914:(snd_pcm_dmix_open) unable to open slave
Error in sys.excepthook:
Traceback (most recent call last):
...
Original comment by anthony....@gmail.com
on 25 Oct 2007 at 10:48
Attachments:
OK, "default" replaces "plug:front" in r1329. I can't reproduce the "Too many
open
files" error.
Original comment by Alex.Hol...@gmail.com
on 26 Oct 2007 at 1:29
Only remaining error is the "too many open files". I suspect this is an ALSA
bug,
we're closing all the PCM handles we open.
The ALSA driver is extremely substandard compared to OpenAL and DirectSound.
We have
no way to synchronise multiple sounds or to adjust the playback volume or pan.
There's nothing we can do about this without introducing a fast array module
(e.g.
numpy) for doing software audio mixing. I will make notes in the documentation
explaining the trade-off between using OpenAL and ALSA on Linux.
Original comment by Alex.Hol...@gmail.com
on 26 Oct 2007 at 2:21
I also get the following error in r1355 with my Audigy4 after shooting lots of
things
in astraea:
python: pcm_params.c:2276: snd_pcm_hw_refine: Assertion `pcm && params' failed.
Abort
Original comment by Alex.Hol...@gmail.com
on 4 Nov 2007 at 8:42
I get:
python2.5: pcm_params.c:2276: snd_pcm_hw_refine: Assertion `pcm && params'
failed.
Aborted
running noisy or astraea after snd_pcm_open has been called 5 times more oftem
than
snd_pcm_close.
Using alsa-lib-1.0.15-33.el4 and Multimedia audio controller: VIA
Technologies, Inc.
VT8233/A/8235/8237 AC97 Audio Controller (rev 60)
Original comment by elmar.me...@gmail.com
on 23 Dec 2007 at 10:56
Thanks for the report. You should have no problems with audio if you install
OpenAL (I am recommending this
to all Linux users now, as the ALSA problems seem insurmountable).
Original comment by Alex.Hol...@gmail.com
on 23 Dec 2007 at 11:58
I'm closing this bug since it is rather old and we need a clean list to follow
new issues. Can you retest the problem with a recent version and add the issue
again?
Original comment by winstonw...@gmail.com
on 22 Jun 2012 at 9:51
Original issue reported on code.google.com by
andy.lar...@gmail.com
on 2 Oct 2007 at 12:50