- */
-
- // We work with 200ms (1/5 sec) steps to avoid rounding errors
- time_start = real_start * 5 / snd_renderbuffer->format.speed;
- modplug_start = time_start * (1000 / 5);
-
- Con_DPrintf("warning: mod file needed to seek (to %d)\n", modplug_start);
-
- ModPlug_Seek(per_ch->mf, modplug_start);
- sb->nbframes = 0;
-
- real_start = (float)modplug_start / 1000 * snd_renderbuffer->format.speed;
- if (*start - real_start + nbsampleframes > sb->maxframes)
- {
- Con_Printf ("ModPlug_FetchSound: stream buffer too small after seek (%u sample frames required)\n",
- *start - real_start + nbsampleframes);
- per_ch->sb_offset = real_start;
- return NULL;
- }
- }
- // Else, move forward the samples we need to keep in the sound buffer
- else
- {
- memmove (sb->samples, sb->samples + (real_start - per_ch->sb_offset) * factor, newlength * factor);
- sb->nbframes = newlength;
- }
-
- per_ch->sb_offset = real_start;
-
- // We add exactly 1 sec of sound to the buffer:
- // 1- to ensure we won't lose any sample during the resampling process
- // 2- to force one call to ModPlug_FetchSound per second to regulate the workload
- if (sb->format.speed + sb->nbframes > sb->maxframes)
- {
- Con_Printf ("ModPlug_FetchSound: stream buffer overflow (%u sample frames / %u)\n",
- sb->format.speed + sb->nbframes, sb->maxframes);
- return NULL;
- }
- newlength = per_sfx->format.speed * factor; // -> 1 sec of sound before resampling
- if(newlength > (int)sizeof(resampling_buffer))
- newlength = sizeof(resampling_buffer);
-
- // Decompress in the resampling_buffer
- done = 0;
- while ((ret = ModPlug_Read (per_ch->mf, (char *)&resampling_buffer[done], (int)(newlength - done))) > 0)
- done += ret;
- if(done < newlength)
- {
- // Argh. We didn't get as many samples as we wanted. Probably
- // libmodplug forgot what mLoopCount==-1 means... basically, this means
- // we can't loop like this. Try to let DP fix it later...
- per_sfx->sfx->total_length = (real_start + ((size_t)done / (size_t)factor));
- per_sfx->sfx->loopstart = 0;
-
- if(newlength != done)
- Con_DPrintf("ModPlug_Fetch: wanted: %d, got: %d\n", newlength, done);