mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
reuse resampler object
This commit is contained in:
parent
c1c1b1f749
commit
edbad56202
1 changed files with 25 additions and 8 deletions
|
@ -2,8 +2,6 @@
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "speex_resampler.h"
|
#include "speex_resampler.h"
|
||||||
|
|
||||||
// FIXME: call a real resampler :-)
|
|
||||||
|
|
||||||
void *Snd_Resample(int inrate, int inwidth, int innumsamples, int channels, const void *indata,
|
void *Snd_Resample(int inrate, int inwidth, int innumsamples, int channels, const void *indata,
|
||||||
int outrate, int outwidth, int *outnumsamples)
|
int outrate, int outwidth, int *outnumsamples)
|
||||||
{
|
{
|
||||||
|
@ -32,19 +30,36 @@ void *Snd_Resample(int inrate, int inwidth, int innumsamples, int channels, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the resampler
|
// Call the resampler
|
||||||
SpeexResamplerState *resampler = speex_resampler_init(channels, inrate, outrate, 10, NULL);
|
static SpeexResamplerState *st = NULL;
|
||||||
|
if (st == NULL)
|
||||||
|
{
|
||||||
|
st = speex_resampler_init(channels, inrate, outrate, 5, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
speex_resampler_reset_mem(st);
|
||||||
|
}
|
||||||
|
speex_resampler_set_rate(st, inrate, outrate);
|
||||||
|
|
||||||
*outnumsamples = 0;
|
*outnumsamples = 0;
|
||||||
unsigned int consumedtotal = 0;
|
unsigned int consumedtotal = 0;
|
||||||
|
unsigned int outputtotal = 0;
|
||||||
unsigned int loops = 0;
|
unsigned int loops = 0;
|
||||||
unsigned int consumed, output;
|
unsigned int consumed, output;
|
||||||
while (consumedtotal < innumsamples)
|
while (consumedtotal < innumsamples)
|
||||||
{
|
{
|
||||||
|
int roomToConsume, roomToOutput;
|
||||||
|
|
||||||
consumed = innumsamples - consumedtotal;
|
consumed = innumsamples - consumedtotal;
|
||||||
output = maxsamples - (*outnumsamples);
|
output = maxsamples - outputtotal;
|
||||||
speex_resampler_process_interleaved_int(resampler, in16bit, &consumed, outdata, &output);
|
|
||||||
|
roomToConsume = consumed;
|
||||||
|
roomToOutput = output;
|
||||||
|
|
||||||
|
speex_resampler_process_interleaved_int(st, in16bit + consumedtotal, &consumed, outdata + outputtotal, &output);
|
||||||
consumedtotal += consumed;
|
consumedtotal += consumed;
|
||||||
(*outnumsamples) += output;
|
outputtotal += output;
|
||||||
|
|
||||||
loops++;
|
loops++;
|
||||||
if (loops > 100)
|
if (loops > 100)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +67,9 @@ void *Snd_Resample(int inrate, int inwidth, int innumsamples, int channels, cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
speex_resampler_destroy(resampler);
|
*outnumsamples = outputtotal;
|
||||||
|
|
||||||
|
//speex_resampler_destroy(resampler);
|
||||||
|
|
||||||
if (in16bit != indata)
|
if (in16bit != indata)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue