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

Author Topic: Attaching SoundBuffers  (Read 5131 times)

0 Members and 1 Guest are viewing this topic.

ClaudioVC

  • Newbie
  • *
  • Posts: 10
    • View Profile
Attaching SoundBuffers
« on: February 17, 2017, 06:33:15 am »
Hi all,
Well, like the title says,is there any way to attach 2 soundbuffer? like:

Quote
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Attaching SoundBuffers
« Reply #1 on: February 17, 2017, 06:36:51 am »
You can easily concatenate their data (audio samples) and create a new buffer from that.
Laurent Gomila - SFML developer

ClaudioVC

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Attaching SoundBuffers
« Reply #2 on: February 17, 2017, 07:06:21 am »
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 :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Attaching SoundBuffers
« Reply #3 on: February 17, 2017, 08:16:02 am »
Quote
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.
Laurent Gomila - SFML developer

ClaudioVC

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Attaching SoundBuffers
« Reply #4 on: February 17, 2017, 06:59:32 pm »
Quote
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:

Quote
>>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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Attaching SoundBuffers
« Reply #5 on: February 17, 2017, 07:26:34 pm »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ClaudioVC

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Attaching SoundBuffers
« Reply #6 on: February 17, 2017, 07:35:03 pm »
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
« Last Edit: February 17, 2017, 07:58:06 pm by ClaudioVC »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Attaching SoundBuffers
« Reply #7 on: February 17, 2017, 07:59:34 pm »
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.

 

anything