Merge pull request #3024 from LAGonauta/x-fi-audio-fix
Added X-Fi check and convert surround FLOAT to SHORT when it is detected
This commit is contained in:
commit
4d5baa4772
|
@ -136,6 +136,7 @@ void OpenALStream::SoundLoop()
|
||||||
// OS X does not have the alext AL_FORMAT_51CHN32 yet.
|
// OS X does not have the alext AL_FORMAT_51CHN32 yet.
|
||||||
surround_capable = false;
|
surround_capable = false;
|
||||||
const ALenum AL_FORMAT_51CHN32 = 0;
|
const ALenum AL_FORMAT_51CHN32 = 0;
|
||||||
|
const ALenum AL_FORMAT_51CHN16 = 0;
|
||||||
#else
|
#else
|
||||||
bool float32_capable = true;
|
bool float32_capable = true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -146,20 +147,36 @@ void OpenALStream::SoundLoop()
|
||||||
memset(uiBuffers, 0, numBuffers * sizeof(ALuint));
|
memset(uiBuffers, 0, numBuffers * sizeof(ALuint));
|
||||||
uiSource = 0;
|
uiSource = 0;
|
||||||
|
|
||||||
|
// Checks if a X-Fi is being used. If it is, disable FLOAT32 support as this sound card has no support for it even though it reports it does.
|
||||||
|
if (strstr(alGetString(AL_RENDERER), "X-Fi"))
|
||||||
|
float32_capable = false;
|
||||||
|
|
||||||
// Generate some AL Buffers for streaming
|
// Generate some AL Buffers for streaming
|
||||||
alGenBuffers(numBuffers, (ALuint *)uiBuffers);
|
alGenBuffers(numBuffers, (ALuint *)uiBuffers);
|
||||||
// Generate a Source to playback the Buffers
|
// Generate a Source to playback the Buffers
|
||||||
alGenSources(1, &uiSource);
|
alGenSources(1, &uiSource);
|
||||||
|
|
||||||
// Short Silence
|
// Short Silence
|
||||||
memset(sampleBuffer, 0, OAL_MAX_SAMPLES * numBuffers * FRAME_SURROUND_FLOAT);
|
if (float32_capable)
|
||||||
|
memset(sampleBuffer, 0, OAL_MAX_SAMPLES * numBuffers * FRAME_SURROUND_FLOAT);
|
||||||
|
else
|
||||||
|
memset(sampleBuffer, 0, OAL_MAX_SAMPLES * numBuffers * FRAME_SURROUND_SHORT);
|
||||||
|
|
||||||
memset(realtimeBuffer, 0, OAL_MAX_SAMPLES * FRAME_STEREO_SHORT);
|
memset(realtimeBuffer, 0, OAL_MAX_SAMPLES * FRAME_STEREO_SHORT);
|
||||||
|
|
||||||
for (int i = 0; i < numBuffers; i++)
|
for (int i = 0; i < numBuffers; i++)
|
||||||
{
|
{
|
||||||
if (surround_capable)
|
if (surround_capable)
|
||||||
alBufferData(uiBuffers[i], AL_FORMAT_51CHN32, sampleBuffer, 4 * FRAME_SURROUND_FLOAT, ulFrequency);
|
{
|
||||||
|
if (float32_capable)
|
||||||
|
alBufferData(uiBuffers[i], AL_FORMAT_51CHN32, sampleBuffer, 4 * FRAME_SURROUND_FLOAT, ulFrequency);
|
||||||
|
else
|
||||||
|
alBufferData(uiBuffers[i], AL_FORMAT_51CHN16, sampleBuffer, 4 * FRAME_SURROUND_SHORT, ulFrequency);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
alBufferData(uiBuffers[i], AL_FORMAT_STEREO16, realtimeBuffer, 4 * FRAME_STEREO_SHORT, ulFrequency);
|
alBufferData(uiBuffers[i], AL_FORMAT_STEREO16, realtimeBuffer, 4 * FRAME_STEREO_SHORT, ulFrequency);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
alSourceQueueBuffers(uiSource, numBuffers, uiBuffers);
|
alSourceQueueBuffers(uiSource, numBuffers, uiBuffers);
|
||||||
alSourcePlay(uiSource);
|
alSourcePlay(uiSource);
|
||||||
|
@ -252,6 +269,7 @@ void OpenALStream::SoundLoop()
|
||||||
{
|
{
|
||||||
float dpl2[OAL_MAX_SAMPLES * OAL_MAX_BUFFERS * SURROUND_CHANNELS];
|
float dpl2[OAL_MAX_SAMPLES * OAL_MAX_BUFFERS * SURROUND_CHANNELS];
|
||||||
DPL2Decode(sampleBuffer, nSamples, dpl2);
|
DPL2Decode(sampleBuffer, nSamples, dpl2);
|
||||||
|
|
||||||
// zero-out the subwoofer channel - DPL2Decode generates a pretty
|
// zero-out the subwoofer channel - DPL2Decode generates a pretty
|
||||||
// good 5.0 but not a good 5.1 output. Sadly there is not a 5.0
|
// good 5.0 but not a good 5.1 output. Sadly there is not a 5.0
|
||||||
// AL_FORMAT_50CHN32 to make this super-explicit.
|
// AL_FORMAT_50CHN32 to make this super-explicit.
|
||||||
|
@ -260,7 +278,20 @@ void OpenALStream::SoundLoop()
|
||||||
{
|
{
|
||||||
dpl2[i*SURROUND_CHANNELS + 3 /*sub/lfe*/] = 0.0f;
|
dpl2[i*SURROUND_CHANNELS + 3 /*sub/lfe*/] = 0.0f;
|
||||||
}
|
}
|
||||||
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_51CHN32, dpl2, nSamples * FRAME_SURROUND_FLOAT, ulFrequency);
|
|
||||||
|
if (float32_capable)
|
||||||
|
{
|
||||||
|
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_51CHN32, dpl2, nSamples * FRAME_SURROUND_FLOAT, ulFrequency);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
short surround_short[OAL_MAX_SAMPLES * SURROUND_CHANNELS * OAL_MAX_BUFFERS];
|
||||||
|
for (u32 i = 0; i < nSamples * SURROUND_CHANNELS; ++i)
|
||||||
|
surround_short[i] = (short)((float)dpl2[i] * (1 << 15));
|
||||||
|
|
||||||
|
alBufferData(uiBufferTemp[iBuffersFilled], AL_FORMAT_51CHN16, surround_short, nSamples * FRAME_SURROUND_SHORT, ulFrequency);
|
||||||
|
}
|
||||||
|
|
||||||
ALenum err = alGetError();
|
ALenum err = alGetError();
|
||||||
if (err == AL_INVALID_ENUM)
|
if (err == AL_INVALID_ENUM)
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#define FRAME_STEREO_SHORT STEREO_CHANNELS * SIZE_SHORT
|
#define FRAME_STEREO_SHORT STEREO_CHANNELS * SIZE_SHORT
|
||||||
#define FRAME_STEREO_FLOAT STEREO_CHANNELS * SIZE_FLOAT
|
#define FRAME_STEREO_FLOAT STEREO_CHANNELS * SIZE_FLOAT
|
||||||
#define FRAME_SURROUND_FLOAT SURROUND_CHANNELS * SIZE_FLOAT
|
#define FRAME_SURROUND_FLOAT SURROUND_CHANNELS * SIZE_FLOAT
|
||||||
|
#define FRAME_SURROUND_SHORT SURROUND_CHANNELS * SIZE_SHORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class OpenALStream final : public SoundStream
|
class OpenALStream final : public SoundStream
|
||||||
|
|
Loading…
Reference in New Issue