Skip to content

Commit ba65bd7

Browse files
committed
WARNING: BREAKING: Redesigned SetSoundPan() and SetMusicPan() #5350
Now it goes from -1.0 (full left) to 1.0 (full right) being 0.0 center
1 parent 67f24b3 commit ba65bd7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/raudio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ AudioBuffer *LoadAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sam
593593
// Init audio buffer values
594594
audioBuffer->volume = 1.0f;
595595
audioBuffer->pitch = 1.0f;
596-
audioBuffer->pan = 0.5f;
596+
audioBuffer->pan = 0.0f; // Center
597597

598598
audioBuffer->callback = NULL;
599599
audioBuffer->processor = NULL;
@@ -720,7 +720,7 @@ void SetAudioBufferPitch(AudioBuffer *buffer, float pitch)
720720
// Set pan for an audio buffer
721721
void SetAudioBufferPan(AudioBuffer *buffer, float pan)
722722
{
723-
if (pan < 0.0f) pan = 0.0f;
723+
if (pan < -1.0f) pan = -1.0f;
724724
else if (pan > 1.0f) pan = 1.0f;
725725

726726
if (buffer != NULL)
@@ -985,10 +985,10 @@ Sound LoadSoundAlias(Sound source)
985985
audioBuffer->sizeInFrames = source.stream.buffer->sizeInFrames;
986986
audioBuffer->data = source.stream.buffer->data;
987987

988-
// initalize the buffer as if it was new
988+
// Initalize the buffer as if it was new
989989
audioBuffer->volume = 1.0f;
990990
audioBuffer->pitch = 1.0f;
991-
audioBuffer->pan = 0.5f;
991+
audioBuffer->pan = 0.0f; // Center
992992

993993
sound.frameCount = source.frameCount;
994994
sound.stream.sampleRate = AUDIO.System.device.sampleRate;
@@ -2605,8 +2605,8 @@ static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 fr
26052605

26062606
if (channels == 2) // We consider panning
26072607
{
2608-
const float left = buffer->pan;
2609-
const float right = 1.0f - left;
2608+
const float right = (buffer->pan + 1.0f)/2.0f; // Normalize: [-1..1] -> [0..1]
2609+
const float left = 1.0f - right;
26102610

26112611
// Fast sine approximation in [0..1] for pan law: y = 0.5f*x*(3 - x*x);
26122612
const float levels[2] = { localVolume*0.5f*left*(3.0f - left*left), localVolume*0.5f*right*(3.0f - right*right) };

src/raylib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ RLAPI void ResumeSound(Sound sound); // Resume
16721672
RLAPI bool IsSoundPlaying(Sound sound); // Check if a sound is currently playing
16731673
RLAPI void SetSoundVolume(Sound sound, float volume); // Set volume for a sound (1.0 is max level)
16741674
RLAPI void SetSoundPitch(Sound sound, float pitch); // Set pitch for a sound (1.0 is base level)
1675-
RLAPI void SetSoundPan(Sound sound, float pan); // Set pan for a sound (0.5 is center)
1675+
RLAPI void SetSoundPan(Sound sound, float pan); // Set pan for a sound (-1.0 left, 0.0 center, 1.0 right)
16761676
RLAPI Wave WaveCopy(Wave wave); // Copy a wave to a new wave
16771677
RLAPI void WaveCrop(Wave *wave, int initFrame, int finalFrame); // Crop a wave to defined frames range
16781678
RLAPI void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels); // Convert wave data to desired format
@@ -1693,7 +1693,7 @@ RLAPI void ResumeMusicStream(Music music); // Resume
16931693
RLAPI void SeekMusicStream(Music music, float position); // Seek music to a position (in seconds)
16941694
RLAPI void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
16951695
RLAPI void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
1696-
RLAPI void SetMusicPan(Music music, float pan); // Set pan for a music (0.5 is center)
1696+
RLAPI void SetMusicPan(Music music, float pan); // Set pan for a music (-1.0 left, 0.0 center, 1.0 right)
16971697
RLAPI float GetMusicTimeLength(Music music); // Get music time length (in seconds)
16981698
RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
16991699

0 commit comments

Comments
 (0)