+ int hs;
+
+ float **pcm;
+ long samples;
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);
+
+ while(1){
+ if(vf->ready_state==INITSET){
+ samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
+ if(samples)break;
+ }
+
+ /* suck in another packet */
+ {
+ int ret=_fetch_and_process_packet(vf,NULL,1,1);
+ if(ret==OV_EOF)
+ return(0);
+ if(ret<=0)
+ return(ret);
+ }
+
+ }
+
+ if(samples>0){
+
+ /* yay! proceed to pack data into the byte buffer */
+
+ long channels=ov_info(vf,-1)->channels;
+ long bytespersample=word * channels;
+ vorbis_fpu_control fpu;
+ if(samples>length/bytespersample)samples=length/bytespersample;
+
+ if(samples <= 0)
+ return OV_EINVAL;
+
+ /* Here. */
+ if(filter)
+ filter(pcm,channels,samples,filter_param);
+
+ /* a tight loop to pack each size */
+ {
+ int val;
+ if(word==1){
+ int off=(sgned?0:128);
+ vorbis_fpu_setround(&fpu);
+ for(j=0;j<samples;j++)
+ for(i=0;i<channels;i++){
+ val=vorbis_ftoi(pcm[i][j]*128.f);
+ if(val>127)val=127;
+ else if(val<-128)val=-128;
+ *buffer++=val+off;
+ }
+ vorbis_fpu_restore(fpu);
+ }else{
+ int off=(sgned?0:32768);
+
+ if(host_endian==bigendianp){
+ if(sgned){
+
+ vorbis_fpu_setround(&fpu);
+ for(i=0;i<channels;i++) { /* It's faster in this order */
+ float *src=pcm[i];
+ short *dest=((short *)buffer)+i;
+ for(j=0;j<samples;j++) {
+ val=vorbis_ftoi(src[j]*32768.f);
+ if(val>32767)val=32767;
+ else if(val<-32768)val=-32768;
+ *dest=val;
+ dest+=channels;
+ }
+ }
+ vorbis_fpu_restore(fpu);
+
+ }else{
+
+ vorbis_fpu_setround(&fpu);
+ for(i=0;i<channels;i++) {
+ float *src=pcm[i];
+ short *dest=((short *)buffer)+i;
+ for(j=0;j<samples;j++) {
+ val=vorbis_ftoi(src[j]*32768.f);
+ if(val>32767)val=32767;
+ else if(val<-32768)val=-32768;
+ *dest=val+off;
+ dest+=channels;
+ }
+ }
+ vorbis_fpu_restore(fpu);
+
+ }
+ }else if(bigendianp){
+
+ vorbis_fpu_setround(&fpu);
+ for(j=0;j<samples;j++)
+ for(i=0;i<channels;i++){
+ val=vorbis_ftoi(pcm[i][j]*32768.f);
+ if(val>32767)val=32767;
+ else if(val<-32768)val=-32768;
+ val+=off;
+ *buffer++=(val>>8);
+ *buffer++=(val&0xff);
+ }
+ vorbis_fpu_restore(fpu);
+
+ }else{
+ int val;
+ vorbis_fpu_setround(&fpu);
+ for(j=0;j<samples;j++)
+ for(i=0;i<channels;i++){
+ val=vorbis_ftoi(pcm[i][j]*32768.f);
+ if(val>32767)val=32767;
+ else if(val<-32768)val=-32768;
+ val+=off;
+ *buffer++=(val&0xff);
+ *buffer++=(val>>8);
+ }
+ vorbis_fpu_restore(fpu);
+
+ }
+ }
+ }
+
+ vorbis_synthesis_read(&vf->vd,samples);
+ hs=vorbis_synthesis_halfrate_p(vf->vi);
+ vf->pcm_offset+=(samples<<hs);
+ if(bitstream)*bitstream=vf->current_link;
+ return(samples*bytespersample);
+ }else{
+ return(samples);
+ }
+}
+
+long ov_read(OggVorbis_File *vf,char *buffer,int length,
+ int bigendianp,int word,int sgned,int *bitstream){
+ return ov_read_filter(vf, buffer, length, bigendianp, word, sgned, bitstream, NULL, NULL);
+}
+
+/* input values: pcm_channels) a float vector per channel of output
+ length) the sample length being read by the app
+
+ return values: <0) error/hole in data (OV_HOLE), partial open (OV_EINVAL)
+ 0) EOF
+ n) number of samples of PCM actually returned. The
+ below works on a packet-by-packet basis, so the
+ return length is not related to the 'length' passed
+ in, just guaranteed to fit.
+
+ *section) set to the logical bitstream number */
+
+
+
+long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
+ int *bitstream){
+
+ if(vf->ready_state<OPENED)return(OV_EINVAL);