Welcome to %s forums

BrainModular Users Forum

Login Register

store array module

Create your own modules in C++
Post Reply
User avatar
oli_lab
Member
Posts: 1266
Location: Brittany, France
Contact:

Unread post by oli_lab » 29 Jun 2017, 17:07

Hi !
so I build a store array module !

I did a

TPrecision* m_buffer;
and
int bufferSize = MAX_ARRAY_SIZE * SLOTNUMBER;
in .h

that init like this in .cpp:

storeArray::storeArray()
{
//Ensure that initial memo values at buffer are 0.0f
m_buffer = new float[bufferSize];
for (int i = 0; i<bufferSize; i++)
{
m_buffer = 0.0f;
}

so I have a buffer in which all the memory slots will be saved
for example, if I set 128 slots of 1024 bits there will be a fixed amount of memory that will be taken for this module.

- is it a problem ?

- is there another way to have the size been chosen from the size of the incoming array at input ?

thanx
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 30 Jun 2017, 15:14

im not that an expert and might be wrong, but i think performance wise if you have ram it's better to make a static allocated size at fist, possible in the .h like
float mybuffer[MAX_SIZE];

or you can use new in cpp but be careful to delete the array prior a new one at some point if multiple calls or ram use will increase
delete[] mybuffer; mybuffer = nullptr;

if want dynamic size i think it's better to use vector.
vector has a reserve size where you would put max size, and a resize function to dynamically alter its size without needing to recreate a new one.
vector.reserve(size); ie at init and vector.resize(newsize) in the code, ie getting length of your input buffer first
#include <vector>

std::vector<float> mybuffer;
mybuffer.reserve(MAX_SIZE);
mybuffer.resize(NEW_SIZE);

you can resize even without a reserve size set first, then it will find some freespace in ram and allocate, but internally the resizing will be more efficient if you had reserved first,
tho of course i assume the max_size is locked space in ram then.

no problem looping and setting to 0 each id, but if setting to 0 the whole array man can use memset:
memset(mybuffer, 0 , sizeof(float)*MAX_SIZE); or more simply memset(mybuffer, 0 , sizeof(mybuffer));

or assuming you know the MAX_SIZE, the bytes size is MAX_SIZE * 4 (4 bytes per float) so for a 1024 array its 4094 bytes
memset(mybuffer,0,4096);

User avatar
oli_lab
Member
Posts: 1266
Location: Brittany, France
Contact:

Unread post by oli_lab » 30 Jun 2017, 16:03

Thanks I'l l try that tonight !

The next idea is to build wavetables from fft :
From an audio signal snap a fft every 10ms then resynthetise from the fft data on one period.
Put the waves each after the other in one big wavetable that can be scanned.
This way I can store a large amount of spectral data with fewer ram.
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 30 Jun 2017, 16:08

One function you might wanna look at too in your case is memcpy , wich allows a direct copy of a pointer content to another, allowing to skip looping.
for conveniance i pers would do a bi-dimentional vector or array of nb_slots, nb_floats_per_slot, then let you set/get a slot.
for ex

mybuffer[128][1024]; //128 slots, 1024 floats

TPrecision* Out_Ptr; //pointer to float adress

Out_Ptr = sdkGetEvtDataAddr(pArrayOut); // get mem adress of output pin array

memcpy(Out_Ptr, &(mybuffer[5][0]), slot_bytes_size); //copy to output array the content starting at start mem adress of slot 5, of slot size.

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 30 Jun 2017, 21:39

sry, we maybe cross-eited tghe post, adn't seen your second message completely, yeah sound nice idea!

User avatar
oli_lab
Member
Posts: 1266
Location: Brittany, France
Contact:

Unread post by oli_lab » 30 Jun 2017, 22:15

hi !
how would you declare mybuffer[128][1024]; //128 slots, 1024 floats

as 128 is for int and 1024 is for floats. ?
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 30 Jun 2017, 23:19

yes sorry should be for ex in .h

float mybuffer[128][1024]; // both are int representing X Y sizes for a float contening array. where here for ex 128 is your nb of 'slots' and 1024 nb of floats want in each slot.

User avatar
oli_lab
Member
Posts: 1266
Location: Brittany, France
Contact:

Unread post by oli_lab » 30 Jun 2017, 23:38

got it !
I did the tricks on your first post.
put 8 array outputs so I can scan the memory slots differently for each of my 8 loudspeakers.

File uploaded: http://www.sensomusic.com/forums/upload ... ray_V1.zip

tell me if your on OSX.
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 01 Jul 2017, 00:24

yeah ! tried the wksp, very nice patch gg :)

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests