diff options
Diffstat (limited to 'src/SFML/Audio/SoundFileWriterOgg.cpp')
-rw-r--r-- | src/SFML/Audio/SoundFileWriterOgg.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/SFML/Audio/SoundFileWriterOgg.cpp b/src/SFML/Audio/SoundFileWriterOgg.cpp index 0091f84..8962a10 100644 --- a/src/SFML/Audio/SoundFileWriterOgg.cpp +++ b/src/SFML/Audio/SoundFileWriterOgg.cpp @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// // // SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org) // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. @@ -130,21 +130,31 @@ bool SoundFileWriterOgg::open(const std::string& filename, unsigned int sampleRa //////////////////////////////////////////////////////////// void SoundFileWriterOgg::write(const Int16* samples, Uint64 count) { - // Prepare a buffer to hold our samples + // Vorbis has issues with buffers that are too large, so we ask for 64K + static const int bufferSize = 65536; + + // A frame contains a sample from each channel int frameCount = static_cast<int>(count / m_channelCount); - float** buffer = vorbis_analysis_buffer(&m_state, frameCount); - assert(buffer); - // Write the samples to the buffer, converted to float - for (int i = 0; i < frameCount; ++i) - for (unsigned int j = 0; j < m_channelCount; ++j) - buffer[j][i] = *samples++ / 32767.0f; + while (frameCount > 0) + { + // Prepare a buffer to hold our samples + float** buffer = vorbis_analysis_buffer(&m_state, bufferSize); + assert(buffer); + + // Write the samples to the buffer, converted to float + for (int i = 0; i < std::min(frameCount, bufferSize); ++i) + for (unsigned int j = 0; j < m_channelCount; ++j) + buffer[j][i] = *samples++ / 32767.0f; - // Tell the library how many samples we've written - vorbis_analysis_wrote(&m_state, frameCount); + // Tell the library how many samples we've written + vorbis_analysis_wrote(&m_state, std::min(frameCount, bufferSize)); + + frameCount -= bufferSize; - // Flush any produced block - flushBlocks(); + // Flush any produced block + flushBlocks(); + } } |