Vorbis decode example code fails to produce valid pcm data if not stereo
The code in decoder_example.c works fine as long as one does not decode audio
data that has been encoded from a non stereo source.
The original code in the decoder_example.c file looks like this:
for(i=0;i<vi.channels;i++){
ogg_int16_t *ptr=convbuffer+i;
float *mono=pcm[i];
for(j=0;j<bout;j++){
int val=mono[j]*32767.f;
if(val>32767){val=32767; clipflag=1;}
if(val<-32768){val=-32768; clipflag=1;}
*ptr=val;
ptr+=2;
}
}
This works just fine on stereo. ptr is set to the right interleaved start
address. But in the following loop ptr should fill all samples on one channel.
So ptr is incremented to jump over the other channels. Here's the bug
in the original code, ptr+=2 is hardcoded for stereo output.
Without hardcoding, here's the working code:
for(i=0;i<vi.channels;i++){
ogg_int16_t *ptr=convbuffer+i;
float *mono=pcm[i];
for(j=0;j<bout;j++){
int val=mono[j]*32767.f;
if(val>32767){val=32767; clipflag=1;}
if(val<-32768){val=-32768; clipflag=1;}
*ptr=val;
ptr+=vi.channels;
}
}
I have tested it on several audio sources, its all working. But I have not
tested it on >2 channel audio sources. I believe it should work, but no proof
from me...
>8) Best regards
Christian Meinhardt
Neuland Multimedia GmbH
www.neulandmm.de