Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Crash in SoundFileWriterOgg::write  (Read 2899 times)

0 Members and 1 Guest are viewing this topic.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Crash in SoundFileWriterOgg::write
« on: March 04, 2016, 12:41:16 am »
If anyone is a bit bored and wants to investigate, I currently lack the time.

Windows 10
SFML master
Tested with: VS 2015, MinGW Builds GCC 5.3.0

Used code:
#include <SFML/Audio.hpp>
#include <iostream>

int main()
{
        sf::SoundBuffer buf;
        buf.loadFromFile("ff.ogg");

        std::vector<sf::Int16> samples(buf.getSampleCount());

        std::cout << "Memory allocated\n";

        for(std::size_t i = 0; i < buf.getSampleCount(); i++)
        {
                samples[i] = buf.getSamples()[i];
        }
        sf::SoundBuffer buff;

        buff.loadFromSamples(samples.data(), buf.getSampleCount(), buf.getChannelCount(), buf.getSampleRate());

        std::cout << "Loading new buffer.\n";
        buff.saveToFile("ff-test.ogg");
        std::cout << "Data written\n";
}
 

Call stack (from VS 2015):
        SupportVS.exe!_chkstk() Line 99
        SupportVS.exe!_vorbis_analysis_wrote()
        SupportVS.exe!sf::priv::SoundFileWriterOgg::write(const short * samples, unsigned __int64 count) Line 144
        SupportVS.exe!sf::OutputSoundFile::write(const short * samples, unsigned __int64 count) Line 76
        SupportVS.exe!sf::SoundBuffer::saveToFile(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & filename) Line 153
        SupportVS.exe!main() Line 22

Used sound file: ff.ogg [1.25 MiB]

Have fun debugging. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Crash in SoundFileWriterOgg::write
« Reply #1 on: March 05, 2016, 06:09:39 am »
////////////////////////////////////////////////////////////
void SoundFileWriterOgg::write(const Int16* samples, Uint64 count)
{
        // Vorbis has issues with buffers that are too large, so we ask for 64K
        const static int bufferSize = 65536;

        // A frame contains a sample from each channel
    int frameCount = static_cast<int>(count / m_channelCount);

        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, std::min(frameCount, bufferSize));
               
                frameCount -= bufferSize;

                // Flush any produced block
                flushBlocks();
        }
}
Make a PR... I'm preoccupied with... "stuff"...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Crash in SoundFileWriterOgg::write
« Reply #2 on: March 06, 2016, 01:25:21 pm »
Cool, thanks! :)

I've made a PR.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/