- // Calculate resampled length
- len = (double)done * (double)shm->format.speed / (double)vi->rate;
-
- // Resample it
- memsize = (size_t)len + sizeof (*sb) - sizeof (sb->data);
- sb = (sfxbuffer_t *)Mem_Alloc (snd_mempool, memsize);
- s->memsize += memsize;
- 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 = (unsigned int)ResampleSfx ((unsigned char *)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 = -1;
+ sfx->flags &= ~SFXFLAG_STREAMED;