[Solved]Slow to stop/pause sound

deadvirus

01-09-2009 00:10:42

Hello,
I notice a little framebreak while pausing or stopping a sound. (I'm not sure if it happens too when I play, its hard to tell)

I create it this way:
//create sounds
mSoundMgr = OgreOggSound::OgreOggSoundManager::getSingletonPtr();
if(mShotSound = mSoundMgr->createSound(shotsNamePrefix + "_sound", "Shot10shots1sec.wav", false, true))
{
mShotSound->setPitch(2);
mPlaneNode->attachObject(mShotSound);
}


Play this way:
mSoundMgr->playSound(mShotSound->getName());

Pause this way:
mSoundMgr->pauseSound(mShotSound->getName());

I'm using the .dll version, multithreaded (at least, I did not change the macro...)

Thanks.

stickymango

01-09-2009 11:20:28

This is by design in the multi-threaded version.

What happens when you create a sound is that it is put into a cue to be handled by the extra thread to prevent the main application blocking, it also allows the sound manager to catch any events such as play/pause/stop requested immediately after creation.

The reason for this was to combat the pause/delay caused when creating them dynamically during your main update loop, it was unacceptable to me to have visual stutters when doing this, so I decided to use the extra thread to handle this in the background to prevent it.

Anything which needs to start immediately should be preloaded during initialisation allowing immediate playback, there is an optional flag ('preload') in createSound() to prefill the buffers with data at the point at which the sound is created, this is to allow immediate audio output on a subsequent call to play().

This is what is probably causing your delay as when you call play(), the buffers are empty and will need filling first.

HTH

deadvirus

01-09-2009 14:28:59

I've tested it with preBuffer set to true, and it is still not right... I still can see some frame break :S
I've also tested with a OGG file, with no luck...

stickymango

01-09-2009 14:43:54

Under what circumstances are you testing with?

Are you saying you are getting noticable frame stuttering or a delay between calling play and hearing sound?

deadvirus

01-09-2009 15:21:29

Under what circumstances are you testing with?

Are you saying you are getting noticable frame stuttering or a delay between calling play and hearing sound?


I notice a frame stuttering.. I've tested it on another computer to, and it behaves the same way...
I don't think there's a delay between play and hearing it... at least not a noticable delay...

The user presses the fire key wich will call the "fire" function. Inside this function I do this:

if(!mIsSoundPlaying)
{
mSoundMgr->playSound(mShotSound->getName());
mIsSoundPlaying = true;
}


Then, when the user releases the fire key, I call this:

void ShotsManager::stopFireSound()
{
if(mIsSoundPlaying)
mSoundMgr->pauseSound(mShotSound->getName());
mIsSoundPlaying = false;
}


EDIT: I've added play/pause keys to the "Two" sound on the TestDemo, and if you move (specially if you can see that Ogre Head moving), sometimes you will notive frame stuttering when play/pause.

if( arg.key == OIS::KC_A)
{
mSoundManager->playSound("Two");
}
if( arg.key == OIS::KC_B)
{
mSoundManager->pauseSound("Two");
}

stickymango

01-09-2009 15:42:05

I assume those functions are called once each not continuously?

I'll try and see if I can set up a test case to see if I can find a problem, are the pc systems quite high spec?

deadvirus

01-09-2009 15:48:23

I assume those functions are called once each not continuously?

I'll try and see if I can set up a test case to see if I can find a problem, are the pc systems quite high spec?


The fire function is called continuously while fireing (pressing fire key), but the "play" is not, because of the if(...) check... the stop function is called only when releases the fire key...

On the TestDemo they are only called when I press the keys...

Sometimes the "frame-break" is not notorious.. so you have to play/pause sometimes... If you play/pause quickly, you'll notice more...

The main pc system specs are:
-Creative X-Fi Titanium
-XFX GeForce 8800GT
-XFX nForce 780i
-Intel Core 2 Quad Q6600 @ 2.40GHz
-4GB Ram.

The other one is an "old" laptop... just for test purposes and stuff...

stickymango

01-09-2009 16:27:43

Okay, I shall debug the test demo and try to solve that..

deadvirus

01-09-2009 16:34:04

Thank you very much for the help, and most of all, for this library! :D

stickymango

01-09-2009 16:42:56

Your very welcome, I want to iron out any problems people come across :)

