///////////////////////////////////////////////////////
| 204 | |
| 205 | //////////////////////////////////////////////////////////// |
| 206 | std::uint64_t SoundFileReaderOgg::read(std::int16_t* samples, std::uint64_t maxCount) |
| 207 | { |
| 208 | assert(m_vorbis.datasource && "Vorbis datasource is missing. Call SoundFileReaderOgg::open() to initialize it."); |
| 209 | |
| 210 | // Try to read the requested number of samples, stop only on error or end of file |
| 211 | std::uint64_t count = 0; |
| 212 | while (count < maxCount) |
| 213 | { |
| 214 | const int bytesToRead = static_cast<int>(maxCount - count) * static_cast<int>(sizeof(std::int16_t)); |
| 215 | const long bytesRead = ov_read(&m_vorbis, reinterpret_cast<char*>(samples), bytesToRead, SFML_IS_BIG_ENDIAN, 2, 1, nullptr); |
| 216 | if (bytesRead > 0) |
| 217 | { |
| 218 | const long samplesRead = bytesRead / static_cast<long>(sizeof(std::int16_t)); |
| 219 | count += static_cast<std::uint64_t>(samplesRead); |
| 220 | samples += samplesRead; |
| 221 | } |
| 222 | else |
| 223 | { |
| 224 | // error or end of file |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | return count; |
| 230 | } |
| 231 | |
| 232 | |
| 233 | //////////////////////////////////////////////////////////// |