Skip to content

Comments

Convert volume API from integers [0-128] to floats [0-1]#653

Closed
Starbuck5 wants to merge 6 commits intolibsdl-org:mainfrom
Starbuck5:volume-as-float
Closed

Convert volume API from integers [0-128] to floats [0-1]#653
Starbuck5 wants to merge 6 commits intolibsdl-org:mainfrom
Starbuck5:volume-as-float

Conversation

@Starbuck5
Copy link
Contributor

@Starbuck5 Starbuck5 commented Dec 22, 2024

In a lot of places this actually makes the code simpler. Volumes can be multiplied without then dividing by the integer range, the new SDL3 mixing API can be used without another divide into float-land, it makes one or two music codecs more straightforward.

Closes #652

A couple things I wanted to highlight in review:

  • The handling of gain in music_gme.c might not be 100% the same, I'm finding it difficult to think through the x * y vs floor(x * y + 0.5)/128.
  • The Timidity_SetVolume function previously took in values between 0 and 128, but compares to a MAX AMPLIFICATION of 800, and checks if the value is at least 0. That is strange.
  • Is my handling of master_volume in mixer.c okay? It previously was an SDL_AtomicInt, but there is no SDL_AtomicFloat so I gave it a spinlock instead.

@Starbuck5 Starbuck5 marked this pull request as draft December 22, 2024 12:03
@Starbuck5 Starbuck5 marked this pull request as ready for review December 28, 2024 06:31
@Starbuck5
Copy link
Contributor Author

Starbuck5 commented Jun 1, 2025

Coming back to this, I see it will be overcome-by-events by icculus's SDL_remixer, where volume is controlled by a *float* gain. So I will close this out.

@Starbuck5 Starbuck5 closed this Jun 1, 2025
@Starbuck5 Starbuck5 deleted the volume-as-float branch June 1, 2025 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDL3: update volume to a float

2 participants