/*-------------- Telecommunications & Signal Processing Lab --------------- McGill University Routine: int AFreadF4 (AFILE *AFp, long int offs, float Fbuff[], int Nreq) Purpose: Read 32-bit float data from an audio file (return float values) Description: This routine reads a specified number of 32-bit float samples from an audio file. The data in the file is converted to float format on output. The file must have been opened using subroutine AFopenRead. Parameters: <- int AFreadF4 Number of data values transferred from the file. On reaching the end of the file, this value may be less than Nreq. -> AFILE *AFp Audio file pointer for an audio file opened by AFopenRead -> long int offs Offset into the file in samples. The parameter offs must be non- negative. <- float Fbuff[] Array of floats to receive the samples -> int Nreq Number of samples requested. Nreq may be zero. Author / revision: P. Kabal Copyright (C) 1996 $Revision: 1.20 $ $Date: 1996/08/14 18:01:45 $ -------------------------------------------------------------------------*/ static char rcsid [] = "$Id: AFreadF4.c 1.20 1996/08/14 AFsp-V2R1 $"; #include #include #include #include #define LW FDL_FLOAT32 #define MINV(a, b) (((a) < (b)) ? (a) : (b)) #define NBBUF 8192 int AFreadF4 (AFp, offs, Fbuff, Nreq) AFILE *AFp; long int offs; float Fbuff[]; int Nreq; { long int offsb; int Nd, is, n, i, Nval; float4_t Buf[NBBUF/LW]; float4_t *B; unsigned char *cp; unsigned char t; offsb = AFp->Start + LW * offs; Nd = (int) MINV (Nreq, (AFp->End - offsb) / LW); /* Nd can be negative */ for (is = 0; is < Nd; ) { /* Read data from the audio file */ n = MINV (NBBUF / LW, Nd - is); Nval = FLreadFile (AFp->fp, (long int) (offsb + is * LW), (void *) Buf, (size_t) LW, (size_t) n); if (Nval != n) UThalt ("AFreadF4: Unexpected end-of-file"); /* Byte swap and convert to float */ B = Buf; for (i = 0; i < Nval; ++i) { if (AFp->Swapb == DS_SWAP) { cp = (unsigned char *) B; t = cp[3]; cp[3] = cp[0]; cp[0] = t; t = cp[2]; cp[2] = cp[1]; cp[1] = t; } Fbuff[is] = AFp->ScaleF * (*B); ++is; ++B; } } return is; }