wav now supports any combination of frequency, bitrate, channels, (except 11khz+16bit)

This commit is contained in:
nehalmistry 2003-04-16 19:00:53 +00:00
parent 91032d6a87
commit e9311431ec

View file

@ -69,7 +69,15 @@ local int WavReadStream(Sample *sample, void *buf, int len)
int i;
int x;
int y;
int rate;
int f;
int c;
int freqratio;
int chanratio;
int brratio;
int chansize;
int samplesize;
int divide;
int offset;
data = (WavData*) sample->User;
@ -79,18 +87,36 @@ local int WavReadStream(Sample *sample, void *buf, int len)
memcpy(sample->Data, data->PointerInBuffer, sample->Length);
data->PointerInBuffer = sample->Data;
n = WAV_BUFFER_SIZE - sample->Length;
n = WAV_BUFFER_SIZE - sample->Length - 4;
rate = 44100 / sample->Frequency;
i = CLread(data->WavFile, sndbuf, n/rate);
freqratio = (44100 / sample->Frequency);
samplesize = sample->SampleSize / 8; // number of bytes per sample
brratio = 4 / samplesize;
chansize = samplesize / sample->Channels; // number of bytes per channel
chanratio = 2 / sample->Channels;
divide=freqratio*(brratio)/chanratio;
for (x = 0; x < i*rate; x += 4) {
for (y = 0; y < 4; ++y) {
data->PointerInBuffer[sample->Length + x + y] = sndbuf[x/rate+(y&1)];
i = CLread(data->WavFile, sndbuf, n/divide);
f = 0;
for (x = 0; x < i*divide; x += 4) { // x is the sample
for (c = 0; c < 2; ++c) { // c is the channel in the sample
for (y = 0; y < 2; ++y) { // y is the byte in the channel
// FIXME: 11khz 16-bit per channel not supported
offset=( ((x/4)/freqratio)*samplesize*chanratio +
(c/chanratio)*chansize + y/(2/chansize));
// FIXME: what's correct way?
if (offset >= i*divide) {
break;
}
data->PointerInBuffer[sample->Length + x + c*2 + y] =
sndbuf[offset] + (chansize == 1 ? 127 : 0);
}
}
}
sample->Length += i*rate;
sample->Length += i*divide;
if (sample->Length < len) {
len = sample->Length;