Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / how to use memblock ?

Author
Message
dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th Feb 2011 19:41
trying to use memblock in darkbasic pro, trying to skip every fourth bytes of data. how can I implement in code?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Feb 2011 20:27
Quote: "trying to skip every fourth bytes of data"

Where's the data coming from, and what will you be doing with the data? Did you mean 'bytes', or 'byte' (I'm guessing you meant use the first three bytes and skip the fourth)?

dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th Feb 2011 20:34 Edited at: 19th Feb 2011 21:25
yes I meant skip the fourth byte. can you help?

I'm trying to read audio from the memblock.
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 19th Feb 2011 21:25


WRITE MEMBLOCK BYTE MemblockNo, offset(in bytes), ByteToWrite
offset is set to 0, which is the start of the memblock, then after each 3-bytes have been written, you increase the offset by 4. This will move the writing position forward by 4 bytes... Repeat until you have written the data you wanted to write...

dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th Feb 2011 21:35 Edited at: 19th Feb 2011 21:41
I already wrote to the memblock, I'm using get memblock ptr(1) and I'm trying to read the data, for every three bytes and skip the fourth.


ex.

245 <-
100 <-
32 <-
51 <- skip
128 <-
45 <-
80 <-
51 <- skip
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 19th Feb 2011 21:47 Edited at: 19th Feb 2011 21:50


You might have to change the order of the bData1-3, can't remember if the highest byte comes first or the lowest...

It would probably be easier to read the memblock using the regular memblock commands instead...

bData1 = memblock byte(1, offset)

dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 19th Feb 2011 22:12 Edited at: 19th Feb 2011 22:14
that is what I'm doing, using memblock byte(1,offset)
I tried using this.

if n > offset
inc offset,3
else
memblock byte(1,n)
inc n,1
endif
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 19th Feb 2011 22:20


Ofcourse you have to change the bData variable to fill in your own variables, and make sure you don't read beyond the size of the memblock... That goes for previous examples aswell...

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Feb 2011 23:06
Why not read a whole dword (or integer) and then mask off the byte you don't want? Wouldn't that be easier?



dman
21
Years of Service
User Offline
Joined: 21st Feb 2005
Location:
Posted: 20th Feb 2011 01:16
thanks for the help everyone I appreciate the help.
It was most helpful.
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 20th Feb 2011 02:23
Quote: "Why not read a whole dword (or integer) and then mask off the byte you don't want? Wouldn't that be easier?"

Not easier to read though...

BTW... Is there a speed benefit by reading a dword at a time instead of individual bytes?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Feb 2011 13:50
It's approx 20-25% fast on my machine.

Login to post a reply

Server time is: 2026-07-17 13:59:43
Your offset time is: 2026-07-17 13:59:43