Home › Forums › General › Programming › utils.packDsiData() not working well
Tagged: DSI pack unpack
- This topic has 0 replies, 1 voice, and was last updated 7 years, 8 months ago by goodweather.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
August 16, 2016 at 9:14 pm #69843
Hi,
when finalizing with many tests my Pro2 panel, I discovered that the utils.packDsiData() function was not working well.
I suspect that it is not made to handle data which is not a multiple of 7 but I’m not sure if this is the reason.
Anyway, to test the issue, just take a packed file, unpack it then repack it and compare the result… The last bytes are not correct…The other function utils.unpackDsiData() works well on the other side.
Therefore, while getting a corrected PACK function, I have built one that is working.
Feel free to use 🙂-- -- A function to pack DSI data according to description at end of Pro 2 and P12 manuals -- Written because internal utils.packDsiData() Ctrlr function doesn't work properly. -- -- DSI Packed Data Format -- Data is packed in 8 byte “packets”, with the MS bit stripped from 7 parameter bytes, -- and packed into an eighth byte, which is sent at the start of the 8 byte packet. -- -- Example: -- -- Input Data Packed MIDI data -- 1 A7 A6 A5 A4 A3 A2 A1 A0 1 00 G7 F7 E7 D7 C7 B7 A7 -- 2 B7 B6 B5 B4 B3 B2 B1 B0 2 00 A6 A5 A4 A3 A2 A1 A0 -- 3 C7 C6 C5 C4 C3 C2 C1 C0 3 00 B6 B5 B4 B3 B2 B1 B0 -- 4 D7 D6 D5 D4 D3 D2 D1 D0 4 00 C6 C5 C4 C3 C2 C1 C0 -- 5 E7 E6 E5 E4 E3 E2 E1 E0 5 00 D6 D5 D4 D3 D2 D1 D0 -- 6 F7 F6 F5 F4 F3 F2 F1 F0 6 00 E6 E5 E4 E3 E2 E1 E0 -- 7 G7 G6 G5 G4 G3 G2 G1 G0 7 00 F6 F5 F4 F3 F2 F1 F0 -- 8 00 G6 G5 G4 G3 G2 G1 G0 -- -- This explains why it takes 1171 MIDI bytes to transmit 1024 Program data bytes. -- PackDsiData = function(mbUnpackedDsiData) console("*** PackDsiData function ***") -- Take a copy of mbUnpackedDsiData to avoid modifying it mbUnpacked = MemoryBlock(mbUnpackedDsiData) -- Check mbUnpacked size is a multiple of 7 iSize = mbUnpacked:getSize() console("..Unpacked size="..tostring(iSize)) iRemains = math.mod(iSize, 7) mbInit = MemoryBlock ({0x00}) if iRemains ~= 0 then console("..Size to append="..tostring(7-iRemains)) -- mbTemp=MemoryBlock(7-iRemains, true) Doesn't work! mbTemp = MemoryBlock() for i=1,7-iRemains do mbTemp:append (mbInit) end mbUnpacked:append (mbTemp) console("..Temporary unpacked data: "..mbUnpacked:toHexString(1)) console("..Temporary unpacked size="..tostring(mbUnpacked:getSize())) end mbPacked = MemoryBlock() if iRemains == 0 then console("..Calculated packed size="..8*math.floor(iSize/7)) for i=1,8*math.floor(iSize/7) do mbPacked:append (mbInit) end else console("..Calculated packed size="..8*math.floor(iSize/7)+iRemains+1) for i=1,8*math.floor(iSize/7)+iRemains+1 do mbPacked:append (mbInit) end end k = 0 for i=0,iSize-1,7 do -- Build and write the first packed byte from the bit7 of the 7 unpacked bytes FirstByte = 0 for j=0,6 do FirstByte = FirstByte + bit.rshift(mbUnpacked:getByte(i+j), 7) * 2^j -- console("..i="..i.." j="..j.." Bit="..tostring(bit.rshift(mbUnpacked:getByte(i+j), 7))) end mbPacked:setByte(k, FirstByte) -- Strip and write the 7 unpacked bytes for j=0,6 do k = k + 1 mbPacked:setByte(k, bit.band(mbUnpacked:getByte(i+j), 0x7F)) end k = k + 1 end console("..Returned packed size="..tostring(mbPacked:getSize())) console("..Returned packed data: "..mbPacked:toHexString(1)) return mbPacked end
-
AuthorPosts
Viewing 1 post (of 1 total)
- The forum ‘Programming’ is closed to new topics and replies.
There is currently 0 users and 96 guests online
No users are currently activeForum Statistics
Threads: 2,495, Posts: 17,374, Members: 77,605Most users ever online was 12 on January 22, 2019 3:47 pm