deadvirus

01-09-2009 23:27:46

Your very welcome, I want to iron out any problems people come across :)
If I can help, I will! :)
Any news on the problem?

stickymango

02-09-2009 09:29:09

Hi,

I've identified the problem, I think I might need to look at redesigning the library to get around the issue, but for now I've committed a temporary fix you can use for testing. If you don't require the non-blocking streaming fuctionality you could rebuild the lib without BOOSt and that should cure the problem also..

I'll try and remedy the situation asap but I need to have a think about the best approach, for now get the latest SVN and try that out or compile without BOOST.

sorry for the inconvenience.

stickymango

02-09-2009 15:58:00

Hi deadvirus,

see: http://www.ogre3d.org/addonforums/viewtopic.php?f=19&t=8588&start=30 for an updated version which hopefully fixes this issue, can you try it out and let me know if you experience any problems.

HTH.

deadvirus

02-09-2009 17:18:20

Thanks! I'll try that in a minute.
I will post the results ASAP.

EDIT: I don't notice any pause now :D I think it is solved :P
By the way, you did nice in removing the play/pause/stop from OgreOggISound, because it can lead to some errors, like forgetting that you should not use it and such...

stickymango

02-09-2009 20:09:14

Thats great news, I shall try to do some more testing to check stability but hopefully thats cured it for now, thanks for bringing it to my attention! :)

deadvirus

02-09-2009 23:10:26

Glad to help eheh.
I didn't notice any problem from the last change :)

Oh, there's another thing. Sometimes when you do muteAllSounds(), then when you unmute, the sounds wont come back... I can't duplicate the problem allways... so it's hard to tell what the problem really is... But since I've started using setMasterVolume, I didn't had that problem again..

stickymango

03-09-2009 08:14:22

Shall look into it.

[EDIT] I can't see anything obviously wrong with the code, it basically does the same thing as setMasterVolume() anyway, if you can establish the circumstances again that would be much appreciated. :?

thierryg

01-09-2011 16:01:00

Hi,

I experienced the same problem with muteAllSounds.
I used pauseAllSounds and muteAllSounds, and sometimes, I couldn't unMute the sounds at all. I tried everything, and at the end I used setMasterVolume (0) instead of MuteAllSounds, and setMasterVolume(1) instead of unMuteAllSounds, and everything worked perfectly.
I'm not sure of the proper way to reproduce the bug, though.

T.

shenjoku

22-12-2013 02:11:05

I'm having this same problem when rapidly using play/pause on sounds. Currently I'm trying to swap back and forth between music tracks based on events and when swapping between sounds it will hang the application and cause really bad sound stuttering, sometimes even leading to bad sound corruption (the music starts crackling really badly). All I'm doing is pausing the active sound and then playing the other one. I'm currently testing this on the latest code from SVN but the issue was already present in a previous released version 1.21. I'm also not currently using the multi-threaded functionality. Would turning that on fix the issue?

EDIT: I turned on multi-threading and it fixes the application hang but none of the stutter/crackle issues.

Edit2: I've narrowed down the problem a bit to the cal to alSourcePause() in OgreOggStreamSound::_pauseImpl(). For some reason that function call is getting stuck somewhere once in a while, which is causing the stutter. I can't really tell what since I can't get a clear callstack of the OpenAL functions so I'm not sure how to debug this further.

stickymango

06-01-2014 17:25:10

Is this problem only for streamed sounds, do static sounds behave correctly?

shenjoku

06-01-2014 21:24:31

Is this problem only for streamed sounds, do static sounds behave correctly?

I'm not sure. At the time I think I was only testing with streamed sounds so I'll give that a test sometime today and let you know.

EDIT: Just tested it with static sounds and it still has the stutter issues.

shenjoku

08-01-2014 20:18:19

