///////////////////////////////////////////////////////
| 196 | |
| 197 | //////////////////////////////////////////////////////////// |
| 198 | void SoundFileWriterOgg::write(const std::int16_t* samples, std::uint64_t count) |
| 199 | { |
| 200 | // Vorbis has issues with buffers that are too large, so we ask for 64K |
| 201 | constexpr int bufferSize = 65536; |
| 202 | |
| 203 | // A frame contains a sample from each channel |
| 204 | int frameCount = static_cast<int>(count / m_channelCount); |
| 205 | |
| 206 | while (frameCount > 0) |
| 207 | { |
| 208 | // Prepare a buffer to hold our samples |
| 209 | float** buffer = vorbis_analysis_buffer(&m_state, bufferSize); |
| 210 | assert(buffer && "Vorbis buffer failed to allocate"); |
| 211 | |
| 212 | // Write the samples to the buffer, converted to float and remapped to target channels |
| 213 | for (int i = 0; i < std::min(frameCount, bufferSize); ++i) |
| 214 | { |
| 215 | for (unsigned int j = 0; j < m_channelCount; ++j) |
| 216 | buffer[j][i] = samples[m_remapTable[j]] / 32767.0f; |
| 217 | |
| 218 | samples += m_channelCount; |
| 219 | } |
| 220 | |
| 221 | // Tell the library how many samples we've written |
| 222 | vorbis_analysis_wrote(&m_state, std::min(frameCount, bufferSize)); |
| 223 | |
| 224 | frameCount -= bufferSize; |
| 225 | |
| 226 | // Flush any produced block |
| 227 | flushBlocks(); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | |
| 232 | //////////////////////////////////////////////////////////// |
no outgoing calls
no test coverage detected