| 269 | |
| 270 | |
| 271 | int WavInFile::read(unsigned char *buffer, int maxElems) |
| 272 | { |
| 273 | int numBytes; |
| 274 | uint afterDataRead; |
| 275 | |
| 276 | // ensure it's 8 bit format |
| 277 | if (header.format.bits_per_sample != 8) |
| 278 | { |
| 279 | ST_THROW_RT_ERROR("Error: WavInFile::read(char*, int) works only with 8bit samples."); |
| 280 | } |
| 281 | assert(sizeof(char) == 1); |
| 282 | |
| 283 | numBytes = maxElems; |
| 284 | afterDataRead = dataRead + numBytes; |
| 285 | if (afterDataRead > header.data.data_len) |
| 286 | { |
| 287 | // Don't read more samples than are marked available in header |
| 288 | numBytes = (int)header.data.data_len - (int)dataRead; |
| 289 | assert(numBytes >= 0); |
| 290 | } |
| 291 | |
| 292 | assert(buffer); |
| 293 | numBytes = (int)fread(buffer, 1, numBytes, fptr); |
| 294 | dataRead += numBytes; |
| 295 | |
| 296 | return numBytes; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | int WavInFile::read(short *buffer, int maxElems) |