-
Hello Ctrlr's, Has someone build a funktion for that allready? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I haven't looked deeply at it because it's a head wreck all this packed bit stuff, but I think it's the same logic as with Korg and how they do it. But I have two functions that can convert such data - you may have to change things in these functions. They return memory blocks of 8 or 7 bits depending which way you're going. function convert728(m) -- take a set of 7 bytes - extract the msbit and save to byte 0 of 8 bytes assert(m:getSize() == 7) local b, t = {1, 2, 4, 8, 16, 32, 64}, {} local msb = {} local lsb = {} local mlsb = MemoryBlock() for i = 0, m:getSize() - 1 do -- loop each byte local mask = bit.rshift(bit.band(m:getByte(i), 128), 7) msb[i + 1] = mask * b[i + 1] -- add each msBit to table table.insert(lsb, bit.band(m:getByte(i), 127)) -- record the masked lsb values end local sumMsb = 0 for i, v in ipairs(msb) do -- add each table value up for the MSB sumMsb = sumMsb + v end local result = MemoryBlock(sf("%.2x", bit.band(sumMsb, 127))) mlsb:createFromTable(lsb) -- now add the lsb values result:append(mlsb) -- append the lsb values to the end of the MSB return result end function convert827(m) -- take a set of 8 bytes (first byte contains) msbit data of each subsequent byte local t = {} assert(m:getSize() == 8, "size=" .. m:getSize()) local b = {1, 2, 4, 8, 16, 32, 64} local msb = m:getByte(0) -- for i = 1, m:getSize() - 1 do -- start at the second byte local mask = b[i] local band = bit.rshift(bit.band(msb, mask), i - 1) local addmsb = m:getByte(i) + (band * 128) table.insert(t, addmsb) end local result = MemoryBlock() result:createFromTable(t) assert(result:getSize() == 7) return result end |
Beta Was this translation helpful? Give feedback.
-
To convert an incoming data dump, find where the data starts after the sysex header (with Korg it's byte 6) less the EOX local sizeOfLoop = m:getSize() - 1 - 6 -- m = midi:getData() from Dump local accrue = MemoryBlock() -- initialise holder of converted 8 bit to 7 bit for i = 6, sizeOfLoop, 8 do -- 6 is offset from header get the 8 bytes of data (1st byte contains MSB data) local set = MemoryBlock(m:getRange(i, 8)) -- get each block of 8 bytes offset by 8 local res = convert827(set) -- convert down to 7 byte data accrue:append(res) -- append each 7 byte string end You now have 7 bytes of data with values above 127 or containing negative values depending - Assign the data in |
Beta Was this translation helpful? Give feedback.
-
How did you get on @Tonfisch ? Were these algorithms useful? 🥣 |
Beta Was this translation helpful? Give feedback.
-
Hello Dnaldoog, Thank you very much! |
Beta Was this translation helpful? Give feedback.
I haven't looked deeply at it because it's a head wreck all this packed bit stuff, but I think it's the same logic as with Korg and how they do it.
But I have two functions that can convert such data - you may have to change things in these functions. They return memory blocks of 8 or 7 bits depending which way you're going.