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 7611557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:41:31+00:00 2026-05-31T01:41:31+00:00

Whenever I play a sound effect I use: alSourcei(sources[index], AL_BUFFER, 0); alSourcei(sources[index], AL_BUFFER, bufferID);

  • 0

Whenever I play a sound effect I use:

alSourcei(sources[index], AL_BUFFER, 0);
alSourcei(sources[index], AL_BUFFER, bufferID);
alSourcef(sources[index], AL_PITCH, 1.0);
alSourcef(sources[index], AL_GAIN, 1.0);

would it be a significant optimization to remove setting the AL_PITCH and the AL_GAIN every time a sound effect is played? Obviously since they’re 1.0 every time I could just set it once when I initialize the sound. What values do AL_PITCH and AL_GAIN default to if they aren’t set?

  • 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-31T01:41:31+00:00Added an answer on May 31, 2026 at 1:41 am

    Only an “in general” type of answer is possible as far as the optimization bit goes since an implementation is not required to work in some particular way as long as it works within the conditions laid down by the OpenAL specification. It is nevertheless likely that all implementations more or less work similarly.

    In general, alSourcei/alSourcef involves at least calling a function like GetContextSuspended, which involves an access to thread-local storage and entering/leaving a critical section, as well as a switch statement (it also means a jump through a function pointer equivalent to a possibly not cached address in a possibly out-of-core page, and likely wasting one TLB cache entry).

    alSourcei further needs to do a thread-safe increment of a reference count, and allocate/append a new list node to the source’s buffer list, which means something on the order of magnitude of calling malloc at least once.

    Setting AL_GAIN and AL_PITCH per se is almost a free operation. It sets a value and marks the source as being updated, so the context mixer thread knows something has changed when mixing the next time slice. In the worst case, if the parameters are illegal, alSourcef needs to set the last error code.

    Insofar, removing the calls to alSourcef will of course avoid some unnecessary calls, and since you say that there is no chance the values could be anything else but 1.0, there is actually no reason to ever touch them at all, since that is the default value as per the specification.
    But… if you expect a noticeable speed-up from removing these calls, you will likely be disappointed (unless there’s several hundred thousands of them per second).

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

Sidebar

Related Questions

I just want a sound to play whenever a user clicks a button. Said
I am basically trying to make the device play a sound whenever the app
I have a card game in java. I would like to play a sound
I am trying to play a short sound whenever clicks a button on the
Currently, I have some basic code to play a simple tone whenever a button
Whenever I use the signal/slot editor dialog box, I have to choose from the
i am using the following code to play a sound when user touches anywhere
Whenever we play a normal video through phone or sdcard in android's phone memory,
I want to play an audio of an image whenever click on it .If
I want to play an audio file whenever my page gets loaded onto the

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.