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

Author Topic: Soundstream understanding  (Read 4280 times)

0 Members and 1 Guest are viewing this topic.

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Soundstream understanding
« on: May 11, 2018, 11:36:11 pm »
Hello,
I want to implement a custom Soundstream. For that, I also have to override onGetData, but I don't really understand how I can feed it data. Why is data.samples a pointer to a int16? That doesn't make sense to me, I expected that I pass an array or something like that. Also, is it necessary to use a vector like in the example? My theory is that you are giving a pointer to a start int16, and then SFML is stepping through the vector by incrementing the sample pointer address by the size of int16 to get to the next sample. Is that right?

Another question, I deliver the data through a vector <boost::variant <int, int16, maybe something else...>>. Is there a way to give soundstream the data through that? Of course, the actual data in each variant passed to the soundstream will ALWAYS be an int16, but I need that variant for flexibility reasons (the vectors with the data is passed through a pipeline before it gets to the soundstream).
Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Soundstream understanding
« Reply #1 on: May 12, 2018, 09:22:51 pm »
Quote
Why is data.samples a pointer to a int16? That doesn't make sense to me, I expected that I pass an array or something like that
It is a pointer to an array of int16, not to just a single int16. That's why there's another "size" member in data.

Quote
I deliver the data through a vector <boost::variant <int, int16, maybe something else...>>. Is there a way to give soundstream the data through that?
No.
Laurent Gomila - SFML developer

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: Soundstream understanding
« Reply #2 on: May 12, 2018, 10:18:03 pm »
So I have to cast the variants to int16 (maybe just with assigning it to an int16)?
Quote
It is a pointer to an array of int16, not to just a single int16. That's why there's another "size" member in data.
But in the example in the tutorials data.samples is just assigned to a pointer of the (currentSampleIndex)'th
sample. So it seems to be just a pointer to a single int16? How can it be a pointer to an array if it's a pointer to a single element? I thought that sfml just uses the address of that pointer and then steps through the vector by doing pointer address arithmetics?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Soundstream understanding
« Reply #3 on: May 13, 2018, 08:46:51 am »
Quote
I thought that sfml just uses the address of that pointer and then steps through the vector by doing pointer address arithmetics?
Yes. And that's called an array. In C++, an array (we're not speaking about the various STL wrappers) is a pointer to its first element. I don't know what other type than int16* you would expect in "data" for an array.
Laurent Gomila - SFML developer

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: Soundstream understanding
« Reply #4 on: May 13, 2018, 11:16:18 am »
Ah ok, yes, I only worked with stl containers before because they are pretty save.