- // Calculate resampled length
- len = (double)done * (double)shm->format.speed / (double)vi->rate;
-
- // Resample it
- sb = Mem_Alloc (s->mempool, (size_t)len + sizeof (*sb) - sizeof (sb->data));
- s->fetcher_data = sb;
- s->fetcher = &wav_fetcher;
- s->format.speed = vi->rate;
- s->format.width = 2; // We always work with 16 bits samples
- s->format.channels = vi->channels;
- s->loopstart = -1;
- s->flags &= ~SFXFLAG_STREAMED;
-
- sb->length = ResampleSfx (buff, (size_t)done / (vi->channels * 2), &s->format, sb->data, s->name);
- s->format.speed = shm->format.speed;
- s->total_length = sb->length;
- sb->offset = 0;
+ // Build the sound buffer
+ ogg_format.speed = vi->rate;
+ ogg_format.channels = vi->channels;
+ ogg_format.width = 2; // We always work with 16 bits samples
+ sb = Snd_CreateSndBuffer ((unsigned char *)buff, (size_t)done / (vi->channels * 2), &ogg_format, snd_renderbuffer->format.speed);
+ if (sb == NULL)
+ {
+ qov_clear (&vf);
+ Mem_Free (data);
+ Mem_Free (buff);
+ return false;
+ }
+
+ sfx->fetcher = &wav_fetcher;
+ sfx->fetcher_data = sb;
+
+ sfx->total_length = sb->nbframes;
+ sfx->memsize += sb->maxframes * sb->format.channels * sb->format.width + sizeof (*sb) - sizeof (sb->samples);
+
+ sfx->loopstart = sfx->total_length;
+ sfx->flags &= ~SFXFLAG_STREAMED;
+ vc = qov_comment(&vf, -1);
+ if(vc)
+ {
+ loopcomment = qvorbis_comment_query(vc, "LOOP_START", 0);
+ if(loopcomment)
+ sfx->loopstart = bound(0, (unsigned int) (atoi(loopcomment) * (double)snd_renderbuffer->format.speed / (double)sb->format.speed), sfx->total_length);
+ }