Menu

Embedding .XMs in to VB Project.

Help
2007-05-20
2013-04-24
  • Nobody/Anonymous

    How would you go about doing so?
    Having trouble finding info on it.

    Also could you give some code for playing it
    once its embedded?

    Thanks in advance.
    -Broly

     
    • Vladimir Kameñar

      Do you mean not including the XM as a resource, but embedding it directly into the source code? VB doesn't support initialized static byte arrays, as opposed to some other Basic compilers. So doing something like

      Dim my_xm_file() As Byte = [ &H45, &H78, &H74, &H65, &H6E, &H64, &H65, &H64, ... ]

      won't work.

      The only "initializable" static array supported in VB is String, so you can use the following trick:

      Convert your XM file to ascii hex format (using Eff or a hex editor). Make a String containing the hex values:

      Dim my_xm_file As Byte
      Dim my_xm_file_s As String
      my_xm_file_s = "457874656E646564" ' and so on...

      Then, make a dynamic byte array and convert the ascii-hex values from the static string to actual bytes:

      ReDim my_xm_file(Len(my_xm_file_s) \ 2 - 1)

      For i = 1 To Len(my_xm_file_s) Step 2
         my_xm_file(i \ 2) = Val("&H" & Mid(my_xm_file_s, i, 2))
      Next

      my_xm_file now holds the XM file in memory.

      Well, doing so wastes a lot of memory. BTW, static Strings ain't initialized statically at all! In general, I'd rather use resources instead.

      Playing it is rather straightforward:

      Dim pXM As Long
      Dim XM_len As Long

      pXM = VarPtr(my_xm_file(0))
      XM_len = Len(my_xm_file)

      uFMOD_PlaySong(pXM, XM_len, XM_MEMORY)

       
    • Nobody/Anonymous

      One other thing, what syntax should I dump it as?

      -Broly

       
    • Vladimir Kameñar

      > what syntax should I dump it as?
      Eff doesn't support VB string syntax. So, you can dump it, let's say, in C/C++ format:

      unsigned char xm[905] = {
           0x45,0x78,0x74,0x65,0x6E,0x64,0x65,0x64,0x20,0x4D,0x6F,0x64,0x75,0x6C,0x65,0x3A,
           0x20,0x73,0x6F,0x66,0x74,0x20,0x6D,0x61,0x6E,0x69,0x61,0x63,0x2D,0x6D,0x69,0x6E,
      // ...

      Then, perform a search&replace, removing all occurances of "," and "0x":

      unsigned char xm[905] = {
           457874656E646564204D6F64756C653A
           20736F6674206D616E6961632D6D696E
      // ...

      Now, let's concatenate 'em:

      my_xm_file_s = "457874656E646564204D6F64756C653A20736F6674206D616E6961632D6D696E" ' ...

      You'll have to split the XM dump in various blocks, since VB won't accept a string soooo long. Something like:

      my_xm_file_s = block1 + block2 + ... + blockN.

       
    • Nobody/Anonymous

      Ah alright thanks man finally got it.
      I'm sure it will help others too.

      -Broly

       
    • Nobody/Anonymous

      Hi im some what new to VB Coding, bu could you post the source thats in the complied
      example?

       
    • Vladimir Kameñar

      The complete source code of test.exe included in the official release is in VisualBasic6\WINMM. Have you experienced any problems compiling it?

       

Log in to post a comment.