Background music stops when playing 3D sounds #32096

Closed
opened 2012-07-13 17:15:49 +02:00 by Alex Fraser · 14 comments
Member

Category: Audio

%%%If a game plays 3D sounds, a looping 2D music track might stop playing.

Attached is a demo file (bg_music_test2.zip). It contains:

  • One 2D sound that plays in a loop (bird squawking), started with aud via Python
  • Three 3D sounds that play in a repeating sequence (squeaking noise), started from three different Sound actuators.

If you start the game, the bird should squawk endlessly. But instead, it stops after a few times. The number of times it squawks changes. On my computer it usually stops before it reaches 20. It doesn't wait until the end of a loop before stopping.

Because the test uses 3 sound actuators, I think this test could only ever try to play 4 sounds at once.

Workaround: change the 3D sounds to 2D.

Sorry about the slightly annoying choice of sound samples!

Versions:
Blender: 2.63a, 2.62, 2.61, 2.60a, 2.63.14 r48871
alsa-base 1.0.25+dfsg-0ubuntu1
pulseaudio 1:1.1-0ubuntu15.1
libopenal1: 1.13-2
libsdl1.2debian-pulseaudio: 1.2.14-6.1ubuntu4
libpulse0: 1.0-0ubuntu3.1
OS: Ubuntu 12.04 (64-bit)
Sound cards (happens with all):

  • USB: Bus 001 Device 028: ID 046d:ba05 Logitech, Inc. ("PureFi Mobile")
  • PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 06)
  • PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 05)
    CPU: Intel Core i5 U 430%%%
**Category**: Audio %%%If a game plays 3D sounds, a looping 2D music track might stop playing. Attached is a demo file (bg_music_test2.zip). It contains: - One 2D sound that plays in a loop (bird squawking), started with aud via Python - Three 3D sounds that play in a repeating sequence (squeaking noise), started from three different Sound actuators. If you start the game, the bird should squawk endlessly. But instead, it stops after a few times. The number of times it squawks changes. On my computer it usually stops before it reaches 20. It doesn't wait until the end of a loop before stopping. Because the test uses 3 sound actuators, I think this test could only ever try to play 4 sounds at once. Workaround: change the 3D sounds to 2D. Sorry about the slightly annoying choice of sound samples! Versions: Blender: 2.63a, 2.62, 2.61, 2.60a, 2.63.14 r48871 alsa-base 1.0.25+dfsg-0ubuntu1 pulseaudio 1:1.1-0ubuntu15.1 libopenal1: 1.13-2 libsdl1.2debian-pulseaudio: 1.2.14-6.1ubuntu4 libpulse0: 1.0-0ubuntu3.1 OS: Ubuntu 12.04 (64-bit) Sound cards (happens with all): - USB: Bus 001 Device 028: ID 046d:ba05 Logitech, Inc. ("PureFi Mobile") - PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 06) - PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 05) CPU: Intel Core i5 U 430%%%
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Member

%%%Not a bug. This is a limitation by OpenGL and is plattform depended. If it runs out of sounds it can play at once, it just stops the oldest ones, you have to limit your number sounds played at the same time!%%%

%%%Not a bug. This is a limitation by OpenGL and is plattform depended. If it runs out of sounds it can play at once, it just stops the oldest ones, you have to limit your number sounds played at the same time!%%%

%%%Joerg, is there a way to get how many 'available' sounds left the game can use? That would be a way to prevent that from the Python side%%%

%%%Joerg, is there a way to get how many 'available' sounds left the game can use? That would be a way to prevent that from the Python side%%%
Author
Member

%%%Exactly. I accept that there's a limit to the number of sounds, but how can I make sure my music is never killed? The only way I can see to do it now is to keep my own register of playing handles, and poll each for its status - and even then, I would have to guess at how many can be played at once. What would be really nice is to have a system of priorities, something like:

dev.play(factory, priority)

such that a new sound would never replace an already playing sound with a higher priority. What do you think?%%%

%%%Exactly. I accept that there's a limit to the number of sounds, but how can I make sure my music is never killed? The only way I can see to do it now is to keep my own register of playing handles, and poll each for its status - and even then, I would have to guess at how many can be played at once. What would be really nice is to have a system of priorities, something like: dev.play(factory, priority) such that a new sound would never replace an already playing sound with a higher priority. What do you think?%%%
Member

