Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Emitsound() & Source issues (bug?)


Recommended Posts

I've been having issues with the audio in our game Disinfection lately. Sounds cut off or don't play at all. I've also been seeing some crashes with an OpenAL AL_INVALID_VALUE error in the log.

I've been trying to figure out why, here's some of my observations:

I'm not sure if these are the right values to check but this is how I've been keeping track of the channels and sources available/in use:

System::Print("MAX available sound channels: " + std::to_string(listener->sounddriver->GetMaxChannels()));
System::Print("Sound channels in use: " + std::to_string(listener->sounddriver->sources.size()));

I also checked 'usedchannels' in the Sounddriver object which gave similar results as the size of the sources list.

I noticed when using sounds with EmitSound() that the size of 'sources' keeps increasing every time I call EmitSound(), if the sounds overlap.
For example: I use 6 different stereo sounds for the player footsteps and the size of 'sources' keeps going up, eventually reaching very high values like 400+. I noticed that crashes often happen at this point too.
At first I thought this was an issue with stereo sounds because when I accidentally set the footsteps sound to the (mono) flashlight sound, which is much shorter, the issue was gone. I then tried using the footstep sounds in mono but the issue was back, because the sounds overlap again.
Another time when I noticed this when the monster entity had a bug where it would do a certain action in quick succession, also producing the same sound in quick succession causing sounds to overlap and the list to increase in size rapidly.

I then started noticing the same issue with other sounds in the game too. For example there's a Fusion Reactor in the game which produces various sounds (a mono looping hum sound and mono start/stop sounds). However this Entity is using a Source for the looping sound and a Source for the start/stop sounds. Again when sounds overlap the 'sources' list keeps growing.

The bigger 'sources' grow the more things start cutting off or not playing at all. I'm not entirely sure the OpenAL crashes are directly linked to it, but they did start happening recently too. I've started using EmitSound() and Source a lot more, since I implemented volume settings in the game. I was simply using Sound->Play(); for a lot of sounds, but it doesn't have volume control so I switched to EmitSound() mostly and that's when this issue started becoming apparent.
The volume settings are saved as System property values and fetched in various parts of the code where needed.


Any ideas on what I could be doing wrong or if this is a known bug or something?

Link to post
Share on other sites
1 hour ago, Josh said:

Can you post the code for your player?

I'll cut it up to the bits related to sound, it's a bit much otherwise. Most of the code is very similar to the standard FPSplayer LUA script anyways, albeit C++ :)

Here's where the sounds are loaded in and Sources are setup:

//sounds
	sounds[0] = Sound::Load("Sound/Player/flashlight_02_on.wav");

	sounds[1] = nullptr; //TODO use a sound here, suit noises loop?

	sounds[2] = Sound::Load("Sound/Footsteps/Astronaut/step1.wav");
	sounds[3] = Sound::Load("Sound/Footsteps/Astronaut/step2.wav");
	sounds[4] = Sound::Load("Sound/Footsteps/Astronaut/step3.wav");
	sounds[5] = Sound::Load("Sound/Footsteps/Astronaut/step4.wav");
	sounds[6] = Sound::Load("Sound/Footsteps/Astronaut/step5.wav");
	sounds[7] = Sound::Load("Sound/Footsteps/Astronaut/step6.wav");

	sounds[8] = Sound::Load("Sound/Player/deathfx1.wav");
	sounds[9] = Sound::Load("Sound/Player/deathfx1.wav"); //TODO more death sounds
	sounds[10] = Sound::Load("Sound/Player/deathfx1.wav"); //TODO more death sounds
	sounds[11] = Sound::Load("Sound/Player/deathfx1.wav"); //TODO more death sounds

	sounds[12] = Sound::Load("Sound/Player/breathing_normal.wav");
	sounds[13] = Sound::Load("Sound/Player/breathing_panting.wav");
	sounds[14] = Sound::Load("Sound/Player/breathing_cooldown.wav");
	sounds[15] = Sound::Load("Sound/Player/breathing_asphyx.wav");

	sounds[16] = Sound::Load("Sound/Player/grunt1.wav");

	//sources
	Sound* airhisssnd = Sound::Load("Sound/Player/airhiss.wav");
	airhiss = Source::Create();
	airhiss->SetSound(airhisssnd);
	airhisssnd->Release();
	airhiss->SetLoopMode(true);
	airhiss->SetVolume(0.5f * vol_fx);
	airhiss->Play();

	breathingA = Source::Create();
	breathingA->SetSound(sounds[12]);
	breathingA->SetLoopMode(true);
	breathingA->SetVolume(1.f * vol_fx);
	breathingA->Play();
	breathingB = Source::Create();
	breathingB->SetSound(sounds[13]);
	breathingB->SetLoopMode(true);
	breathingB->SetVolume(0.f * vol_fx);
	breathingB->Play();
	breathingmode = BREATHING_CALM;
	breathingblend = 1.f;

	//tutorial
	tutorialVO = Source::Create();
	tutorialVO->SetVolume(vol_vo);
	tutorialVO->SetLoopMode(false);
	tutorialmode = false;


The footstep sounds in UpdatePhysics call, 'vol_fx' is the volume setting value for sound effects:

//footstep sounds
if (inputx != 0.f || inputz != 0.f)
{
  Vec3 speed = this->entity->GetVelocity();
  steptiming += speed.Length();

  if (steptiming > 150.f)
  {
    steptiming = 0.f;
    stepsoundind++;
    if (stepsoundind > 7)
    stepsoundind = 2;

    this->entity->EmitSound(sounds[stepsoundind], 10.f, vol_fx);
  }
}

 

Link to post
Share on other sites

As a test I commented out every single line with EmitSound() and Source's Play() methods so not a single sound would play.

As expected the amount of sources (sources.size()) stays at 21 (I didn't disable the Source creation code, also 21 seems a bit much?).

If I uncomment the EmitSound() line in the above footstep sounds code then again the sources start at 21, but as soon as I start walking around it increments with each footstep i.e. the behavior as described in my post.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...