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

Author Topic: how to cut the end of a sound?  (Read 3012 times)

0 Members and 1 Guest are viewing this topic.

Temophor

  • Newbie
  • *
  • Posts: 2
    • View Profile
how to cut the end of a sound?
« on: May 07, 2015, 11:07:20 pm »
hey guys!

I'm recording a sound, unfortunately it puts like 0.5 seconds of non-recorded silence at the end of the recording.
I want the recording to loop seamlessly.
I found this code which cuts the sound from the beginning:

sf::SoundBuffer withoutSilence;
const std::size_t cut = buffer.getSampleRate() * buffer.getChannelCount() * 0.5f;;
withoutSilence.loadFromSamples(buffer.getSamples() + cut, buffer.getSampleCount() - cut, buffer.getChannelCount(), buffer.getSampleRate());

I then feed the new buffer appropriately to create, play and loop the sound.
I don't quite understand the loadFromSamples function. It successfully cuts the sound, but from the beginning instead from the end.

Any ideas?
Thank you :)
Temophor

Temophor

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: how to cut the end of a sound?
« Reply #1 on: May 07, 2015, 11:12:38 pm »
Nevermind, I just solved it myself:

buffer.getSamples() + cut determines the starting position of the new buffer. So of course I just want buffer.getSamples() here to start from the beginning (and not cut the beginning.
buffer.getSampleCount() - cut is the number of remaining samples. If I didn't cut in the beginning by not adding cut to the starting point, it will cut the audio at the end, just like intented.

cheers,
Temophor

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: how to cut the end of a sound?
« Reply #2 on: May 07, 2015, 11:13:34 pm »
I don't quite understand the loadFromSamples function.
Then look at its documentation. It clearly describes what the first and second argument mean.

It successfully cuts the sound, but from the beginning instead from the end.
That's not surprising. You're adding an offset to the start of the samples array.

By the way, it would be easier to use a software like Audacity to perform such modifications ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything