don't click here

XM code questions

Discussion in 'Technical Discussion' started by Andlabs, Aug 23, 2010.

  1. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    Code (Text):
    1. &nbsp;&nbsp;&nbsp;&nbsp;for (I = 0; I < ninst; I++) {
    2. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int nsamps;
    3. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QStringList sn;
    4.  
    5. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (readlelong(f) != 0x107)
    6. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return QString("instrument header length for instrument %1 not 0x107 - probably nonstandard XM file").arg(I, 0, 16);
    7. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instrNames.append(readFLString(f, 22));
    8. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (readbyte(f) != 0)
    9. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return QString("instrument type for instrument %1 not 0 - probably nonstandard XM file").arg(I, 0, 16);
    10. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nsamps = readleword(f);
    11. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sn.clear();
    12. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (readlelong(f) != 0x28)
    13. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return QString("sample header size for instrument %1 not 0x28 - probably nonstandard XM file").arg(I, 0, 16);
    14. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;skipnbytes(f, 96+48+48+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2); // skip instrument settings
    15. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 0; j < nsamps; j++) {
    16. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;quint32 samplen;
    17.  
    18. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;samplen = readlelong(f);
    19. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;skipnbytes(f, 4+4+1+1+1+1+1+1); // skip other sample settings
    20. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sn.append(readFLString(f, 22));
    21. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;skipnbytes(f, samplen);
    22. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    23. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sampleNames.push_back(sn);
    24. &nbsp;&nbsp;&nbsp;&nbsp;}
    If f is pointed to where the XM instruments start, the code doesn't get the instrument information correctly; right at the samplen=readlelong(f) it appears to be 20 (decimal) bytes before where it should be. What am I doing wrong? Thanks.
     
  2. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    Ok, I found two things I was doing wrong and I changed some lines to

    Code (Text):
    1. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (nsamps > 0) {
    2. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (readlelong(f) != 0x28)
    3. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return QString("sample header size for instrument %1 not 0x28 - probably nonstandard XM file").arg(I, 0, 16);
    4. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;skipnbytes(f, 96+48+48+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+22); // skip instrument settings
    5. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    However, now I'm winding up with the last instrument before an empty one leaving the file pointer 145 bytes before where it should be; namely, this file on the first instrument without any samples. What am I doing wrong now?
     
  3. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    Bah, figured it out: MilkyTracker is dumb and writes a header size of 0x1D instead of 0x107 for instruments that have no samples. Thanks anyway.
     
  4. TmEE

    TmEE

    Master of OPL3-SA2/3 Tech Member
    1,726
    2
    18
    Estonia, Rapla City
    T-04YBSC-A !
    dedicated format would be nicer, unless you need this for importing files
     
  5. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    Yes this is for importing; in fact I can release a build with importing in it as soon as I squash one last bug.