SFML community forums
Help => Audio => Topic started by: ClaudioVC on February 17, 2017, 06:33:15 am
-
Hi all,
Well, like the title says,is there any way to attach 2 soundbuffer? like:
sf::SoundBuffer buffer1;
sf::SoundBuffer buffer2;
sf::SoundBuffer buffer3;
----then i record 2 times for buffer1 and buffer2 and now i want to attach them-----
buffer3 = buffer1 + buffer2;
or other way, is there any way to attach 2 sounds?
Thanks all.
-
You can easily concatenate their data (audio samples) and create a new buffer from that.
-
You can easily concatenate their data (audio samples) and create a new buffer from that.
So, just need to create a function to concatenate their arrays of audio? (getSamples)
or, need i to attach their getSamples, getSamplesCount, getSamplesRate and getChannelCount?
thanks for ur fast reply :)
-
So, just need to create a function to concatenate their arrays of audio? (getSamples)
Yes.
Sample rate and channel count obviously need to be the same.
-
So, just need to create a function to concatenate their arrays of audio? (getSamples)
Yes.
Sample rate and channel count obviously need to be the same.
I was trying to work with it but i dont know if im doing it right.
First, i rlly dont know how join to the array, for example:
>>I have this Buffer:
sf::SoundBuffer buffer1;
sf::SoundBuffer buffer2;
now i want to take the array from the first one. So i should use buffer1.getSamples(); the first thing that i think is that if this is an array i could get the samples of the array like: buffer1.getSamples()[number], i know it is wrong but i dont know how get the data of the array. if i print buffer1.getSamples() just get a number like "0x6668478" and the second buffer give me "0x66ed2f0". I rlly dont know how to concatenate those arrays because i dont know how work with it, i read the def of the function getSamples() but i really dont get it.
Thanks for all your help again
-
How to work with arrays is basic C++ knowledge and not really SFML specific, so you might want to read up on that topic.
I suggest to use a std::vector, for the rest ypu can also Google it (so I don't have to). And then pass vec.data() to loadFromSamples to the new buffer.
If this operation always occurs at load time, you might just want to merge them in an audio editing software beforehand.
-
How to work with arrays is basic C++ knowledge and not really SFML specific, so you might want to read up on that topic.
I suggest to use a std::vector, for the rest ypu can also Google it (so I don't have to). And then pass vec.data() to loadFromSamples to the new buffer.
If this operation always occurs at load time, you might just want to merge them in an audio editing software beforehand.
Yes, i know how to work with arrays in c++, that i was trying to say is that is not giving me an array.
btw, Thanks for the suggest .
EDIT: it finally works, im going to try to concatenate now, thanks to both of you
-
Well here's something a bit more to learn about arrays: "buffers" and "arrays" are often (not always) the same thing.
In this case, getSamples() is giving you a pointer to the buffer (hence the class name) containing the sound data. There are getSampleCount() datums in the buffer.
You're going to want to read about pointers to understand more in depth about what's going on here.