Skip to content

Commit

Permalink
MOD improved SoundTracker support
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHeinrich committed Apr 14, 2022
1 parent c561bfd commit 079c4d7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
21 changes: 11 additions & 10 deletions getid3/getid3.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class getID3
*/
protected $startup_warning = '';

const VERSION = '1.9.21-202202220815';
const VERSION = '1.9.21-202204141319';
const FREAD_BUFFER_SIZE = 32768;

const ATTACHMENTS_NONE = false;
Expand Down Expand Up @@ -1054,15 +1054,16 @@ public function GetFileFormatArray() {
'mime_type' => 'audio/x-monkeys-audio',
),

// has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
// // MOD - audio - MODule (assorted sub-formats)
// 'mod' => array(
// 'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)',
// 'group' => 'audio',
// 'module' => 'mod',
// 'option' => 'mod',
// 'mime_type' => 'audio/mod',
// ),

// MOD - audio - MODule (SoundTracker)
'mod' => array(
//'pattern' => '^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)', // has been known to produce false matches in random files (e.g. JPEGs), leave out until more precise matching available
'pattern' => '^.{1080}(M\\.K\\.)',
'group' => 'audio',
'module' => 'mod',
'option' => 'mod',
'mime_type' => 'audio/mod',
),

// MOD - audio - MODule (Impulse Tracker)
'it' => array(
Expand Down
44 changes: 35 additions & 9 deletions getid3/module.audio.mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public function Analyze() {
return $this->getITheaderFilepointer();
} elseif (preg_match('#^Extended Module#', $fileheader)) {
return $this->getXMheaderFilepointer();
} elseif (preg_match('#^.{44}SCRM#', $fileheader)) {
} elseif (preg_match('#^.{44}SCRM#s', $fileheader)) {
return $this->getS3MheaderFilepointer();
} elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#', $fileheader)) {
//} elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#s', $fileheader)) {
} elseif (preg_match('#^.{1080}(M\\.K\\.)#s', $fileheader)) {
return $this->getMODheaderFilepointer();
}
$this->error('This is not a known type of MOD file');
Expand All @@ -45,17 +46,42 @@ public function Analyze() {
*/
public function getMODheaderFilepointer() {
$info = &$this->getid3->info;
$this->fseek($info['avdataoffset'] + 1080);
$FormatID = $this->fread(4);
if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) {
$this->error('This is not a known type of MOD file');
$this->fseek($info['avdataoffset']);
$filedata = $this->fread(1084);
//if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) {
if (substr($filedata, 1080, 4) == 'M.K.') {

// + 0 song/module working title
// + 20 15 sample headers (see below)
// + 470 song length (number of steps in pattern table)
// + 471 song speed in beats per minute (see below)
// + 472 pattern step table
$offset = 0;
$info['mod']['title'] = rtrim(substr($filedata, $offset, 20), "\x00"); $offset += 20;

$info['tags']['mod']['title'] = array($info['mod']['title']);

for ($samplenumber = 0; $samplenumber < 31; $samplenumber++) {
$sampledata = array();
$sampledata['name'] = substr($filedata, $offset, 22); $offset += 22;
$sampledata['length'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$sampledata['volume'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$sampledata['repeat_offset'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$sampledata['repeat_length'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 2)); $offset += 2;
$info['mod']['samples'][$samplenumber] = $sampledata;
}

$info['mod']['step_count'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 1)); $offset += 1;
$info['mod']['bpm'] = getid3_lib::BigEndian2Int(substr($filedata, $offset, 1)); $offset += 1;

} else {
$this->error('unknown MOD ID at offset 1080: '.getid3_lib::PrintHexBytes(substr($filedata, 1080, 4)));
return false;
}

$info['fileformat'] = 'mod';

$this->error('MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
return false;
$this->warning('MOD (SoundTracker) parsing incomplete in this version of getID3() ['.$this->getid3->version().']');
return true;
}

/**
Expand Down

0 comments on commit 079c4d7

Please sign in to comment.