Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/raudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ void StopAudioBuffer(AudioBuffer *buffer);
void PauseAudioBuffer(AudioBuffer *buffer);
void ResumeAudioBuffer(AudioBuffer *buffer);
void SetAudioBufferVolume(AudioBuffer *buffer, float volume);
float GetAudioBufferVolume(AudioBuffer *buffer);
void SetAudioBufferPitch(AudioBuffer *buffer, float pitch);
void SetAudioBufferPan(AudioBuffer *buffer, float pan);
void TrackAudioBuffer(AudioBuffer *buffer);
Expand Down Expand Up @@ -717,6 +718,19 @@ void SetAudioBufferVolume(AudioBuffer *buffer, float volume)
}
}

// Get volume of an audio buffer, returns -1 if invalid
float GetAudioBufferVolume(AudioBuffer *buffer)
{
float volume = -1.0f;
if (buffer != NULL)
{
ma_mutex_lock(&AUDIO.System.lock);
volume = buffer->volume;
ma_mutex_unlock(&AUDIO.System.lock);
}
return volume;
}

// Set pitch for an audio buffer
void SetAudioBufferPitch(AudioBuffer *buffer, float pitch)
{
Expand Down Expand Up @@ -1232,6 +1246,12 @@ void SetSoundVolume(Sound sound, float volume)
SetAudioBufferVolume(sound.stream.buffer, volume);
}

// Get volume of a sound, returns -1 if invalid
float GetSoundVolume(Sound sound)
{
return GetAudioBufferVolume(sound.stream.buffer);
}

// Set pitch for a sound
void SetSoundPitch(Sound sound, float pitch)
{
Expand Down Expand Up @@ -2063,6 +2083,12 @@ void SetMusicVolume(Music music, float volume)
SetAudioStreamVolume(music.stream, volume);
}

// Get volume of music, returns -1 if invalid
float GetMusicVolume(Music music)
{
return GetAudioStreamVolume(music.stream);
}

// Set pitch for music
void SetMusicPitch(Music music, float pitch)
{
Expand Down Expand Up @@ -2235,6 +2261,12 @@ void SetAudioStreamVolume(AudioStream stream, float volume)
SetAudioBufferVolume(stream.buffer, volume);
}

// Get volume for audio stream (1.0 is max level), returns -1 if invalid
float GetAudioStreamVolume(AudioStream stream)
{
return GetAudioBufferVolume(stream.buffer);
}

// Set pitch for audio stream (1.0 is base level)
void SetAudioStreamPitch(AudioStream stream, float pitch)
{
Expand Down
3 changes: 3 additions & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ RLAPI void PauseSound(Sound sound); // Pause a
RLAPI void ResumeSound(Sound sound); // Resume a paused sound
RLAPI bool IsSoundPlaying(Sound sound); // Check if sound is currently playing
RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
RLAPI float GetSoundVolume(Sound sound); // Get volume of a sound (1.0 is max level), returns -1 if invalid
RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
RLAPI void SetSoundPan(Sound sound, float pan); // Set pan for a sound (-1.0 left, 0.0 center, 1.0 right)
RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave
Expand All @@ -1729,6 +1730,7 @@ RLAPI void PauseMusicStream(Music music); // Pause m
RLAPI void ResumeMusicStream(Music music); // Resume playing paused music
RLAPI void SeekMusicStream(Music music, float position); // Seek music to a position (in seconds)
RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
RLAPI float GetMusicVolume(Music music); // Get volume of music (1.0 is max level), returns -1 if invalid
RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for music (1.0 is base level)
RLAPI void SetMusicPan(Music music, float pan); // Set pan for music (-1.0 left, 0.0 center, 1.0 right)
RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds)
Expand All @@ -1746,6 +1748,7 @@ RLAPI void ResumeAudioStream(AudioStream stream); // Resume
RLAPI bool IsAudioStreamPlaying(AudioStream stream); // Check if audio stream is playing
RLAPI void StopAudioStream(AudioStream stream); // Stop audio stream
RLAPI void SetAudioStreamVolume(AudioStream stream, float volume); // Set volume for audio stream (1.0 is max level)
RLAPI float GetAudioStreamVolume(AudioStream stream); // Get volume of an audio stream (1.0 is max level), returns -1 if invalid
RLAPI void SetAudioStreamPitch(AudioStream stream, float pitch); // Set pitch for audio stream (1.0 is base level)
RLAPI void SetAudioStreamPan(AudioStream stream, float pan); // Set pan for audio stream (-1.0 left, 0.0 center, 1.0 right)
RLAPI void SetAudioStreamBufferSizeDefault(int size); // Default size for new audio streams
Expand Down