mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-11 07:12:02 +00:00
Remove the 'monoize' option from sound loading
Unnecessary with the AL_SOFT_source_spatialize extension, which has been available for over a year.
This commit is contained in:
parent
42fd84a09d
commit
c095872b0a
6 changed files with 43 additions and 158 deletions
|
@ -127,15 +127,15 @@ public:
|
||||||
void SetMusicVolume (float volume)
|
void SetMusicVolume (float volume)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
std::pair<SoundHandle,bool> LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer)
|
SoundHandle LoadSound(uint8_t *sfxdata, int length, FSoundLoadBuffer *pBuffer)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
std::pair<SoundHandle,bool> LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend, bool monoize)
|
SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
void UnloadSound (SoundHandle sfx)
|
void UnloadSound (SoundHandle sfx)
|
||||||
{
|
{
|
||||||
|
@ -339,7 +339,7 @@ FString SoundStream::GetStats()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
std::pair<SoundHandle,bool> SoundRenderer::LoadSoundVoc(uint8_t *sfxdata, int length, bool monoize)
|
SoundHandle SoundRenderer::LoadSoundVoc(uint8_t *sfxdata, int length)
|
||||||
{
|
{
|
||||||
uint8_t * data = NULL;
|
uint8_t * data = NULL;
|
||||||
int len, frequency, channels, bits, loopstart, loopend;
|
int len, frequency, channels, bits, loopstart, loopend;
|
||||||
|
@ -483,14 +483,14 @@ std::pair<SoundHandle,bool> SoundRenderer::LoadSoundVoc(uint8_t *sfxdata, int le
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (false);
|
} while (false);
|
||||||
std::pair<SoundHandle,bool> retval = LoadSoundRaw(data, len, frequency, channels, bits, loopstart, loopend, monoize);
|
SoundHandle retval = LoadSoundRaw(data, len, frequency, channels, bits, loopstart, loopend);
|
||||||
if (data) delete[] data;
|
if (data) delete[] data;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<SoundHandle, bool> SoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *buffer, bool monoize)
|
SoundHandle SoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *buffer)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,10 +108,10 @@ public:
|
||||||
virtual void SetSfxVolume (float volume) = 0;
|
virtual void SetSfxVolume (float volume) = 0;
|
||||||
virtual void SetMusicVolume (float volume) = 0;
|
virtual void SetMusicVolume (float volume) = 0;
|
||||||
// Returns a pair containing a sound handle and a boolean indicating the sound can be used in 3D.
|
// Returns a pair containing a sound handle and a boolean indicating the sound can be used in 3D.
|
||||||
virtual std::pair<SoundHandle,bool> LoadSound(uint8_t *sfxdata, int length, bool monoize=false, FSoundLoadBuffer *pBuffer = nullptr) = 0;
|
virtual SoundHandle LoadSound(uint8_t *sfxdata, int length, FSoundLoadBuffer *pBuffer = nullptr) = 0;
|
||||||
std::pair<SoundHandle,bool> LoadSoundVoc(uint8_t *sfxdata, int length, bool monoize=false);
|
SoundHandle LoadSoundVoc(uint8_t *sfxdata, int length);
|
||||||
virtual std::pair<SoundHandle,bool> LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1, bool monoize = false) = 0;
|
virtual SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1) = 0;
|
||||||
virtual std::pair<SoundHandle, bool> LoadSoundBuffered(FSoundLoadBuffer *buffer, bool monoize);
|
virtual SoundHandle LoadSoundBuffered(FSoundLoadBuffer *buffer);
|
||||||
virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory
|
virtual void UnloadSound (SoundHandle sfx) = 0; // unloads a sound from memory
|
||||||
virtual unsigned int GetMSLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency
|
virtual unsigned int GetMSLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency
|
||||||
virtual unsigned int GetSampleLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency
|
virtual unsigned int GetSampleLength(SoundHandle sfx) = 0; // Gets the length of a sound at its default frequency
|
||||||
|
|
|
@ -985,14 +985,11 @@ float OpenALSoundRenderer::GetOutputRate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend, bool monoize)
|
SoundHandle OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
|
|
||||||
if(length == 0) return std::make_pair(retval, true);
|
if(length == 0) return retval;
|
||||||
|
|
||||||
/* Only downmix to mono if we can't spatialize multi-channel sounds. */
|
|
||||||
monoize = monoize && !AL.SOFT_source_spatialize;
|
|
||||||
|
|
||||||
if(bits == -8)
|
if(bits == -8)
|
||||||
{
|
{
|
||||||
|
@ -1002,33 +999,6 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata,
|
||||||
bits = -bits;
|
bits = -bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(channels > 1 && monoize)
|
|
||||||
{
|
|
||||||
size_t frames = length / channels * 8 / bits;
|
|
||||||
if(bits == 16)
|
|
||||||
{
|
|
||||||
for(size_t i = 0;i < frames;i++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for(int c = 0;c < channels;c++)
|
|
||||||
sum += ((short*)sfxdata)[i*channels + c];
|
|
||||||
((short*)sfxdata)[i] = sum / channels;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(bits == 8)
|
|
||||||
{
|
|
||||||
for(size_t i = 0;i < frames;i++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for(int c = 0;c < channels;c++)
|
|
||||||
sum += sfxdata[i*channels + c] - 128;
|
|
||||||
sfxdata[i] = (sum / channels) + 128;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
length /= channels;
|
|
||||||
channels = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ALenum format = AL_NONE;
|
ALenum format = AL_NONE;
|
||||||
if(bits == 16)
|
if(bits == 16)
|
||||||
{
|
{
|
||||||
|
@ -1044,7 +1014,7 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata,
|
||||||
if(format == AL_NONE || frequency <= 0)
|
if(format == AL_NONE || frequency <= 0)
|
||||||
{
|
{
|
||||||
Printf("Unhandled format: %d bit, %d channel, %d hz\n", bits, channels, frequency);
|
Printf("Unhandled format: %d bit, %d channel, %d hz\n", bits, channels, frequency);
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
length -= length%(channels*bits/8);
|
length -= length%(channels*bits/8);
|
||||||
|
|
||||||
|
@ -1057,7 +1027,7 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata,
|
||||||
Printf("Failed to buffer data: %s\n", alGetString(err));
|
Printf("Failed to buffer data: %s\n", alGetString(err));
|
||||||
alDeleteBuffers(1, &buffer);
|
alDeleteBuffers(1, &buffer);
|
||||||
getALError();
|
getALError();
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((loopstart > 0 || loopend > 0) && AL.SOFT_loop_points)
|
if((loopstart > 0 || loopend > 0) && AL.SOFT_loop_points)
|
||||||
|
@ -1081,10 +1051,10 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSoundRaw(uint8_t *sfxdata,
|
||||||
}
|
}
|
||||||
|
|
||||||
retval.data = MAKE_PTRID(buffer);
|
retval.data = MAKE_PTRID(buffer);
|
||||||
return std::make_pair(retval, AL.SOFT_source_spatialize || channels==1);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *pBuffer)
|
SoundHandle OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int length, FSoundLoadBuffer *pBuffer)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
ALenum format = AL_NONE;
|
ALenum format = AL_NONE;
|
||||||
|
@ -1094,19 +1064,14 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
||||||
uint32_t loop_start = 0, loop_end = ~0u;
|
uint32_t loop_start = 0, loop_end = ~0u;
|
||||||
bool startass = false, endass = false;
|
bool startass = false, endass = false;
|
||||||
|
|
||||||
/* Only downmix to mono if we can't spatialize multi-channel sounds. */
|
|
||||||
monoize = monoize && !AL.SOFT_source_spatialize;
|
|
||||||
|
|
||||||
FindLoopTags(sfxdata, length, &loop_start, &startass, &loop_end, &endass);
|
FindLoopTags(sfxdata, length, &loop_start, &startass, &loop_end, &endass);
|
||||||
auto decoder = CreateDecoder(sfxdata, length, true);
|
auto decoder = CreateDecoder(sfxdata, length, true);
|
||||||
if (!decoder)
|
if (!decoder)
|
||||||
{
|
return retval;
|
||||||
return std::make_pair(retval, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundDecoder_GetInfo(decoder, &srate, &chans, &type);
|
SoundDecoder_GetInfo(decoder, &srate, &chans, &type);
|
||||||
int samplesize = 1;
|
int samplesize = 1;
|
||||||
if (chans == ChannelConfig_Mono || monoize)
|
if (chans == ChannelConfig_Mono)
|
||||||
{
|
{
|
||||||
if (type == SampleType_UInt8) format = AL_FORMAT_MONO8, samplesize = 1;
|
if (type == SampleType_UInt8) format = AL_FORMAT_MONO8, samplesize = 1;
|
||||||
if (type == SampleType_Int16) format = AL_FORMAT_MONO16, samplesize = 2;
|
if (type == SampleType_Int16) format = AL_FORMAT_MONO16, samplesize = 2;
|
||||||
|
@ -1122,7 +1087,7 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
||||||
SoundDecoder_Close(decoder);
|
SoundDecoder_Close(decoder);
|
||||||
Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans),
|
Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans),
|
||||||
GetSampleTypeName(type));
|
GetSampleTypeName(type));
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
|
@ -1138,36 +1103,6 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
||||||
data.resize(total);
|
data.resize(total);
|
||||||
SoundDecoder_Close(decoder);
|
SoundDecoder_Close(decoder);
|
||||||
|
|
||||||
if(chans != ChannelConfig_Mono && monoize)
|
|
||||||
{
|
|
||||||
size_t chancount = GetChannelCount(chans);
|
|
||||||
size_t frames = data.size() / chancount /
|
|
||||||
(type == SampleType_Int16 ? 2 : 1);
|
|
||||||
if(type == SampleType_Int16)
|
|
||||||
{
|
|
||||||
short *sfxdata = (short*)&data[0];
|
|
||||||
for(size_t i = 0;i < frames;i++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for(size_t c = 0;c < chancount;c++)
|
|
||||||
sum += sfxdata[i*chancount + c];
|
|
||||||
sfxdata[i] = short(sum / chancount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(type == SampleType_UInt8)
|
|
||||||
{
|
|
||||||
uint8_t *sfxdata = (uint8_t*)&data[0];
|
|
||||||
for(size_t i = 0;i < frames;i++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for(size_t c = 0;c < chancount;c++)
|
|
||||||
sum += sfxdata[i*chancount + c] - 128;
|
|
||||||
sfxdata[i] = uint8_t((sum / chancount) + 128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.resize((data.size()/chancount));
|
|
||||||
}
|
|
||||||
|
|
||||||
ALenum err;
|
ALenum err;
|
||||||
ALuint buffer = 0;
|
ALuint buffer = 0;
|
||||||
alGenBuffers(1, &buffer);
|
alGenBuffers(1, &buffer);
|
||||||
|
@ -1177,7 +1112,7 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
||||||
Printf("Failed to buffer data: %s\n", alGetString(err));
|
Printf("Failed to buffer data: %s\n", alGetString(err));
|
||||||
alDeleteBuffers(1, &buffer);
|
alDeleteBuffers(1, &buffer);
|
||||||
getALError();
|
getALError();
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!startass) loop_start = Scale(loop_start, srate, 1000);
|
if (!startass) loop_start = Scale(loop_start, srate, 1000);
|
||||||
|
@ -1204,10 +1139,10 @@ std::pair<SoundHandle,bool> OpenALSoundRenderer::LoadSound(uint8_t *sfxdata, int
|
||||||
pBuffer->type = type;
|
pBuffer->type = type;
|
||||||
pBuffer->srate = srate;
|
pBuffer->srate = srate;
|
||||||
}
|
}
|
||||||
return std::make_pair(retval, AL.SOFT_source_spatialize || chans == ChannelConfig_Mono || monoize);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<SoundHandle, bool> OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *pBuffer, bool monoize)
|
SoundHandle OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBuffer *pBuffer)
|
||||||
{
|
{
|
||||||
SoundHandle retval = { NULL };
|
SoundHandle retval = { NULL };
|
||||||
ALenum format = AL_NONE;
|
ALenum format = AL_NONE;
|
||||||
|
@ -1216,10 +1151,7 @@ std::pair<SoundHandle, bool> OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBu
|
||||||
auto chans = pBuffer->chans;
|
auto chans = pBuffer->chans;
|
||||||
uint32_t loop_start = pBuffer->loop_start, loop_end = pBuffer->loop_end;
|
uint32_t loop_start = pBuffer->loop_start, loop_end = pBuffer->loop_end;
|
||||||
|
|
||||||
/* Only downmix to mono if we can't spatialize multi-channel sounds. */
|
if (chans == ChannelConfig_Mono)
|
||||||
monoize = monoize && !AL.SOFT_source_spatialize;
|
|
||||||
|
|
||||||
if (chans == ChannelConfig_Mono || monoize)
|
|
||||||
{
|
{
|
||||||
if (type == SampleType_UInt8) format = AL_FORMAT_MONO8;
|
if (type == SampleType_UInt8) format = AL_FORMAT_MONO8;
|
||||||
if (type == SampleType_Int16) format = AL_FORMAT_MONO16;
|
if (type == SampleType_Int16) format = AL_FORMAT_MONO16;
|
||||||
|
@ -1234,41 +1166,11 @@ std::pair<SoundHandle, bool> OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBu
|
||||||
{
|
{
|
||||||
Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans),
|
Printf("Unsupported audio format: %s, %s\n", GetChannelConfigName(chans),
|
||||||
GetSampleTypeName(type));
|
GetSampleTypeName(type));
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &data = pBuffer->mBuffer;
|
auto &data = pBuffer->mBuffer;
|
||||||
|
|
||||||
if (pBuffer->chans == ChannelConfig_Stereo && monoize)
|
|
||||||
{
|
|
||||||
size_t chancount = GetChannelCount(chans);
|
|
||||||
size_t frames = data.size() / chancount /
|
|
||||||
(type == SampleType_Int16 ? 2 : 1);
|
|
||||||
if (type == SampleType_Int16)
|
|
||||||
{
|
|
||||||
short *sfxdata = (short*)&data[0];
|
|
||||||
for (size_t i = 0; i < frames; i++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (size_t c = 0; c < chancount; c++)
|
|
||||||
sum += sfxdata[i*chancount + c];
|
|
||||||
sfxdata[i] = short(sum / chancount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (type == SampleType_UInt8)
|
|
||||||
{
|
|
||||||
uint8_t *sfxdata = (uint8_t*)&data[0];
|
|
||||||
for (size_t i = 0; i < frames; i++)
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (size_t c = 0; c < chancount; c++)
|
|
||||||
sum += sfxdata[i*chancount + c] - 128;
|
|
||||||
sfxdata[i] = uint8_t((sum / chancount) + 128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data.resize(data.size() / chancount);
|
|
||||||
}
|
|
||||||
|
|
||||||
ALenum err;
|
ALenum err;
|
||||||
ALuint buffer = 0;
|
ALuint buffer = 0;
|
||||||
alGenBuffers(1, &buffer);
|
alGenBuffers(1, &buffer);
|
||||||
|
@ -1278,7 +1180,7 @@ std::pair<SoundHandle, bool> OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBu
|
||||||
Printf("Failed to buffer data: %s\n", alGetString(err));
|
Printf("Failed to buffer data: %s\n", alGetString(err));
|
||||||
alDeleteBuffers(1, &buffer);
|
alDeleteBuffers(1, &buffer);
|
||||||
getALError();
|
getALError();
|
||||||
return std::make_pair(retval, true);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the loop points were already validated by the previous load.
|
// the loop points were already validated by the previous load.
|
||||||
|
@ -1291,7 +1193,7 @@ std::pair<SoundHandle, bool> OpenALSoundRenderer::LoadSoundBuffered(FSoundLoadBu
|
||||||
}
|
}
|
||||||
|
|
||||||
retval.data = MAKE_PTRID(buffer);
|
retval.data = MAKE_PTRID(buffer);
|
||||||
return std::make_pair(retval, AL.SOFT_source_spatialize || chans == ChannelConfig_Mono || monoize);
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
|
void OpenALSoundRenderer::UnloadSound(SoundHandle sfx)
|
||||||
|
|
|
@ -125,9 +125,9 @@ public:
|
||||||
|
|
||||||
virtual void SetSfxVolume(float volume);
|
virtual void SetSfxVolume(float volume);
|
||||||
virtual void SetMusicVolume(float volume);
|
virtual void SetMusicVolume(float volume);
|
||||||
virtual std::pair<SoundHandle, bool> LoadSound(uint8_t *sfxdata, int length, bool monoize, FSoundLoadBuffer *buffer);
|
virtual SoundHandle LoadSound(uint8_t *sfxdata, int length, FSoundLoadBuffer *buffer);
|
||||||
virtual std::pair<SoundHandle,bool> LoadSoundBuffered(FSoundLoadBuffer *buffer, bool monoize);
|
virtual SoundHandle LoadSoundBuffered(FSoundLoadBuffer *buffer);
|
||||||
virtual std::pair<SoundHandle,bool> LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1, bool monoize = false);
|
virtual SoundHandle LoadSoundRaw(uint8_t *sfxdata, int length, int frequency, int channels, int bits, int loopstart, int loopend = -1);
|
||||||
virtual void UnloadSound(SoundHandle sfx);
|
virtual void UnloadSound(SoundHandle sfx);
|
||||||
virtual unsigned int GetMSLength(SoundHandle sfx);
|
virtual unsigned int GetMSLength(SoundHandle sfx);
|
||||||
virtual unsigned int GetSampleLength(SoundHandle sfx);
|
virtual unsigned int GetSampleLength(SoundHandle sfx);
|
||||||
|
|
|
@ -188,12 +188,9 @@ void SoundEngine::CacheSound (sfxinfo_t *sfx)
|
||||||
|
|
||||||
void SoundEngine::UnloadSound (sfxinfo_t *sfx)
|
void SoundEngine::UnloadSound (sfxinfo_t *sfx)
|
||||||
{
|
{
|
||||||
if (sfx->data3d.isValid() && sfx->data != sfx->data3d)
|
|
||||||
GSnd->UnloadSound(sfx->data3d);
|
|
||||||
if (sfx->data.isValid())
|
if (sfx->data.isValid())
|
||||||
GSnd->UnloadSound(sfx->data);
|
GSnd->UnloadSound(sfx->data);
|
||||||
sfx->data.Clear();
|
sfx->data.Clear();
|
||||||
sfx->data3d.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -579,7 +576,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
|
||||||
if (attenuation > 0 && type != SOURCE_None)
|
if (attenuation > 0 && type != SOURCE_None)
|
||||||
{
|
{
|
||||||
LoadSound3D(sfx, &SoundBuffer);
|
LoadSound3D(sfx, &SoundBuffer);
|
||||||
chan = (FSoundChan*)GSnd->StartSound3D (sfx->data3d, &listener, float(volume), rolloff, float(attenuation), pitch, basepriority, pos, vel, channel, startflags, NULL);
|
chan = (FSoundChan*)GSnd->StartSound3D (sfx->data, &listener, float(volume), rolloff, float(attenuation), pitch, basepriority, pos, vel, channel, startflags, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -685,7 +682,7 @@ void SoundEngine::RestartChannel(FSoundChan *chan)
|
||||||
|
|
||||||
LoadSound3D(sfx, &SoundBuffer);
|
LoadSound3D(sfx, &SoundBuffer);
|
||||||
chan->ChanFlags &= ~(CHANF_EVICTED|CHANF_ABSTIME);
|
chan->ChanFlags &= ~(CHANF_EVICTED|CHANF_ABSTIME);
|
||||||
ochan = (FSoundChan*)GSnd->StartSound3D(sfx->data3d, &listener, chan->Volume, &chan->Rolloff, chan->DistanceScale, chan->Pitch,
|
ochan = (FSoundChan*)GSnd->StartSound3D(sfx->data, &listener, chan->Volume, &chan->Rolloff, chan->DistanceScale, chan->Pitch,
|
||||||
chan->Priority, pos, vel, chan->EntChannel, startflags, chan);
|
chan->Priority, pos, vel, chan->EntChannel, startflags, chan);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -745,34 +742,29 @@ sfxinfo_t *SoundEngine::LoadSound(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
|
||||||
if (size > 8)
|
if (size > 8)
|
||||||
{
|
{
|
||||||
int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]);
|
int32_t dmxlen = LittleLong(((int32_t *)sfxdata.Data())[1]);
|
||||||
std::pair<SoundHandle,bool> snd;
|
|
||||||
|
|
||||||
// If the sound is voc, use the custom loader.
|
// If the sound is voc, use the custom loader.
|
||||||
if (strncmp ((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
|
if (strncmp ((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSoundVoc(sfxdata.Data(), size);
|
sfx->data = GSnd->LoadSoundVoc(sfxdata.Data(), size);
|
||||||
}
|
}
|
||||||
// If the sound is raw, just load it as such.
|
// If the sound is raw, just load it as such.
|
||||||
else if (sfx->bLoadRAW)
|
else if (sfx->bLoadRAW)
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart);
|
sfx->data = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart);
|
||||||
}
|
}
|
||||||
// Otherwise, try the sound as DMX format.
|
// Otherwise, try the sound as DMX format.
|
||||||
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
|
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
|
||||||
{
|
{
|
||||||
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
|
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
|
||||||
if (frequency == 0) frequency = 11025;
|
if (frequency == 0) frequency = 11025;
|
||||||
snd = GSnd->LoadSoundRaw(sfxdata.Data()+8, dmxlen, frequency, 1, 8, sfx->LoopStart);
|
sfx->data = GSnd->LoadSoundRaw(sfxdata.Data()+8, dmxlen, frequency, 1, 8, sfx->LoopStart);
|
||||||
}
|
}
|
||||||
// If that fails, let the sound system try and figure it out.
|
// If that fails, let the sound system try and figure it out.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSound(sfxdata.Data(), size, false, pBuffer);
|
sfx->data = GSnd->LoadSound(sfxdata.Data(), size, pBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
sfx->data = snd.first;
|
|
||||||
if(snd.second)
|
|
||||||
sfx->data3d = sfx->data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sfx->data.isValid())
|
if (!sfx->data.isValid())
|
||||||
|
@ -792,16 +784,14 @@ void SoundEngine::LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
|
||||||
{
|
{
|
||||||
if (GSnd->IsNull()) return;
|
if (GSnd->IsNull()) return;
|
||||||
|
|
||||||
if(sfx->data3d.isValid())
|
if(sfx->data.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//DPrintf(DMSG_NOTIFY, "Loading monoized sound \"%s\" (%td)\n", sfx->name.GetChars(), sfx - &S_sfx[0]);
|
//DPrintf(DMSG_NOTIFY, "Loading monoized sound \"%s\" (%td)\n", sfx->name.GetChars(), sfx - &S_sfx[0]);
|
||||||
|
|
||||||
std::pair<SoundHandle, bool> snd;
|
|
||||||
|
|
||||||
if (pBuffer->mBuffer.size() > 0)
|
if (pBuffer->mBuffer.size() > 0)
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSoundBuffered(pBuffer, true);
|
sfx->data = GSnd->LoadSoundBuffered(pBuffer);
|
||||||
}
|
}
|
||||||
else if (sfx->lumpnum >= 0)
|
else if (sfx->lumpnum >= 0)
|
||||||
{
|
{
|
||||||
|
@ -813,28 +803,26 @@ void SoundEngine::LoadSound3D(sfxinfo_t *sfx, FSoundLoadBuffer *pBuffer)
|
||||||
// If the sound is voc, use the custom loader.
|
// If the sound is voc, use the custom loader.
|
||||||
if (strncmp((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
|
if (strncmp((const char *)sfxdata.Data(), "Creative Voice File", 19) == 0)
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSoundVoc(sfxdata.Data(), size, true);
|
sfx->data = GSnd->LoadSoundVoc(sfxdata.Data(), size);
|
||||||
}
|
}
|
||||||
// If the sound is raw, just load it as such.
|
// If the sound is raw, just load it as such.
|
||||||
else if (sfx->bLoadRAW)
|
else if (sfx->bLoadRAW)
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart, true);
|
sfx->data = GSnd->LoadSoundRaw(sfxdata.Data(), size, sfx->RawRate, 1, 8, sfx->LoopStart);
|
||||||
}
|
}
|
||||||
// Otherwise, try the sound as DMX format.
|
// Otherwise, try the sound as DMX format.
|
||||||
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
|
else if (((uint8_t *)sfxdata.Data())[0] == 3 && ((uint8_t *)sfxdata.Data())[1] == 0 && dmxlen <= size - 8)
|
||||||
{
|
{
|
||||||
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
|
int frequency = LittleShort(((uint16_t *)sfxdata.Data())[1]);
|
||||||
if (frequency == 0) frequency = 11025;
|
if (frequency == 0) frequency = 11025;
|
||||||
snd = GSnd->LoadSoundRaw(sfxdata.Data() + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1, true);
|
sfx->data = GSnd->LoadSoundRaw(sfxdata.Data() + 8, dmxlen, frequency, 1, 8, sfx->LoopStart, -1);
|
||||||
}
|
}
|
||||||
// If that fails, let the sound system try and figure it out.
|
// If that fails, let the sound system try and figure it out.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snd = GSnd->LoadSound(sfxdata.Data(), size, true, pBuffer);
|
sfx->data = GSnd->LoadSound(sfxdata.Data(), size, pBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sfx->data3d = snd.first;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -1535,7 +1523,6 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc
|
||||||
sfxinfo_t &newsfx = S_sfx.Last();
|
sfxinfo_t &newsfx = S_sfx.Last();
|
||||||
|
|
||||||
newsfx.data.Clear();
|
newsfx.data.Clear();
|
||||||
newsfx.data3d.Clear();
|
|
||||||
newsfx.name = logicalname;
|
newsfx.name = logicalname;
|
||||||
newsfx.lumpnum = lump;
|
newsfx.lumpnum = lump;
|
||||||
newsfx.next = 0;
|
newsfx.next = 0;
|
||||||
|
|
|
@ -18,9 +18,6 @@ struct sfxinfo_t
|
||||||
// Next field is for use by the system sound interface.
|
// Next field is for use by the system sound interface.
|
||||||
// A non-null data means the sound has been loaded.
|
// A non-null data means the sound has been loaded.
|
||||||
SoundHandle data;
|
SoundHandle data;
|
||||||
// Also for the sound interface. Used for 3D positional
|
|
||||||
// sounds, may be the same as data.
|
|
||||||
SoundHandle data3d;
|
|
||||||
|
|
||||||
FString name; // [RH] Sound name defined in SNDINFO
|
FString name; // [RH] Sound name defined in SNDINFO
|
||||||
int lumpnum; // lump number of sfx
|
int lumpnum; // lump number of sfx
|
||||||
|
@ -59,7 +56,6 @@ struct sfxinfo_t
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
data.Clear();
|
data.Clear();
|
||||||
data3d.Clear();
|
|
||||||
lumpnum = -1; // lump number of sfx
|
lumpnum = -1; // lump number of sfx
|
||||||
next = -1;
|
next = -1;
|
||||||
index = 0; // [RH] For hashing
|
index = 0; // [RH] For hashing
|
||||||
|
|
Loading…
Reference in a new issue