View Single Post
Old 05-21-2020, 04:17 PM   #4
nitsuj
Human being with feelings
 
nitsuj's Avatar
 
Join Date: Nov 2017
Posts: 292
Default

Quote:
Originally Posted by danmc View Post
This is indeed helpful. To make sure I have it, is it true that in your example buffer1 is 0 and buffer2 is 4096 (i.e. address of the start of the buffers)? What I have a scalar variable as well, for example gain below. How do I know that gain would not get stored somewhere in the memory used by those two buffers? Or do variables live in a totally different space than memory accessed with the [] operator? Maybe that is the key bit of understanding I was missing when I first read over the docs.

Code:
MEMORY.init_memory();

buffer1 = MEMORY.alloc_memory(4096);
buffer2 = MEMORY.alloc_memory(1024);

buffer1[0] = 1970;
buffer1[1] = 1971;

buffer2[0] = 1993;
// and so on...

// ADDED
gain = 37.2
Yes, buffer1 is 0, buffer2 is 4096.

Variables are a totally separate/different thing and you don't have to worry about those. The memory buffer is accessed using the [] operator.

Buffer usage is a very common thing in DSP programming and this was the main intention for providing the memory space. Essentially a big array of doubles that you can carve up how you see fit.
nitsuj is offline   Reply With Quote