external/libmodplug-0.8.8.4/src/load_umx.cpp
author Sam Lantinga <slouken@libsdl.org>
Sun, 09 Jun 2013 16:22:42 -0700
changeset 639 f8901a7ff3f1
permissions -rw-r--r--
Switched from mikmod to libmodplug, which is now in the public domain.
This allows us to add MOD support for iOS and Android, yay!
slouken@639
     1
/*
slouken@639
     2
 * This source code is public domain.
slouken@639
     3
 *
slouken@639
     4
 * Authors: Olivier Lapicque <olivierl@jps.net>
slouken@639
     5
*/
slouken@639
     6
slouken@639
     7
#include "stdafx.h"
slouken@639
     8
#include "sndfile.h"
slouken@639
     9
slouken@639
    10
#define MODMAGIC_OFFSET	(20+31*30+130)
slouken@639
    11
slouken@639
    12
slouken@639
    13
BOOL CSoundFile::ReadUMX(const BYTE *lpStream, DWORD dwMemLength)
slouken@639
    14
//---------------------------------------------------------------
slouken@639
    15
{
slouken@639
    16
	if ((!lpStream) || (dwMemLength < 0x800)) return FALSE;
slouken@639
    17
	// Rip Mods from UMX
slouken@639
    18
	if ((bswapLE32(*((DWORD *)(lpStream+0x20))) < dwMemLength)
slouken@639
    19
	 && (bswapLE32(*((DWORD *)(lpStream+0x18))) <= dwMemLength - 0x10)
slouken@639
    20
	 && (bswapLE32(*((DWORD *)(lpStream+0x18))) >= dwMemLength - 0x200))
slouken@639
    21
	{
slouken@639
    22
		for (UINT uscan=0x40; uscan<0x500; uscan++)
slouken@639
    23
		{
slouken@639
    24
			DWORD dwScan = bswapLE32(*((DWORD *)(lpStream+uscan)));
slouken@639
    25
			// IT
slouken@639
    26
			if (dwScan == 0x4D504D49)
slouken@639
    27
			{
slouken@639
    28
				DWORD dwRipOfs = uscan;
slouken@639
    29
				return ReadIT(lpStream + dwRipOfs, dwMemLength - dwRipOfs);
slouken@639
    30
			}
slouken@639
    31
			// S3M
slouken@639
    32
			if (dwScan == 0x4D524353)
slouken@639
    33
			{
slouken@639
    34
				DWORD dwRipOfs = uscan - 44;
slouken@639
    35
				return ReadS3M(lpStream + dwRipOfs, dwMemLength - dwRipOfs);
slouken@639
    36
			}
slouken@639
    37
			// XM
slouken@639
    38
			if (!strnicmp((LPCSTR)(lpStream+uscan), "Extended Module", 15))
slouken@639
    39
			{
slouken@639
    40
				DWORD dwRipOfs = uscan;
slouken@639
    41
				return ReadXM(lpStream + dwRipOfs, dwMemLength - dwRipOfs);
slouken@639
    42
			}
slouken@639
    43
			// MOD
slouken@639
    44
			if ((uscan > MODMAGIC_OFFSET) && (dwScan == 0x2e4b2e4d))
slouken@639
    45
			{
slouken@639
    46
				DWORD dwRipOfs = uscan - MODMAGIC_OFFSET;
slouken@639
    47
				return ReadMod(lpStream+dwRipOfs, dwMemLength-dwRipOfs);
slouken@639
    48
			}
slouken@639
    49
		}
slouken@639
    50
	}
slouken@639
    51
	return FALSE;
slouken@639
    52
}
slouken@639
    53