SFML community forums

Help => Audio => Topic started by: sfUser on January 31, 2016, 05:08:30 pm

Title: Play parts of many soundBuffers as one audio
Post by: sfUser on January 31, 2016, 05:08:30 pm
Hi there,

I would like to have a sound class that allows me to specify a certain number of soundBuffers and a specific duration on that sound buffer.

ex:

class Audio2 {
 // ((start time / stop time) /  buffer)
  std::vector<std::pair<std::pair<sf::Time, sf::time>, const sf::soundBuffer*>> buffers;
}

where the length of the audio would be the sum of the vector's time members  (difference between start and stop) and where soundbuffers could be repeated.

This would allow me to load 1/n sound buffers of dialogs and construct sentences using parts of those buffers.

So, If I had a buffer that played the sound of "hello" and another that played a sentence with the word "and" in the middle and a third that played "welcome", I could reproduce the sentence "Hello, and welcome" by adding 3 elements to the buffers with the soundBuffers of the tracks and a start and stop position in each buffer to play the part of the sound that corresponds to each word.

What would be the best approach I should take to implement this?
From what I saw, my best bet would probably be to implement this in SFML, to take advantage of private data that could facilitate this.
Title: Re: Play parts of many soundBuffers as one audio
Post by: Hapax on February 01, 2016, 12:59:20 am
It would depend on how quickly you need these results.
It's possible to create a new sound buffer that is built from copying and appending the parts of the other buffers.