1
0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-02 00:42:53 +01:00

Fixed sound duration for missing sounds.

Issue #140.
This commit is contained in:
Muzychenko Andrey 2022-06-14 11:46:11 +03:00
parent 8017734de4
commit 5e42f37fba
2 changed files with 8 additions and 6 deletions

View File

@ -447,6 +447,8 @@ int TPinballTable::Message(int code, float value)
pinball::MissTextBox->Clear();
LightGroup->Message(28, 0.2f);
auto time = loader::play_sound(SoundIndex1, nullptr, "TPinballTable2");
if (time < 0)
time = 5.0f;
LightShowTimer = timer::set(time, this, LightShow_timeout);
}

View File

@ -94,8 +94,7 @@ void loader::loadfrom(DatFile* datFile)
{
if (sound_count < 65)
{
sound_list[sound_count].WavePtr = nullptr;
sound_list[sound_count].GroupIndex = groupIndex;
sound_list[sound_count] = {nullptr, groupIndex, 0, 0};
sound_count++;
}
}
@ -108,8 +107,7 @@ void loader::unload()
for (int index = 1; index < sound_count; ++index)
{
Sound::FreeSound(sound_list[index].WavePtr);
sound_list[index].Loaded = 0;
sound_list[index].WavePtr = nullptr;
sound_list[index] = {};
}
sound_count = 1;
@ -158,16 +156,18 @@ int loader::get_sound_id(int groupIndex)
fileName.insert(0, "SOUND");
}
float duration = -1;
auto filePath = pinball::make_path_name(fileName);
auto file = fopenu(filePath.c_str(), "rb");
if (file)
{
fread(&wavHeader, 1, sizeof wavHeader, file);
fclose(file);
auto sampleCount = wavHeader.data_size / (wavHeader.channels * (wavHeader.bits_per_sample / 8.0));
duration = static_cast<float>(sampleCount / wavHeader.sample_rate);
}
auto sampleCount = wavHeader.data_size / (wavHeader.channels * (wavHeader.bits_per_sample / 8.0));
sound_list[soundIndex].Duration = static_cast<float>(sampleCount / wavHeader.sample_rate);
sound_list[soundIndex].Duration = duration;
sound_list[soundIndex].WavePtr = Sound::LoadWaveFile(filePath);
}
}