Chat

Author Topic: .DMF Specs  (Read 31986 times)

Offline Delek

  • Salí para ver
  • Administrator
  • Hero Member
  • Posts: 1771
    • Delek's Website
    • Email
.DMF Specs
« on: February 04, 2013, 03:23:52 AM »
If you are writing a music app and you want to include support for DMF format, you want to convert any format to the DefleMask format or transform a DMF to a different filetype, this will be helpful:

LATEST DMF FORMAT SPECS

OLD ONES:
http://www.delek.com.ar/soft/deflemask/DMF_SPECS_0x11.txt
http://www.delek.com.ar/soft/deflemask/DMF_SPECS_0x12.txt
http://www.delek.com.ar/soft/deflemask/DMF_SPECS_0x13.txt
http://www.delek.com.ar/soft/deflemask/DMF_SPECS_0x15.txt
« Last Edit: February 29, 2016, 09:45:19 PM by Delek »

Offline UltrasonicMadness

  • Jr. Member
  • Posts: 90
    • My Website
.DMF Specs
« Reply #1 on: February 11, 2013, 12:58:37 PM »
I don't claim to be an expert in file formats but I think you may have made a typo here:
Quote
SYSTEM_SMS 3         (SYSTEM_TOTAL_CHANNELS 3)
Last I checked, the SMS had 4 channels.

You even have the Mega Drive/Genesis listed with 10 channels, which I would assume is 6 for the YM2612 and 4 for the TI SN76489.

I apologize if you have used some compression sorcery resulting in this point being null and void and me appearing ignorant.

As an aside, do you know how I can decompress DMF data so I can look at what, for instance, Monday looks like in a hex editor?

Offline Delek

  • Salí para ver
  • Administrator
  • Hero Member
  • Posts: 1771
    • Delek's Website
    • Email
.DMF Specs
« Reply #2 on: February 11, 2013, 01:33:00 PM »
You are right, I will fix that.

You should use Zlib library to decompress DMFs.

Offline UltrasonicMadness

  • Jr. Member
  • Posts: 90
    • My Website
.DMF Specs
« Reply #3 on: February 11, 2013, 03:30:02 PM »
I checked www.zlib.net and all I could find was source code.

r57shell

  • Guest
.DMF Specs
« Reply #4 on: February 15, 2013, 10:23:53 AM »
If it will help, I use this programs on python.
Compress:
Code: [Select]
import zlib, sys
str_object1 = open(sys.argv[1], 'rb').read()
str_object2 = zlib.compress(str_object1, 9)
f = open(sys.argv[2], 'wb')
f.write(str_object2)
f.close()
Decompres:
Code: [Select]
import zlib, sys
str_object1 = open(sys.argv[1], 'rb').read()
str_object2 = zlib.decompress(str_object1)
f = open(sys.argv[2], 'wb')
f.write(str_object2)
f.close()
Usage (from command line): file.py input output

If you have some simple way to support zlib compression in C++ source, please post here :).

Offline UltrasonicMadness

  • Jr. Member
  • Posts: 90
    • My Website
.DMF Specs
« Reply #5 on: February 18, 2013, 08:04:38 PM »
Sorry if I sound like a complete n00b but how would I 'chdir' or 'dir' in Python?

r57shell

  • Guest
.DMF Specs
« Reply #6 on: February 19, 2013, 10:22:52 AM »
Code: [Select]
os.chdir("/path/to/change/to")compress.py supports full paths.
from C++ you can start process on python for example
Code: [Select]
#include <cstdio>
#include <cstdlib>

void Compress(char* input_path, char* output_path)
{
    char cmd[255];
    sprintf(cmd, "compress.py \"%s\" \"%s\"", input_path, output_path); // make cmd line
    system(cmd); // execute cmd line (start process)
}
« Last Edit: February 19, 2013, 10:24:28 AM by r57shell »

r57shell

  • Guest
.DMF Specs
« Reply #7 on: February 19, 2013, 11:14:51 AM »
For MIDI to DMF tool, I want to requset speed configuration into pulses per beat, and BPM calculation algorithm.
More definitely:
BPM = how many Beats in minute.
Pulses per beat = how many Pulses in beat.
Pulse = row in my opinion.
So BPM*(Pulses per beat) = how many rows in minute. It is more simple(clear) thing than speed.

