remove pan smoothing, code formatting changes following pull request comments
This commit is contained in:
parent
ac90726fda
commit
564d8765ac
26
src/raudio.c
26
src/raudio.c
|
|
@ -333,8 +333,6 @@ struct rAudioBuffer {
|
||||||
|
|
||||||
rAudioBuffer *next; // Next audio buffer on the list
|
rAudioBuffer *next; // Next audio buffer on the list
|
||||||
rAudioBuffer *prev; // Previous audio buffer on the list
|
rAudioBuffer *prev; // Previous audio buffer on the list
|
||||||
|
|
||||||
float panVolumeSmoothing[2];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define AudioBuffer rAudioBuffer // HACK: To avoid CoreAudio (macOS) symbol collision
|
#define AudioBuffer rAudioBuffer // HACK: To avoid CoreAudio (macOS) symbol collision
|
||||||
|
|
@ -405,13 +403,6 @@ void SetAudioBufferPitch(AudioBuffer *buffer, float pitch);
|
||||||
void TrackAudioBuffer(AudioBuffer *buffer);
|
void TrackAudioBuffer(AudioBuffer *buffer);
|
||||||
void UntrackAudioBuffer(AudioBuffer *buffer);
|
void UntrackAudioBuffer(AudioBuffer *buffer);
|
||||||
|
|
||||||
|
|
||||||
// pan law
|
|
||||||
static float FastSineApproximation(float x)
|
|
||||||
{
|
|
||||||
return 0.5f * x * (3 - x * x);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Audio Device initialization and Closing
|
// Module Functions Definition - Audio Device initialization and Closing
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -565,7 +556,6 @@ AudioBuffer *LoadAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sam
|
||||||
audioBuffer->volume = 1.0f;
|
audioBuffer->volume = 1.0f;
|
||||||
audioBuffer->pitch = 1.0f;
|
audioBuffer->pitch = 1.0f;
|
||||||
audioBuffer->pan = 0.5f;
|
audioBuffer->pan = 0.5f;
|
||||||
audioBuffer->panVolumeSmoothing[0] = audioBuffer->panVolumeSmoothing[1] = FastSineApproximation(0.5f);
|
|
||||||
|
|
||||||
audioBuffer->playing = false;
|
audioBuffer->playing = false;
|
||||||
audioBuffer->paused = false;
|
audioBuffer->paused = false;
|
||||||
|
|
@ -1061,8 +1051,6 @@ void PlaySoundMulti(Sound sound)
|
||||||
AUDIO.MultiChannel.pool[index]->volume = sound.stream.buffer->volume;
|
AUDIO.MultiChannel.pool[index]->volume = sound.stream.buffer->volume;
|
||||||
AUDIO.MultiChannel.pool[index]->pitch = sound.stream.buffer->pitch;
|
AUDIO.MultiChannel.pool[index]->pitch = sound.stream.buffer->pitch;
|
||||||
AUDIO.MultiChannel.pool[index]->pan = sound.stream.buffer->pan;
|
AUDIO.MultiChannel.pool[index]->pan = sound.stream.buffer->pan;
|
||||||
AUDIO.MultiChannel.pool[index]->panVolumeSmoothing[0] = sound.stream.buffer->panVolumeSmoothing[0];
|
|
||||||
AUDIO.MultiChannel.pool[index]->panVolumeSmoothing[1] = sound.stream.buffer->panVolumeSmoothing[1];
|
|
||||||
|
|
||||||
AUDIO.MultiChannel.pool[index]->looping = sound.stream.buffer->looping;
|
AUDIO.MultiChannel.pool[index]->looping = sound.stream.buffer->looping;
|
||||||
AUDIO.MultiChannel.pool[index]->usage = sound.stream.buffer->usage;
|
AUDIO.MultiChannel.pool[index]->usage = sound.stream.buffer->usage;
|
||||||
|
|
@ -2264,23 +2252,21 @@ static void OnSendAudioDataToDevice(ma_device *pDevice, void *pFramesOut, const
|
||||||
// NOTE: framesOut is both an input and an output. It will be initially filled with zeros outside of this function.
|
// NOTE: framesOut is both an input and an output. It will be initially filled with zeros outside of this function.
|
||||||
static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 frameCount, AudioBuffer *buffer)
|
static void MixAudioFrames(float *framesOut, const float *framesIn, ma_uint32 frameCount, AudioBuffer *buffer)
|
||||||
{
|
{
|
||||||
float localVolume = buffer->volume;
|
const float localVolume = buffer->volume;
|
||||||
|
|
||||||
const ma_uint32 nChannels = AUDIO.System.device.playback.channels;
|
const ma_uint32 nChannels = AUDIO.System.device.playback.channels;
|
||||||
if (nChannels == 2)
|
if (nChannels == 2)
|
||||||
{
|
{
|
||||||
float localPan = buffer->pan;
|
const float left = buffer->pan;
|
||||||
float panVolumeTargets[2] = { localVolume * FastSineApproximation(localPan), localVolume * FastSineApproximation(1.0f - localPan) };
|
const float right = 1.0f - left;
|
||||||
float* levels = buffer->panVolumeSmoothing;
|
|
||||||
|
// fast sine approximation in [0..1] for pan law: y = 0.5f * x * (3 - x * x);
|
||||||
|
const float levels[2] = { localVolume*0.5f*left*(3.0f-left*left), localVolume*0.5f*right*(3.0f-right*right) };
|
||||||
|
|
||||||
float *frameOut = framesOut;
|
float *frameOut = framesOut;
|
||||||
const float *frameIn = framesIn;
|
const float *frameIn = framesIn;
|
||||||
for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame)
|
for (ma_uint32 iFrame = 0; iFrame < frameCount; ++iFrame)
|
||||||
{
|
{
|
||||||
levels[0] = panVolumeTargets[0] - (panVolumeTargets[0]-levels[0]) * 0.995f;
|
|
||||||
levels[1] = panVolumeTargets[1] - (panVolumeTargets[1]-levels[1]) * 0.995f;
|
|
||||||
levels[0] += 1.0f; levels[0] -= 1.0f; // remove denormals
|
|
||||||
levels[1] += 1.0f; levels[1] -= 1.0f;
|
|
||||||
frameOut[0] += (frameIn[0]*levels[0]);
|
frameOut[0] += (frameIn[0]*levels[0]);
|
||||||
frameOut[1] += (frameIn[1]*levels[1]);
|
frameOut[1] += (frameIn[1]*levels[1]);
|
||||||
frameOut += 2;
|
frameOut += 2;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user