engine: soundlib: implemented sound looping feature for Ogg Opus
This commit is contained in:
parent
770054daaf
commit
fa152bef20
1 changed files with 21 additions and 2 deletions
|
@ -75,6 +75,23 @@ static const OpusFileCallbacks op_callbacks_fs = {
|
||||||
|
|
||||||
=================================================================
|
=================================================================
|
||||||
*/
|
*/
|
||||||
|
static void Sound_ScanOpusComments( const OggOpusFile *of )
|
||||||
|
{
|
||||||
|
const char *value;
|
||||||
|
const OpusTags *tags = op_tags( of, -1 );
|
||||||
|
if( tags )
|
||||||
|
{
|
||||||
|
if(( value = opus_tags_query( tags, "LOOPSTART", 0 ))) {
|
||||||
|
sound.loopstart = Q_atoi( value );
|
||||||
|
SetBits( sound.flags, SOUND_LOOPED );
|
||||||
|
}
|
||||||
|
else if(( value = opus_tags_query( tags, "LOOP_START", 0 ))) {
|
||||||
|
sound.loopstart = Q_atoi( value );
|
||||||
|
SetBits( sound.flags, SOUND_LOOPED );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t filesize )
|
qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t filesize )
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
|
@ -105,17 +122,19 @@ qboolean Sound_LoadOggOpus( const char *name, const byte *buffer, fs_offset_t fi
|
||||||
sound.rate = 48000;
|
sound.rate = 48000;
|
||||||
sound.width = 2; // always 16-bit PCM
|
sound.width = 2; // always 16-bit PCM
|
||||||
sound.type = WF_PCMDATA;
|
sound.type = WF_PCMDATA;
|
||||||
sound.flags = SOUND_RESAMPLE;
|
|
||||||
sound.samples = op_pcm_total( of, -1 );
|
sound.samples = op_pcm_total( of, -1 );
|
||||||
sound.size = sound.samples * sound.width * sound.channels;
|
sound.size = sound.samples * sound.width * sound.channels;
|
||||||
sound.wav = (byte *)Mem_Calloc( host.soundpool, sound.size );
|
sound.wav = (byte *)Mem_Calloc( host.soundpool, sound.size );
|
||||||
|
|
||||||
// skip undesired samples before playing sound
|
// skip undesired samples before playing sound
|
||||||
if( op_pcm_seek( of, opusHead->pre_skip ) < 0 ) {
|
if( op_pcm_seek( of, opusHead->pre_skip ) < 0 ) {
|
||||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): pre-skip error\n", __func__, file.name );
|
Con_DPrintf( S_ERROR "%s: failed to load (%s): pre-skip error\n", __func__, file.name );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetBits( sound.flags, SOUND_RESAMPLE );
|
||||||
|
Sound_ScanOpusComments( of );
|
||||||
|
|
||||||
while(( ret = op_read( of, (opus_int16*)(sound.wav + written), (sound.size - written) / sound.width, NULL )) != 0 )
|
while(( ret = op_read( of, (opus_int16*)(sound.wav + written), (sound.size - written) / sound.width, NULL )) != 0 )
|
||||||
{
|
{
|
||||||
if( ret < 0 ) {
|
if( ret < 0 ) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue