From 6b0e493500e927c1bf5747e1b01749dbf05e776f Mon Sep 17 00:00:00 2001 From: zico Date: Mon, 10 Jun 2013 16:34:45 +0200 Subject: [PATCH] Made hmp code actually read tempo. Due to missing documentation of the format I can only guess it's a 4 bit int --- CHANGELOG.txt | 4 ++++ misc/hmp.c | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c5e651e93..4ef80aeeb 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20130610 +-------- +misc/hmp.c: Made hmp code actually read tempo. Due to missing documentation of the format I can only guess it's a 4 bit int + 20130422 -------- main/net_udp.c: In restricted game mode check for player callsign and sockaddr at the same time; Clear Netgame struct each time player enters a new IP in manual join menu diff --git a/misc/hmp.c b/misc/hmp.c index 94fefe50c..34a64fa49 100644 --- a/misc/hmp.c +++ b/misc/hmp.c @@ -44,7 +44,7 @@ void hmp_close(hmp_file *hmp) } hmp_file *hmp_open(const char *filename) { - int i, data, num_tracks; + int i, data, num_tracks, tempo; char buf[256]; PHYSFS_file *fp; hmp_file *hmp; @@ -88,9 +88,21 @@ hmp_file *hmp_open(const char *filename) { hmp_close(hmp); return NULL; } - hmp->num_trks = num_tracks; - hmp->tempo = 120; + + if (PHYSFSX_fseek(fp, 0x38, SEEK_SET)) + { + PHYSFS_close(fp); + hmp_close(hmp); + return NULL; + } + if (PHYSFS_read(fp, &tempo, 4, 1) != 1) + { + PHYSFS_close(fp); + hmp_close(hmp); + return NULL; + } + hmp->tempo = tempo; if (PHYSFSX_fseek(fp, 0x308, SEEK_SET)) { @@ -720,6 +732,7 @@ void hmp2mid(char *hmp_name, unsigned char **midbuf, unsigned int *midlen) return; *midlen = 0; + time_div = hmp->tempo*1.6; // write MIDI-header *midbuf = d_realloc(*midbuf, *midlen + 4);