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

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

0 Members and 3 Guests are viewing this topic.

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
New audio file 2 time longer than original.
« on: February 28, 2016, 05:03:12 pm »
            

                cout << "Enter the name of the audio\n>";
                                cin >> path;

                                sf::SoundBuffer buffer;
                                buffer.loadFromFile(path.c_str());

                                sf::Int16 * samples = new sf::Int16[buffer.getSampleCount()];

                                int ind = 0, progress = 0, last = 0;
                                float running = 1.0f;
                                string bin_code = "";

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

                                buff.loadFromSamples(samples, buffer.getSampleCount(), buffer.getChannelCount(), buffer.getSampleRate());
                                buff.saveToFile("test.wav");

                                delete[] samples;

 

The file that is created is two times longer then original. Its not bigger (in size) but it has duration 2 times longer than original. Also, when i try to play it with SFML it doest play but when I try to play it with Windows media player it does play (when it exceeds the duration of the song the music is still "playing" but there's no sound).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: New audio file 2 time longer than original.
« Reply #1 on: February 28, 2016, 05:57:06 pm »
What version of SFML are you using?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: New audio file 2 time longer than original.
« Reply #2 on: February 28, 2016, 06:07:39 pm »
It believe it is latest version for Visual Studio.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: New audio file 2 time longer than original.
« Reply #3 on: February 28, 2016, 10:33:11 pm »
Is it possible that the original sound has more than 2 channels? I'm not sure that SFML is prepared to deal with more than 2.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: New audio file 2 time longer than original.
« Reply #4 on: February 28, 2016, 11:18:48 pm »
I checked if the sound has 2 channels and it does. When I play the original file everything works fine.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: New audio file 2 time longer than original.
« Reply #5 on: February 29, 2016, 01:38:35 am »
I tested your code (almost identical) on a short, stereo wave file and it worked fine for me (tested it with the latest release version - v2.3.2 - for Visual Studio).

Is your sound file long? By "duration 2 times longer", do you mean that it plays it lower-sounding (an octave), or does it repeat the sound twice or go silent for the extra duration?

Do you get this effect with all samples or just one?
Could you provide a sample that you have the problem with so others can test it (have you tried resaving it elsewhere first)?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: New audio file 2 time longer than original.
« Reply #6 on: February 29, 2016, 11:01:58 am »
My sound file is 5:07 mins long.

By 2 times longer I mean that when I play it, it plays normal for 5:07 mins and then from 5:08 to 10:14 is just pure silence.

I'm not really sure what do you mean by : "Do you get this effect with all samples or just one?"

Basically I want to get all the samples, change them a little bit and then make a new file.

My code is identical to the code that I posted. Those calculations that I am making in my program (changing the samples) are not included on purpose, for simplicity sake.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: New audio file 2 time longer than original.
« Reply #7 on: February 29, 2016, 03:07:44 pm »
What's your version of SFML? Could be related to this bug which was fixed in SFML 2.3.2.
Laurent Gomila - SFML developer

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: New audio file 2 time longer than original.
« Reply #8 on: February 29, 2016, 07:30:39 pm »
I was not sure before but now when you asked I downloaded latest version once again and the file is still not correct.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: New audio file 2 time longer than original.
« Reply #9 on: February 29, 2016, 08:09:58 pm »
Are you able to provide a sound that you are having trouble with? If not, can you test it with a sound that everyone has access to (e.g. a free sound on the internet)?
Have you tried resaving them using other software? Other formats?

I'm not really sure what do you mean by : "Do you get this effect with all samples or just one?"
Basically I want to get all the samples, change them a little bit and then make a new file.
The word sample can be confusing as it is used/abused for many purposes. I was asking if it happens with all sound sample (i.e. sound clip) that you have; I wasn't referring to individual sample values within the sound data.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: New audio file 2 time longer than original.
« Reply #10 on: March 01, 2016, 06:12:54 pm »
I used an online YT to wav converter to get a wav file.

I think that SFML still has a bug. I tried this two lines of code:

buffer.loadFromFile(path.c_str());
buffer.saveToFile("test.wav");
 

And test.wav still is still produced like before. (the duration is 2 times longer).
I guess I leave it like this. If someone knows what could be the issue please let me know.

EDIT: if someone has a link to download a free .wav file plase let me know. But I believe that the file is not the issue here.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: New audio file 2 time longer than original.
« Reply #11 on: March 01, 2016, 07:05:38 pm »
There is a wav file in the SFML SDK.
Laurent Gomila - SFML developer

jamesL

  • Full Member
  • ***
  • Posts: 124
    • View Profile
Re: New audio file 2 time longer than original.
« Reply #12 on: March 01, 2016, 07:46:08 pm »

EDIT: if someone has a link to download a free .wav file plase let me know. But I believe that the file is not the issue here.

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=free%20.wav%20files

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: New audio file 2 time longer than original.
« Reply #13 on: March 02, 2016, 01:36:12 am »
You should test it with sound files with a different number of channels: 1, 2 (maybe more if you want to be thorough).

Try resaving (load into the editor and then save it) your own file using software such as Audacity.

Is there a reason you're passing a c string to the loadFromFile() function? This isn't related to the problem; I was just wondering.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

treez

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: New audio file 2 time longer than original.
« Reply #14 on: March 03, 2016, 04:41:55 pm »
I downloaded Audacity and converted an mp3 file to wav. I tested it and the bug is still there.

I am passing a c string because of the purposes of my program.