Offline UltrasonicMadness

  • Jr. Member
  • Posts: 90
    • My Website
.DMF Specs
« Reply #8 on: February 19, 2013, 04:59:59 PM »
I tried it and this is what I got

Code: [Select]
>>> os.chdir(C:)
SyntaxError: invalid syntax
>>>

I'm running Python 2.7.3 with the IDLE GUI on Windows XP Service Pack 3.

Regarding your more recent post, I'm probably not going to write anything based on this. I just thought it would be interesting to see an uncompressed DMF file in a hex editor side-by-side with Delek's specifications.

Offline Delek

  • Salí para ver
  • Administrator
  • Hero Member
  • Posts: 1771
    • Delek's Website
    • Email
.DMF Specs
« Reply #9 on: February 19, 2013, 06:39:52 PM »
Code: [Select]
char *dst=NULL, a=0, *src=NULL;
unsigned long dstSize=0, srcSize=0, i=0;
FILE *DMFFILE=fopen("dmf.dmf", "rb");

fseek(DMFFILE, 0, SEEK_SET);
while(!feof(DMFFILE)){
    fread(&a,1,1,DMFFILE);
    srcSize++;     //GET FILE SIZE
 }
 dstSize=srcSize*256;       //MAX DECOMPRESS RATIO
 src=malloc(srcSize);
 dst=malloc(dstSize);
 if(src!=NULL && dst!=NULL){
     fseek(DMFFILE, 0, SEEK_SET);
     while(!feof(DMFFILE)){
         fread(&src[i],1,1,DMFFILE);
         i++;
     }
     uncompress(dst, &dstSize, src, srcSize);
     fclose(DMFFILE);
     DMFFILE=fopen("tmp", "wb+");
     fwrite(dst, 1, dstSize, DMFFILE);
 }
 free(src);
 free(dst);

With this code you will have an uncompressed DMFfile called "tmp".
« Last Edit: February 19, 2013, 06:41:39 PM by Delek »

r57shell

  • Guest
.DMF Specs
« Reply #10 on: February 20, 2013, 12:15:58 PM »
I tried it and this is what I got
:-\

WinXP/Win7:
1) Hold WIN+R, window opened, Release WIN+R  :D
2) Type cmd in opened window, press ENTER, new window appears. This - named "command line".
3) Now, drag & drop decompress.py saved somewhere on your system into this black (by default) window - decompres.py full path inserted,
4) Type space (one character), and make sure that it is appeared after file path.
5) Now, drag & drop file which you want to decompress - full path appeared
6) Type space (one character), AGAIN
7) Now, drag & drop file which you will replace (for example just clean bin file with size = 0) - it will be resulting uncompressed file.
8) press enter, in command line, to execute comand.
All you need is: Python (for example 2.7.3), and saved compress.py on hard drive.
If it won't work, try to append in begining of command line "python " (without quotes).

It is just 3 paths, delimeted with space, as I told
Usage: decompress.py input output

Delek, main question - where to get "uncompress" function?)

Offline Delek

  • Salí para ver
  • Administrator
  • Hero Member
  • Posts: 1771
    • Delek's Website
    • Email
.DMF Specs
« Reply #11 on: February 20, 2013, 05:34:17 PM »
Uncompress function is, obviously, inside ZLIB library!

r57shell

  • Guest
.DMF Specs
« Reply #12 on: February 20, 2013, 09:18:28 PM »
Delek, Thanks. It's works. Now my code using zlib compression internaly.

If it will help, there is source of my MemFile to simplify operations with zlib. Just replace FILE *f = fopen(...), to MemFile*f = new MemFile(); And use f->pack(), for packing after all data writed.
http://pastebin.com/Q8kmPj0D
« Last Edit: February 20, 2013, 09:20:14 PM by r57shell »

Offline Delek

  • Salí para ver
  • Administrator
  • Hero Member
  • Posts: 1771
    • Delek's Website
    • Email
.DMF Specs
« Reply #13 on: February 20, 2013, 10:40:59 PM »
Great, thanks!

Offline UltrasonicMadness

  • Jr. Member
  • Posts: 90
    • My Website
.DMF Specs
« Reply #14 on: February 21, 2013, 03:00:57 PM »
It worked! I apologize for being such a n00b. I thought I had to do the whole thing in IDLE.

I gotta say, the DMF format looks interesting...