%%%Well, priorities is an API layer above what audaspace currently supports. It's possible with OpenAL to get a hint about how many sources might be supported, but not a definite number/guarantee. For now you should best limit your sounds to 32 at the same time maximum.%%%

%%%Well, priorities is an API layer above what audaspace currently supports. It's possible with OpenAL to get a hint about how many sources might be supported, but not a definite number/guarantee. For now you should best limit your sounds to 32 at the same time maximum.%%%
Author
Member

%%%Hmm, I'm sure this is happening in my game with very few sounds playing - about 2-4 sounds, I think, including the music. But I'm having trouble putting together a repeatable test case. Can you recommend a strategy for debugging? Maybe a couple of places to add printf statements to the code?%%%

%%%Hmm, I'm sure this is happening in my game with very few sounds playing - about 2-4 sounds, I think, including the music. But I'm having trouble putting together a repeatable test case. Can you recommend a strategy for debugging? Maybe a couple of places to add printf statements to the code?%%%
Author
Member

%%%OK, I think I have a good test now; see bg_music_test2.zip. It has:

  • One 2D sound that plays in a loop (bird squawking), started with aud via Python
  • Three 3D sounds that play in a repeating sequence (squeaking noise), started from three different Sound actuators.

If you start the game, the bird should squawk endlessly. But instead, it stops after a few times. The number of times it squawks changes. On my computer it usually stops before it reaches 20. It doesn't wait until the end of a loop before stopping.

Because the test uses 3 sound actuators, I'm pretty sure this test could only ever try to play 4 sounds at once. Is that right?

Sorry about the slightly annoying choice of sound samples!

Versions:
Blender 2.63.14 r48921
Ubuntu 12.04 (64-bit)
alsa-base 1.0.25+dfsg-0ubuntu1
pulseaudio 1:1.1-0ubuntu15.1

Sound cards (happens with both):

  • USB: Bus 001 Device 028: ID 046d:ba05 Logitech, Inc. ("PureFi Mobile")
  • PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 06)

Probably not important: sometimes I get the following message printed to the console:

  AL lib: pulseaudio.c:331: PulseAudio returned minreq > tlength/2; expect break up

If I restart pulseaudio that message goes away, but the test still fails (bird stops squawking).%%%

%%%OK, I think I have a good test now; see bg_music_test2.zip. It has: - One 2D sound that plays in a loop (bird squawking), started with aud via Python - Three 3D sounds that play in a repeating sequence (squeaking noise), started from three different Sound actuators. If you start the game, the bird should squawk endlessly. But instead, it stops after a few times. The number of times it squawks changes. On my computer it usually stops before it reaches 20. It doesn't wait until the end of a loop before stopping. Because the test uses 3 sound actuators, I'm pretty sure this test could only ever try to play 4 sounds at once. Is that right? Sorry about the slightly annoying choice of sound samples! Versions: Blender 2.63.14 r48921 Ubuntu 12.04 (64-bit) alsa-base 1.0.25+dfsg-0ubuntu1 pulseaudio 1:1.1-0ubuntu15.1 Sound cards (happens with both): - USB: Bus 001 Device 028: ID 046d:ba05 Logitech, Inc. ("PureFi Mobile") - PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 06) Probably not important: sometimes I get the following message printed to the console: ``` AL lib: pulseaudio.c:331: PulseAudio returned minreq > tlength/2; expect break up ``` If I restart pulseaudio that message goes away, but the test still fails (bird stops squawking).%%%
Author
Member

%%%I've done some testing with more versions. The official releases are harder to trigger the bug in. They tend to take longer, and sometimes it's necessary to restart Blender to get the bug to trigger. Doing other things like switching between windows seemed to make it more likely to trigger.
Official releases tested: 2.63a, 2.62, 2.61, 2.60a
Also 2.63 r49322 from http://builder.blender.org/download/blender-2.63-r49322-linux-glibc27-x86_64.tar.bz2

I couldn't get the bug to trigger in 2.59.%%%

%%%I've done some testing with more versions. The official releases are harder to trigger the bug in. They tend to take longer, and sometimes it's necessary to restart Blender to get the bug to trigger. Doing other things like switching between windows seemed to make it more likely to trigger. Official releases tested: 2.63a, 2.62, 2.61, 2.60a Also 2.63 r49322 from http://builder.blender.org/download/blender-2.63-r49322-linux-glibc27-x86_64.tar.bz2 I couldn't get the bug to trigger in 2.59.%%%
Author
Member

