Jump to content

Multidimensional arrays


stryd_one

Recommended Posts

stryd_one:

My most preferenced solution would be to use nested structs, since it naturally represents our dataset.  linked lists are unnecessary since the number of elements is predefined, and I think you will want random accesses, since if a user turns on track 4, step 8, you don't want to iterate over data members to find the entry.. probably create bad timing issues.

So you'd want something like:

typedef struct _step {

  unsigned char Note;

  unsigned char Velocity;

  unsigned char Length;

} step_t;

typedef struct _track {

  step_t Step[16];

  unsigned char Divider; // there is a reason we put these three lonely members behind the Steps

  unsigned char Direction;

  unsigned char Mute;

} track_t;

typedef struct _pattern {

  track_t Track[32];

} pattern_t;

// to allocate a pattern on the stack:

pattern_t pattern;

// to access a specific value:

pattern.Track[2].Step[15].Velocity = 0x7F;

total size of pattern = 32 * ((16*3) +3) = 1632 bytes.  I don't know if SDCC can handle allocating this much memory when it's in a nested structure usage, but I'm guessing the 256 byte issue still applies, which means, it won't.  I think in order for you to access this much data, you will have to:

- use a custom linker script in order to allocate a named block of memory >256 bytes.

- you will most likely then have to manually calculate the offset into the memory region.

To someone who knows: does SDCC support pointers?  Not dynamic memory, just the allocation of pointers to say, a struct.  If so then stryd could just use the linker script entry to allocate the memory, and then allocate on the stack a pointer to a pattern, and then map the pointer to a pattern onto the memory block.

Link to comment
Share on other sites

Thanks mate, I'll take that into account.

(...)

I'm still stuck on the right way to section this memory off if not using arrays though :\

But don't give too much weight on my unexperienced opinion here, I will post some more questions about this in the Bankstick Storage Thread...

Again, guys I have to thank you for the advice. I understand if this is taking too much of your time and I totally understand if you have to tell me to go away and do some more reading

As I am actually thinking about the same issue (but different data, of course), I feel quite lucky having the possibility to chat with some mates. My girlfriend is not really enjoying that kind of talks ;D

Cheers, Michael

Link to comment
Share on other sites

Hey, you might call yourself inexperienced, but look at me! ;)

As I am actually thinking about the same issue (but different data, of course), I feel quite lucky having the possibility to chat with some mates. My girlfriend is not really enjoying that kind of talks ;D

LMAO  ;D

Link to comment
Share on other sites

My most preferenced solution would be to use nested structs

I was starting to think that might be the way to go too, but I wasn't sure if you could nest arrays of structs like that. It sure looks like what I wanted though!

total size of pattern = 32 * ((16*3) +3) = 1632 bytes.  I don't know if SDCC can handle allocating this much memory when it's in a nested structure usage, but I'm guessing the 256 byte issue still applies, which means, it won't.  I think in order for you to access this much data, you will have to:

- use a custom linker script in order to allocate a named block of memory >256 bytes.

- you will most likely then have to manually calculate the offset into the memory region.

To someone who knows: does SDCC support pointers?  Not dynamic memory, just the allocation of pointers to say, a struct.  If so then stryd could just use the linker script entry to allocate the memory, and then allocate on the stack a pointer to a pattern, and then map the pointer to a pattern onto the memory block.

The scary thing is that that's a cutdown version and It'll probably be bigger than that... I've had a look at the other variables that I'll need to use and I think that I'll have to cut it down to 24 tracks in order to make it fit in the available RAM even on the 4620 :( That is, until I get the SRAM interface working, but that's a little while off (read: way above my skill level) at the moment! I was thinking about including some tracks of shorter lengths (3,4,5,6,8 steps) too, but now I'm getting sidetracked... (Hey, while I'm sidetracked, the vX is getting partial polyphony! woo!)

When I get a break (yeh, right) I want to test the arrays with SDCC, to find out if the limitation is to 8-bit array sizes (as in, no arrays over 256k) or 8-bit addressing to the arrays. I reeeeaaaallly hope it's the latter!

Link to comment
Share on other sites

  • 4 weeks later...

The results are in: the arrays can be addressed with >8bits (so array[1024] is still OK) but any variable including the array's total size, is limited to 256bits. This limitation can be overcome by using a customized linker script. I will document this on the wiki shortly.

Link to comment
Share on other sites

A while back you gave me assistance (ACommander also) on changing controller values for my Native Instruments B4 controller. I don't know if that is what you are hitting at, but look again at the post- do a search on 'boolean', it will be the first link.

Weel, mission accomplished. I use a 3 pole switch to toggle between a variety of functions for each pot and switch

eg- position 1- knob 1 is upper manual 16' pipe on channel 1

position 2- knob 1 is lower manual 16' pipe on cahannel 2 etc.

Would the code for this help you. I only completed it two days ago, and am too busy playing with it to post the WIKI. So if you want I'll post the code here if you think it would help!

MP

Link to comment
Share on other sites

Glad to hear it worked :)

I don't think this is the right kind of thing for me, because the seq handles things a bit differently to the controller, but if you PM it to me, I'll wiki it up for the community :) (with credit to you of course!)

Link to comment
Share on other sites

  • 3 months later...

th0mas

You posted the code below and I'm trying to follow the meaning of this thread. This looks interesting!

Can the SDCC compiler handle this for the PIC? Is this a better way to handle things than a simple multi-dimensional array?

Regards

So you'd want something like:

typedef struct _step {

  unsigned char Note;

  unsigned char Velocity;

  unsigned char Length;

} step_t;

typedef struct _track {

  step_t Step[16];

  unsigned char Divider; // there is a reason we put these three lonely members behind the Steps

  unsigned char Direction;

  unsigned char Mute;

} track_t;

typedef struct _pattern {

  track_t Track[32];

} pattern_t;

// to allocate a pattern on the stack:

pattern_t pattern;

// to access a specific value:

pattern.Track[2].Step[15].Velocity = 0x7F;

Link to comment
Share on other sites

"....Multidimensional arrays just won't work at all unfortunately"

You mean, they don't work for arrays larger than 256? Or at all?

But for smaller ones, they are fine.... especially for const unsigned char myarray[32][4] or some such.

..

I see. I re-read this entire thread. Stryd needs data storage for real-time, in memory stuff. I worried that my flash stored constant multi-dimension arrays are a problem. I see they are not.

Link to comment
Share on other sites

  • 1 year later...

Due to a restriction to SDCC, bitfields are limited to 8 bits!  :-\

For the record:

Good news, I have just tested a 15-bit bitfield (15, not 16, to test correct alignment of odd sizes across bytes), and all accesses are correct :)

This was with a post 2.7.0 SDCC release.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...