converting bytes

Home Forums General Programming converting bytes

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #719
    msepsis
    Participant
      • Topics: 219
      • Replies: 732
      • Total: 951
      • ★★★

      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.pdf

      The 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 WCTDATA

      In 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, 0x01

      to call wave#1249 from the synth I need to convert the location from the WCTDump into 2 bytes, like:
      0x09, 0x61

      How 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

      #4800
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        Can you show the same calculation in Bits, or extract that part of the manual here that says how this conversion works ?

        #4801
        msepsis
        Participant
          • Topics: 219
          • Replies: 732
          • Total: 951
          • ★★★
          "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 <img decoding=” 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 half

          I’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’s

          For 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 <img decoding=” title=”Smile” />

          Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

          #4802
          atom
          Keymaster
            • Topics: 159
            • Replies: 2945
            • Total: 3104
            • ★★★★★

            I 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,8))
            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)

            #4803
            msepsis
            Participant
              • Topics: 219
              • Replies: 732
              • Total: 951
              • ★★★

              You 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

            Viewing 5 posts - 1 through 5 (of 5 total)
            • The forum ‘Programming’ is closed to new topics and replies.
            There is currently 0 users and 94 guests online
            No users are currently active
            Forum Statistics
            Threads: 2,495, Posts: 17,374, Members: 77,605
            Most users ever online was 12 on January 22, 2019 3:47 pm
            Ctrlr