///////////////////////////////////////////////////////
| 231 | |
| 232 | //////////////////////////////////////////////////////////// |
| 233 | void SoundFileWriterOgg::flushBlocks() |
| 234 | { |
| 235 | // Let the library divide uncompressed data into blocks, and process them |
| 236 | vorbis_block block; |
| 237 | vorbis_block_init(&m_state, &block); |
| 238 | while (vorbis_analysis_blockout(&m_state, &block) == 1) |
| 239 | { |
| 240 | // Let the automatic bitrate management do its job |
| 241 | vorbis_analysis(&block, nullptr); |
| 242 | vorbis_bitrate_addblock(&block); |
| 243 | |
| 244 | // Get new packets from the bitrate management engine |
| 245 | ogg_packet packet; |
| 246 | while (vorbis_bitrate_flushpacket(&m_state, &packet)) |
| 247 | { |
| 248 | // Write the packet to the ogg stream |
| 249 | ogg_stream_packetin(&m_ogg, &packet); |
| 250 | |
| 251 | // If the stream produced new pages, write them to the output file |
| 252 | ogg_page page; |
| 253 | while (ogg_stream_flush(&m_ogg, &page) > 0) |
| 254 | { |
| 255 | m_file.write(reinterpret_cast<const char*>(page.header), page.header_len); |
| 256 | m_file.write(reinterpret_cast<const char*>(page.body), page.body_len); |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | // Clear the allocated block |
| 262 | vorbis_block_clear(&block); |
| 263 | } |
| 264 | |
| 265 | |
| 266 | //////////////////////////////////////////////////////////// |