Home › Forums › General › Programming › converting bytes
- This topic has 4 replies, 2 voices, and was last updated 11 years, 7 months ago by msepsis.
-
AuthorPosts
-
September 26, 2012 at 6:04 pm #719
So building out this wavetable editor for the waldorf microwave II/XT has got me busy. I’m stumped on a few things with converting bytes.
First, here’s the manual for the synth that I refer to here:
http://carbon111.com/mwxt_manual.pdfThe XT sends it’s Wave Control Table Dump in 265 bytes. bytes 7-262 contain the wave location for the 64 possible waves within the control table in nibblized format..
see p 114-115 under 3.5 WCTDATAIn order to request the waves from the synth that are contained within the wavetable I need to send to the synth the wave location, but not in the same format as they are received within the WCTDump. The wave location needs to be converted from the WCTDump where the location is given in FOUR bytes to the location in TWO bytes, not nibblized.
So for instance if a WCTDump contains reference to wave#1249 on the synth it is formatted like:
0x00, 0x04, 0x0E, 0x01to call wave#1249 from the synth I need to convert the location from the WCTDump into 2 bytes, like:
0x09, 0x61How do I convert in Lua the 0x00, 0x04, 0x0E, 0x01 to 0x09, 0x61?
bigInteger was suggested but honestly I’m not sure [b:13inarp1]how [/b:13inarp1]to use it to get there from here… any examples of its use in context would be incredibly helpful. The API docs are great but I sometimes have a hard time extracting the exact syntax to use from them as there are no real-world examples.many many thanks, this has got me really stumped.
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
September 26, 2012 at 8:15 pm #4800Can you show the same calculation in Bits, or extract that part of the manual here that says how this conversion works ?
September 27, 2012 at 1:25 am #4801"atom":s1tia3s9 wrote:Can you show the same calculation in Bits, or extract that part of the manual here that says how this conversion works ?[/quote:s1tia3s9]well there’s no part in the manual that shows how this works besides what I quoted, but I’ll go in detail here based on what I know here… You asked ” title=”Smile” />
See see p 114-115 in the manual linked above, under 3.5 WCTDATA for the wave control table (wavetable) data format.
See page 108 for the WAVR (Wave Request) data format.Here’s what all that means:
A WCTD (Wavetable Dump) contains 265 bytes, 255 of which are used to designate which wave is assigned at each position of the wavetable. There are 64 positions, four "nibblized" bytes used per wave position.
In the set of four bytes that designate a specific wave position within the wavetable:
First byte is most significant nibble, upper half
Second byte is the least significant nibble, upper half
Third byte is the most significant nibble, lower half
Fourth byte is the least significant nibble, lower halfI’ve deducted each of the four bytes used to address a single wave on the synth are weighted as follows:
first byte is the 512’s (there are no values other than 00 given for the first byte, so this byte is never used fyi)
second byte is the 256’s
third byte is the 16’s
first byte is the 1’sFor positions within the wavetable that are not assigned a wave, each of the four bytes for it’s position is 0x0F
Then in order to actually call up the wave from the synth, I need to format the wave address in two bytes within waldorf’s WAVR (wave request) message format, page 108.
There, the first byte is the 128’s, second byte is the 1’s..so (0x00*512)+(0x04*256)+(0x0E*16)+(0x01*1) = 0x09, 0x61
With me so far?
I basically have gone so far to actually "convert" the wave locations from the wavetable dump into decimal values for the actual wave’s location just by assigning each byte a variable and then doing the math expressed above on the right on the variables.. It’s many lines of code but from it I’m able to get a "human readable" decimal value (0000-1249) from the four bytes used within the WCTD to call each of the 64 waves within a wavetable. I suppose all I really need to do now is convert these decimal integers to two hex bytes.. Unless there’s a more simple way to use, say BigInteger to just convert the 4 nibblized hex bytes from the Wavetable Dump to the 2 bytes of hex used to request a wave.
so for instance if I want to load wave 1249 I’d need to send 0x09 0x61 in two separate bytes.
enough info to go from to help answer my question? hope so ” title=”Smile” />
Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
September 27, 2012 at 5:17 pm #4802I think what you are saying should be better visualized in bits not bytes (never liked the whole HEX stuff). Say we want 1249, look at the code below
[code:36rjx08m]
bi = CtrlrLuaBigInteger(1249)
console ("Our 14 bits are: "..bi:toString(2,)
lsb = bi:getBitRangeAsInt (0,7)
msb = bi:getBitRangeAsInt (7,7)
console (string.format ("MSB=%.2x(%d) LSB=%.2x(%d)", msb, msb, lsb, lsb))
[/code:36rjx08m]
this will split the number 1249 into 2 7bit values (nothing in MIDI is ever 8bits it’s always 7). And these are the two values you need to send (assuming i understood all what you wrote)September 27, 2012 at 5:38 pm #4803You nailed it.
This works perfectly and now my work can finally continue now that I understand how BigInteger works. HUGE thanks to you for this, atom.Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.