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

Author Topic: Creating a dynamic array of vertexArrays  (Read 2586 times)

0 Members and 1 Guest are viewing this topic.

Anonymous

  • Guest
Creating a dynamic array of vertexArrays
« on: September 01, 2014, 12:12:00 pm »
Hi,

I am looking at drawing a spectrogram, currently I feed in a chunk of samples to my C library which uses FFTW to return a magnitude array for each chunk. I want to draw the output of each magnitude array over time, so in my library I have a linked list which stores the array for each chunk of audio. I then have a callback method from my C++ application. As time increases, there will be more and more arrays to draw to the screen for my spectrogram, and therefore I need to create new VertexArrays on each drawback. I am using the std::vector class to try and add new vertex arrays to a list, however I am having problems with this. Below is my current code:

Code: [Select]
void ClientCallback(uint8_t *array, int current_array, int total_arrays)
{
if (total_arrays > vertex_array.size())
{
sf::VertexArray vertex_point(sf::LinesStrip, SAMPLE_RATE/2);
vertex_array.push_back(vertex_point);
}
for (unsigned counter = 0; counter < 1024; counter++)
{
vertex_array[current_array][counter].position = sf::Vector2f((float)(array[counter]), counter);

}
}

This method is called by my library to draw the arrays for every chunk of the audio track so far. When total_arrays increases, ie we have moved onto drawing a new chunk then I try to create a new vertex array and add this to my std::vector<sf::VertexArray> vertex_array; object. My error I believe is in how I try to access the vertex arrays from my vector object. I want to be able to do: vertexPoints[counter].position = sf::Vector2f((float)(array[counter]), counter); and so I tried the code vertex_array[current_array][counter].position to try and modify this element but this isn't working.

Any help would be greatly appreciated in knowing how to implement an arraylist of sorts that I can continue to add vertexarrays to before modifying the values of the vertexarrays and then drawing to screen.

Many thanks,
Mark

Anonymous

  • Guest
Re: Creating a dynamic array of vertexArrays
« Reply #1 on: September 04, 2014, 11:14:56 am »
Bump, if anyone would be able to enlighten me on how I could create an array that stores VertexArray's and then using this to update the values in each VertexArray and drawing these to the screen that would be great. Thanks

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Creating a dynamic array of vertexArrays
« Reply #2 on: September 04, 2014, 02:59:20 pm »
You probably haven't gotten any replies because you have not given enough information. Just saying that something doesn't work will not get you any replies. You need to be specific about what exactly the problem is.

http://en.sfml-dev.org/forums/index.php?topic=5559.msg36367#msg36367
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Creating a dynamic array of vertexArrays
« Reply #3 on: September 08, 2014, 02:08:07 pm »
zsbzsb is right; there isn't really enough information to know what problem you're actually experiencing.
That said, a couple of things you may want to consider:
1) update the current_array when you push a new one so that you're accessing the newly created one, not the previously last one. In fact, instead of using vector[lastIndex] to access the last element in a vector, try vector.back()
2) I would presume that this "callback" would be a number of times each second so dynamically allocating a new vector seems like more work than is necessary. Wouldn't it make sense to pre-allocate the "maximum" amount (which would presumably be reached quickly).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything