From b7c2c476a88a9daa0a0b357807e3df4099a74869 Mon Sep 17 00:00:00 2001 From: SNMetamorph Date: Sun, 1 Dec 2024 19:22:25 +0400 Subject: [PATCH] engine: soundlib: implemented sound looping feature for Ogg Vorbis --- engine/common/soundlib/snd_ogg_vorbis.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/engine/common/soundlib/snd_ogg_vorbis.c b/engine/common/soundlib/snd_ogg_vorbis.c index 0b05e492..39673c87 100644 --- a/engine/common/soundlib/snd_ogg_vorbis.c +++ b/engine/common/soundlib/snd_ogg_vorbis.c @@ -67,6 +67,23 @@ static const ov_callbacks ov_callbacks_fs = { ================================================================= */ +static void Sound_ScanVorbisComments( OggVorbis_File *vf ) +{ + const char *value; + vorbis_comment *vc = ov_comment( vf, -1 ); + if( vc ) + { + if(( value = vorbis_comment_query( vc, "LOOPSTART", 0 ))) { + sound.loopstart = Q_atoi( value ); + SetBits( sound.flags, SOUND_LOOPED ); + } + else if(( value = vorbis_comment_query( vc, "LOOP_START", 0 ))) { + sound.loopstart = Q_atoi( value ); + SetBits( sound.flags, SOUND_LOOPED ); + } + } +} + qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t filesize ) { long ret; @@ -98,6 +115,9 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t sound.size = sound.samples * sound.width * sound.channels; sound.wav = (byte *)Mem_Calloc( host.soundpool, sound.size ); + SetBits( sound.flags, SOUND_RESAMPLE ); + Sound_ScanVorbisComments( &vorbisFile ); + while(( ret = ov_read( &vorbisFile, (char*)sound.wav + written, sound.size - written, 0, sound.width, 1, §ion )) != 0 ) { if( ret < 0 ) {