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

Author Topic: sf::SoundBuffer getDuration() returns incorrect value  (Read 4939 times)

0 Members and 1 Guest are viewing this topic.

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
sf::SoundBuffer getDuration() returns incorrect value
« on: October 11, 2013, 08:17:22 am »
Hello. I'm loading a .ogg music that has 3 minutes and the getDuration() is returning a incorrect value for the duration.

sf::SoundBuffer sb;
sb.loadFromFile("file2.ogg");

std::cout << sb.getDuration().asMilliseconds() << '\n';
 

this is returning something like 23xxxms, ~23s.

This happens with other files too.

I made this code to get the percentage of played sound:

sf::Sound s(sb);
s.play();

double time = 100.0*s.getPlayingOffset().asMilliseconds()/(double)sb.getDuration().asMilliseconds();
 

And time get bigger than 100 after 23s :). So, appears that the sf::Sound getPlayingOffset() works great but something wrongs happens with the sf::SoundBuffer getDuration()

Music file: https://docs.google.com/file/d/0B87ZIbsLOhJ3NVA2OHp6cHFPQm8/edit?usp=sharing

**This is for a audio software. I know when use sf::Music..

Thanks.
Grégory
« Last Edit: October 11, 2013, 08:32:59 am by Gregory »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #1 on: October 11, 2013, 08:26:08 am »
Can you upload your music so that we can test it?
Laurent Gomila - SFML developer

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #2 on: October 11, 2013, 08:32:31 am »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #3 on: October 11, 2013, 09:00:46 am »
I can replicate this result with that file.

This is the exact code I tested with (Win32 console app in VS 2010):
#include "StdAfx.h"
#include <iostream>
#include <SFML/Audio.hpp>

int main(){
        sf::SoundBuffer sb;
        sb.loadFromFile("file2.ogg");

        std::cout << sb.getDuration().asMilliseconds() << '\n';

        sf::Sound s(sb);
        s.play();

        while(s.getStatus() == sf::Sound::Playing) {
                sf::sleep(sf::seconds(10));
                double time = 100.0*s.getPlayingOffset().asMilliseconds()/(double)sb.getDuration().asMilliseconds();
                std::cout << time << " ";
        }
 
        std::cout << std::endl << "Done";
        char c; std::cin >> c; //quick way to ensure the console stays open for a while
}

This is the console output I got:


So we nearly hit 2000% of a 23s file (according to these numbers) which implies a length of 7 and 2/3 minutes, which seems pretty close to the 7:42 that Media Player Classic gives me.  So at least MPC gets the right length, which I guess means the file isn't corrupted?

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #4 on: October 11, 2013, 09:15:48 am »
Bang!


Quote
So at least MPC gets the right length, which I guess means the file isn't corrupted?

Yeap. It isn't corrupted. I exported it using Reaper. Aprofessional audio production soft.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #5 on: October 11, 2013, 07:20:50 pm »
That was a stupid bug. It's now fixed.

Thanks for your feedback :)
Laurent Gomila - SFML developer

Gregory

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #6 on: October 11, 2013, 08:58:03 pm »
Thanks! The bug fix will come on the SFML 2.2?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: sf::SoundBuffer getDuration() returns incorrect value
« Reply #7 on: October 11, 2013, 09:00:25 pm »
You can see the fix committed here: https://github.com/SFML/SFML/commit/2ff58edd9af5530afa0a58657c0908855c96ce21 so yes it'll be in all future releases.

And if you want, you can pull the latest sources from github right now and compile them yourself to get that fix before 2.2 comes out.

 

anything