%%%I just confirmed this bug on another computer running Ubuntu 12.04 with Blender 2.63a.

Sound card (similar to mine, but different revision)

  • PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 05)

Versions:
Blender: 2.63a
libopenal1: 1.13-2
libsdl1.2debian-pulseaudio: 1.2.14-6.1ubuntu4
libpulse0: 1.0-0ubuntu3.1

I also compiled a fresh checkout of OpenAL Soft 1.14. It fails too.

Reopening this ticket; I hope you don't mind. If you think this is a problem in one of the libraries, I could file a bug on Launchpad too.%%%

%%%I just confirmed this bug on another computer running Ubuntu 12.04 with Blender 2.63a. Sound card (similar to mine, but different revision) - PCI: 00:1b.0 Audio device: Intel Corporation 5 Series/3400 Series Chipset High Definition Audio (rev 05) Versions: Blender: 2.63a libopenal1: 1.13-2 libsdl1.2debian-pulseaudio: 1.2.14-6.1ubuntu4 libpulse0: 1.0-0ubuntu3.1 I also compiled a fresh checkout of OpenAL Soft 1.14. It fails too. Reopening this ticket; I hope you don't mind. If you think this is a problem in one of the libraries, I could file a bug on Launchpad too.%%%
Author
Member

%%%Cleaned up description, and removed rejected test case.%%%

%%%Cleaned up description, and removed rejected test case.%%%
Author
Member

%%%Adding a new test case that uses only aud via Python; no Sound actuators: see bg_music_test3.zip

In this test, aud.Handle.location is used to set the location of the 3D sounds. The locations are updated repeatedly after the sounds start. The script as uploaded updates the locations 1000 times per logic tick, which is very likely to trigger the bug - but on my machine, it happens even when only updating the locations once per tick. You can change the frequency by editing the "range" expression on line 80.

What seems to happen is this: if the location of a sound is changed just as it finishes playing, some other sound will be killed. In this test, the string "W: Tried to set position of stopped sound" is printed when the bug is triggered. It is not triggered if the sound has already been stopped for a while; to test this, comment out the "continue" statement on line 71.

Workaround: This seems to be a race condition. It seems to be fixed by locking:

  1. Lock the device.
  2. Test Handle.status. If the sound has stopped, skip the next step.
  3. Set Handle.location.
  4. Unlock the device.

The test includes the workaround; to see it in action, attach the "Always" sensor to the "SAFE" controller instead of the "BUG" controller.%%%

%%%Adding a new test case that uses only aud via Python; no Sound actuators: see bg_music_test3.zip In this test, aud.Handle.location is used to set the location of the 3D sounds. The locations are updated repeatedly after the sounds start. The script as uploaded updates the locations 1000 times per logic tick, which is very likely to trigger the bug - but on my machine, it happens even when only updating the locations once per tick. You can change the frequency by editing the "range" expression on line 80. What seems to happen is this: if the location of a sound is changed just as it finishes playing, some other sound will be killed. In this test, the string "W: Tried to set position of stopped sound" is printed when the bug is triggered. It is not triggered if the sound has already been stopped for a while; to test this, comment out the "continue" statement on line 71. Workaround: This seems to be a race condition. It seems to be fixed by locking: 1. Lock the device. 2. Test Handle.status. If the sound has stopped, skip the next step. 3. Set Handle.location. 4. Unlock the device. The test includes the workaround; to see it in action, attach the "Always" sensor to the "SAFE" controller instead of the "BUG" controller.%%%
Member

%%%Hey!

I tried your file and could trigger the bug finally. I've implemented a fix in revision 51599, could you check if it works for you? If not reopen the bug please.

Regards%%%

%%%Hey! I tried your file and could trigger the bug finally. I've implemented a fix in revision 51599, could you check if it works for you? If not reopen the bug please. Regards%%%
Member

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Member

%%%Hi Joerg! Thanks for the fix. I just tested it again in r51726, and it works fine on my computer.

Cheers :-)%%%

%%%Hi Joerg! Thanks for the fix. I just tested it again in r51726, and it works fine on my computer. Cheers :-)%%%
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#32096
No description provided.