Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7411799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:26:35+00:00 2026-05-29T06:26:35+00:00

I am using SDL audio to play sounds. SDL_LockAudio tells this : Do not

  • 0

I am using SDL audio to play sounds.

SDL_LockAudio tells this :

Do not call this from the callback function or you will cause deadlock.

But, SDL_PauseAudio doesn’t say that, instead it tells :

This function pauses and unpauses the audio callback processing

My mixer callback looks like this :

void AudioPlaybackCallback( void *, core::bty::UInt8 *stream, int len )
{
         // number of bytes left to play in the current sample
        const int thisSampleLeft = currentSample.dataLength - currentSample.dataPos;
        // number of bytes that will be sent to the audio stream
        const int amountToPlay = std::min( thisSampleLeft, len );

        if ( amountToPlay > 0 )
        {
            SDL_MixAudio( stream,
                          currentSample.data + currentSample.dataPos,
                          amountToPlay,
                          currentSample.volume );

            // update the current sample
            currentSample.dataPos += amountToPlay;
        }
        else
        {
            if ( PlayingQueue::QueueHasElements() )
            {
                // update the current sample
                currentSample = PlayingQueue::QueuePop();
            }
            else
            {
                // since the current sample finished, and there are no more samples to
                // play, pause the playback
                SDL_PauseAudio( 1 );
            }
        }
}

PlayingQueue is a class which provides access to a static std::queue object. Nothing fancy.

This worked fine, until we decided to update the SDL and alsa libraries (now there is no turning back anymore). Since then I see this in my log :

ALSA lib pcm.c:7316:(snd_pcm_recover) underrun occurred

If I assume there are no bugs in SDL or alsa library (this is most likely wrong, after googling this message), I guess it should be possible to change my code to fix, or at least avoid the underrun.

So, the question is : can I pause the callback from itself? Can it cause underruns I am seeing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:26:36+00:00Added an answer on May 29, 2026 at 6:26 am

    Finally I figured out.

    When the SDL_PauseAudio( 1 ); is called in the callback, then the SDL is going to switch to another callback (which just put zeros into the audio stream). The callback will finish the execution after the function is called.

    Therefore, it is safe to call this function from the callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created this basic 3D Demo using OpenGL/SDL. I handled the keyboard callback so
As I stated in this question , I am using SDL for a small
I'm building a program in C++, using SDL, and am occasionally receiving this error:
I have converted C++ source from using GLUT to using SDL/OpenGL The problem is
I'm using SDL with FASM, and have code that's minimally like the following: format
I'm using Windows and I need the SDL Library to start using SDL with
My situation is Using .NET 3.5 Using SDL.NET Need to make a friendly installer
I'm using the SDL library to try to create a rendering context in a
I'm just using the opengl SDL template with Xcode, and everything runs fine. I
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.