Fixed sndfile loader sometimes not working

Former-commit-id: b76e823dff63ae125fc25336a0b730bcf8f86901
This commit is contained in:
Lynix 2013-12-20 19:30:26 +01:00
parent 19d5b62009
commit 56438f6ecd
1 changed files with 10 additions and 6 deletions

View File

@ -76,6 +76,8 @@ namespace
NazaraUnused(parameters); NazaraUnused(parameters);
SF_INFO info; SF_INFO info;
info.format = 0;
SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &info, &stream); SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &info, &stream);
if (file) if (file)
{ {
@ -90,15 +92,17 @@ namespace
{ {
NazaraUnused(parameters); NazaraUnused(parameters);
SF_INFO infos; SF_INFO info;
SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &infos, &stream); info.format = 0;
SNDFILE* file = sf_open_virtual(&callbacks, SFM_READ, &info, &stream);
if (!file) if (!file)
{ {
NazaraError("Failed to load sound file: " + NzString(sf_strerror(file))); NazaraError("Failed to load sound file: " + NzString(sf_strerror(file)));
return false; return false;
} }
nzAudioFormat format = NzAudio::GetAudioFormat(infos.channels); nzAudioFormat format = NzAudio::GetAudioFormat(info.channels);
if (format == nzAudioFormat_Unknown) if (format == nzAudioFormat_Unknown)
{ {
NazaraError("Channel count not handled"); NazaraError("Channel count not handled");
@ -110,10 +114,10 @@ namespace
// https://github.com/LaurentGomila/SFML/issues/271 // https://github.com/LaurentGomila/SFML/issues/271
// http://www.mega-nerd.com/libsndfile/command.html#SFC_SET_SCALE_FLOAT_INT_READ // http://www.mega-nerd.com/libsndfile/command.html#SFC_SET_SCALE_FLOAT_INT_READ
///FIXME: Seulement le Vorbis ? ///FIXME: Seulement le Vorbis ?
if (infos.format & SF_FORMAT_VORBIS) if (info.format & SF_FORMAT_VORBIS)
sf_command(file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE); sf_command(file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE);
sf_count_t sampleCount = infos.frames*infos.channels; sf_count_t sampleCount = info.frames * info.channels;
std::unique_ptr<nzInt16[]> samples(new nzInt16[sampleCount]); std::unique_ptr<nzInt16[]> samples(new nzInt16[sampleCount]);
if (sf_read_short(file, samples.get(), sampleCount) != sampleCount) if (sf_read_short(file, samples.get(), sampleCount) != sampleCount)
@ -124,7 +128,7 @@ namespace
return false; return false;
} }
if (!soundBuffer->Create(format, static_cast<unsigned int>(sampleCount), infos.samplerate, samples.get())) if (!soundBuffer->Create(format, static_cast<unsigned int>(sampleCount), info.samplerate, samples.get()))
{ {
sf_close(file); sf_close(file);
NazaraError("Failed to create sound buffer"); NazaraError("Failed to create sound buffer");