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

Author Topic: New audio file 2 time longer than original.  (Read 5828 times)

0 Members and 1 Guest are viewing this topic.


  • SFML Team
  • Hero Member
  • *****
  • Posts: 10777
    • View Profile
    • development blog
    • Email
Re: New audio file 2 time longer than original.
« Reply #15 on: March 04, 2016, 12:30:45 am »
I tried it myself and have not run into the issue you're describing. Neither with the audio files provided in the SFML examples, nor with other stereo and mono files, nor with different output formats OGG, WAV, FLAC.

This is the code I used:

#include <SFML/Audio.hpp>

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

    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());

I have however run into a memory allocation issue with the OGG writer, but this is unrelated to your problems.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
Dev Blog: https://duerrenberger.dev/blog/


  • Hero Member
  • *****
  • Posts: 3339
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: New audio file 2 time longer than original.
« Reply #16 on: March 07, 2016, 01:41:57 pm »
If it's present when just directly resaving the file too, as you posted, it narrows down the culprit. e.g. it's not a mistake with the manual management of memory or anything.

I am passing a c string because of the purposes of my program.
The reason I mention it is because you pass the string with the method c_str() so that it only sends the c string. However, the function you send it to takes std::strings so needs to construct one from the c string that you send it. If you sent the string directly, this 'extra work' would be unnecessary.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
 *Hapaxia Links*