I made some sample code for testing the stutter problem. Hopefully you can figure something out because I'm totally stumped. You'll need some test project building Ogre and OgreOggSound already and then you should be able to just add the source and the sound files and follow the instructions in the class documentation to test the issue. Source and test sounds can be found here. The sounds are some tracks from the Starbound soundtrack that I've been using just for testing the music system. This code is loosely based off of it, which is why it's using a different naming convention that the usual Ogre stuff, since that's what we're using everywhere. Shouldn't be too confusing though since it's a very simple class. Let me know if you can reproduce it with this or not.

stickymango

08-01-2014 22:31:14

Hi Shenjoku,

I tried implementing your test but I couldn't reproduce your problem, I tried limiting the update rate as low as 8fps and couldn't get any stuttering with the sounds, what pc spec do you have? I tried both static and streamed sounds and a combination of both and they played fine, does this issue occur straight away or is it over a period of time?

shenjoku

09-01-2014 00:36:49

The stutter is somewhat random, but it happens very often, nearly every time a sound is paused. In the sample I gave you the sound would nearly always stutter after starting the first sound, waiting a few seconds, and then switching to the next sound.

I was afraid it might be a hardware problem. I'm just using the on-board sound that comes with the motherboard. Here's my specs taken from CPU-Z:
Processors Information
-------------------------------------------------------------------------

Processor 1 ID = 0
Number of cores 4 (max 8)
Number of threads 8 (max 16)
Name Intel Core i7 930
Codename Bloomfield
Specification Intel(R) Core(TM) i7 CPU 930 @ 2.80GHz
Package (platform ID) Socket 1366 LGA (0x1)
CPUID 6.A.5
Extended CPUID 6.1A
Core Stepping D0
Technology 45 nm
Core Speed 2938.5 MHz
Multiplier x FSB 22.0 x 133.6 MHz
Rated Bus speed 3205.6 MHz
Stock frequency 2800 MHz
Instructions sets MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, EM64T, VT-x
L1 Data cache 4 x 32 KBytes, 8-way set associative, 64-byte line size
L1 Instruction cache 4 x 32 KBytes, 4-way set associative, 64-byte line size
L2 cache 4 x 256 KBytes, 8-way set associative, 64-byte line size
L3 cache 8 MBytes, 16-way set associative, 64-byte line size
FID/VID Control yes

Turbo Mode supported, enabled
Max non-turbo ratio 21x
Max turbo ratio 23x
Max efficiency ratio 12x
TDP Limit 130 Watts
TDC Limit 110 Amps
Core TDP 110 Watts
Uncore TDP 20 Watts
Power @ 12x 40 Watts
Power @ 13x 46 Watts
Power @ 14x 52 Watts
Power @ 15x 60 Watts
Power @ 16x 68 Watts
Power @ 17x 78 Watts
Power @ 18x 89 Watts
Power @ 19x 101 Watts
Power @ 20x 115 Watts
Power @ 21x 130 Watts
Max bus number 255
Attached device PCI device at bus 255, device 2, function 1
Attached device PCI device at bus 255, device 3, function 4

Chipset
-------------------------------------------------------------------------

Northbridge Intel X58 rev. 13
Southbridge Intel 82801JR (ICH10R) rev. 00
Graphic Interface PCI-Express
PCI-E Link Width x16
PCI-E Max Link Width x16
Memory Type DDR3
Memory Size 12288 MBytes
Channels Triple
Memory Frequency 801.4 MHz (2:12)
CAS# latency (CL) 8.0
RAS# to CAS# delay (tRCD) 8
RAS# Precharge (tRP) 8
Cycle Time (tRAS) 24
Row Refresh Cycle Time (tRFC) 88
Command Rate (CR) 2T
Uncore Frequency 3205.6 MHz

stickymango

09-01-2014 10:10:17

Tried this on a second pc and it seems to work fine :?

shenjoku

09-01-2014 19:44:59

Would a video be helpful at all? So you could see/hear what the problem is. Maybe that'll give some hint as to the cause.

stickymango

09-01-2014 22:48:58

Yeah sure

shenjoku

10-01-2014 19:23:29

I don't have fraps or anything so I just streamed it to my Twitch account. Video is here.

EDIT: The video got deleted somehow. I hope you got a chance to take a look at it. If not, let me know.