Fix sound characteristics calculations

Ogg file has incorrectly calculated size and samples as
result calculation of volume and timings have used
incorrect test samples for sterio sound.

Checked with compare ogg and wav samples from 25th
Anniversary mod:
```
ffmpeg -i 25acu/sound/world/goreshit.wav 25acu/sound/world/goreshit-ogg.wav
```

Soundlist:
```
]/soundlist
 (16b)  1404340(2 ch) world/goreshit.wav -11.7 dB 351.1s:15.0..0.3..1.1..2.0
 (16b)  1404340(2 ch) world/goreshit-ogg.wav -11.5 dB 351.1s:15.0..18.4..1.4..2.0
```

Fixes:
* https://github.com/glhrmfrts/q25_game/issues/8
* https://github.com/yquake2/yquake2/issues/991
This commit is contained in:
Denis Pauk 2023-04-14 18:22:12 +03:00
parent c2d80c64ee
commit 538aadb9dc
2 changed files with 11 additions and 8 deletions

View file

@ -739,23 +739,26 @@ OGG_LoadAsWav(char *filename, wavinfo_t *info, void **buffer)
info->channels = ogg2wav_file->channels;
info->loopstart = -1;
/* return length * channels */
info->samples = stb_vorbis_stream_length_in_samples(ogg2wav_file) / ogg2wav_file->channels;
info->samples = stb_vorbis_stream_length_in_samples(ogg2wav_file) * info->channels;
info->dataofs = 0;
/* alloc memory for uncompressed wav */
final_buffer = Z_Malloc(info->samples * sizeof(short) * ogg2wav_file->channels);
final_buffer = Z_Malloc(info->samples * sizeof(short));
/* load sampleas to buffer */
read_samples = stb_vorbis_get_samples_short_interleaved(
ogg2wav_file, info->channels, final_buffer,
info->samples * ogg2wav_file->channels);
info->samples);
if (read_samples > 0)
{
/* fix sample list size*/
if (read_samples < info->samples)
if ((read_samples * info->channels) != info->samples)
{
info->samples = read_samples;
Com_DPrintf("%s: incorrect size: %d != %d\n",
filename, info->samples, read_samples * info->channels);
info->samples = read_samples * info->channels;
}
/* copy to final result */
@ -772,7 +775,7 @@ OGG_LoadAsWav(char *filename, wavinfo_t *info, void **buffer)
if (ogg2wav_file)
{
stb_vorbis_close(ogg2wav_file);
stb_vorbis_close(ogg2wav_file);
}
FS_FreeFile(temp_buffer);

View file

@ -525,10 +525,10 @@ S_LoadSound(sfx_t *s)
s->is_silenced_muzzle_flash = true;
}
S_GetVolume(data + info.dataofs, info.samples * info.channels,
S_GetVolume(data + info.dataofs, info.samples,
info.width, &sound_volume);
S_GetStatistics(data + info.dataofs, info.samples * info.channels,
S_GetStatistics(data + info.dataofs, info.samples,
info.width, info.channels, sound_volume, &begin_length, &end_length,
&attack_length, &fade_length);