annotate src/modplug/load_dbm.cxx @ 2284:d19b53359b24

cleaned up the sndfile wav plugin, currently limiting it ONLY TO WAV PLAYBACK. if somebody is more experienced with it and wants to restore the other formats, go ahead (maybe change the name of the plugin too?).
author mf0102 <0102@gmx.at>
date Wed, 09 Jan 2008 15:41:22 +0100
parents 6907fc39b53f
children 107c1fed3d92
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1 /*
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
2 * This source code is public domain.
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
3 *
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
4 * Authors: Olivier Lapicque <olivierl@jps.net>,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
5 * Adam Goode <adam@evdebs.org> (endian and char fixes for PPC)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
6 */
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
7
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
8 ///////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
9 //
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
10 // DigiBooster Pro Module Loader (*.dbm)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
11 //
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
12 // Note: this loader doesn't handle multiple songs
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
13 //
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
14 ///////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
15
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
16 #include "stdafx.h"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
17 #include "sndfile.h"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
18
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
19 //#pragma warning(disable:4244)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
20
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
21 #define DBM_FILE_MAGIC 0x304d4244
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
22 #define DBM_ID_NAME 0x454d414e
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
23 #define DBM_NAMELEN 0x2c000000
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
24 #define DBM_ID_INFO 0x4f464e49
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
25 #define DBM_INFOLEN 0x0a000000
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
26 #define DBM_ID_SONG 0x474e4f53
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
27 #define DBM_ID_INST 0x54534e49
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
28 #define DBM_ID_VENV 0x564e4556
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
29 #define DBM_ID_PATT 0x54544150
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
30 #define DBM_ID_SMPL 0x4c504d53
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
31
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
32 #pragma pack(1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
33
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
34 typedef struct DBMFILEHEADER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
35 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
36 DWORD dbm_id; // "DBM0" = 0x304d4244
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
37 WORD trkver; // Tracker version: 02.15
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
38 WORD reserved;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
39 DWORD name_id; // "NAME" = 0x454d414e
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
40 DWORD name_len; // name length: always 44
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
41 CHAR songname[44];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
42 DWORD info_id; // "INFO" = 0x4f464e49
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
43 DWORD info_len; // 0x0a000000
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
44 WORD instruments;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
45 WORD samples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
46 WORD songs;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
47 WORD patterns;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
48 WORD channels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
49 DWORD song_id; // "SONG" = 0x474e4f53
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
50 DWORD song_len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
51 CHAR songname2[44];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
52 WORD orders;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
53 // WORD orderlist[0]; // orderlist[orders] in words
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
54 } DBMFILEHEADER;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
55
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
56 typedef struct DBMINSTRUMENT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
57 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
58 CHAR name[30];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
59 WORD sampleno;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
60 WORD volume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
61 DWORD finetune;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
62 DWORD loopstart;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
63 DWORD looplen;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
64 WORD panning;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
65 WORD flags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
66 } DBMINSTRUMENT;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
67
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
68 typedef struct DBMENVELOPE
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
69 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
70 WORD instrument;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
71 BYTE flags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
72 BYTE numpoints;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
73 BYTE sustain1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
74 BYTE loopbegin;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
75 BYTE loopend;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
76 BYTE sustain2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
77 WORD volenv[2*32];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
78 } DBMENVELOPE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
79
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
80 typedef struct DBMPATTERN
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
81 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
82 WORD rows;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
83 DWORD packedsize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
84 BYTE patterndata[2]; // [packedsize]
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
85 } DBMPATTERN;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
86
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
87 typedef struct DBMSAMPLE
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
88 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
89 DWORD flags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
90 DWORD samplesize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
91 BYTE sampledata[2]; // [samplesize]
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
92 } DBMSAMPLE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
93
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
94 #pragma pack()
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
95
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
96
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
97 BOOL CSoundFile::ReadDBM(const BYTE *lpStream, DWORD dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
98 //---------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
99 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
100 DBMFILEHEADER *pfh = (DBMFILEHEADER *)lpStream;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
101 DWORD dwMemPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
102 UINT nOrders, nSamples, nInstruments, nPatterns;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
103
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
104 if ((!lpStream) || (dwMemLength <= sizeof(DBMFILEHEADER)) || (!pfh->channels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
105 || (pfh->dbm_id != DBM_FILE_MAGIC) || (!pfh->songs) || (pfh->song_id != DBM_ID_SONG)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
106 || (pfh->name_id != DBM_ID_NAME) || (pfh->name_len != DBM_NAMELEN)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
107 || (pfh->info_id != DBM_ID_INFO) || (pfh->info_len != DBM_INFOLEN)) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
108 dwMemPos = sizeof(DBMFILEHEADER);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
109 nOrders = bswapBE16(pfh->orders);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
110 if (dwMemPos + 2 * nOrders + 8*3 >= dwMemLength) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
111 nInstruments = bswapBE16(pfh->instruments);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
112 nSamples = bswapBE16(pfh->samples);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
113 nPatterns = bswapBE16(pfh->patterns);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
114 m_nType = MOD_TYPE_DBM;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
115 m_nChannels = bswapBE16(pfh->channels);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
116 if (m_nChannels < 4) m_nChannels = 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
117 if (m_nChannels > 64) m_nChannels = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
118 memcpy(m_szNames[0], (pfh->songname[0]) ? pfh->songname : pfh->songname2, 32);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
119 m_szNames[0][31] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
120 for (UINT iOrd=0; iOrd < nOrders; iOrd++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
121 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
122 Order[iOrd] = lpStream[dwMemPos+iOrd*2+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
123 if (iOrd >= MAX_ORDERS-2) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
124 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
125 dwMemPos += 2*nOrders;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
126 while (dwMemPos + 10 < dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
127 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
128 DWORD chunk_id = ((LPDWORD)(lpStream+dwMemPos))[0];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
129 DWORD chunk_size = bswapBE32(((LPDWORD)(lpStream+dwMemPos))[1]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
130 DWORD chunk_pos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
131
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
132 dwMemPos += 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
133 chunk_pos = dwMemPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
134 if ((dwMemPos + chunk_size > dwMemLength) || (chunk_size > dwMemLength)) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
135 dwMemPos += chunk_size;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
136 // Instruments
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
137 if (chunk_id == DBM_ID_INST)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
138 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
139 if (nInstruments >= MAX_INSTRUMENTS) nInstruments = MAX_INSTRUMENTS-1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
140 for (UINT iIns=0; iIns<nInstruments; iIns++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
141 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
142 MODINSTRUMENT *psmp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
143 INSTRUMENTHEADER *penv;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
144 DBMINSTRUMENT *pih;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
145 UINT nsmp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
146
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
147 if (chunk_pos + sizeof(DBMINSTRUMENT) > dwMemPos) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
148 if ((penv = new INSTRUMENTHEADER) == NULL) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
149 pih = (DBMINSTRUMENT *)(lpStream+chunk_pos);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
150 nsmp = bswapBE16(pih->sampleno);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
151 psmp = ((nsmp) && (nsmp < MAX_SAMPLES)) ? &Ins[nsmp] : NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
152 memset(penv, 0, sizeof(INSTRUMENTHEADER));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
153 memcpy(penv->name, pih->name, 30);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
154 if (psmp)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
155 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
156 memcpy(m_szNames[nsmp], pih->name, 30);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
157 m_szNames[nsmp][30] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
158 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
159 Headers[iIns+1] = penv;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
160 penv->nFadeOut = 1024; // ???
2218
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
161 penv->nGlobalVol = 64;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
162 penv->nPan = bswapBE16(pih->panning);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
163 if ((penv->nPan) && (penv->nPan < 256))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
164 penv->dwFlags = ENV_SETPANNING;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
165 else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
166 penv->nPan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
167 penv->nPPC = 5*12;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
168 for (UINT i=0; i<120; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
169 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
170 penv->Keyboard[i] = nsmp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
171 penv->NoteMap[i] = i+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
172 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
173 // Sample Info
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
174 if (psmp)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
175 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
176 DWORD sflags = bswapBE16(pih->flags);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
177 psmp->nVolume = bswapBE16(pih->volume) * 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
178 if ((!psmp->nVolume) || (psmp->nVolume > 256)) psmp->nVolume = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
179 psmp->nGlobalVol = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
180 psmp->nC4Speed = bswapBE32(pih->finetune);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
181 int f2t = FrequencyToTranspose(psmp->nC4Speed);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
182 psmp->RelativeTone = f2t >> 7;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
183 psmp->nFineTune = f2t & 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
184 if ((pih->looplen) && (sflags & 3))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
185 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
186 psmp->nLoopStart = bswapBE32(pih->loopstart);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
187 psmp->nLoopEnd = psmp->nLoopStart + bswapBE32(pih->looplen);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
188 psmp->uFlags |= CHN_LOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
189 psmp->uFlags &= ~CHN_PINGPONGLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
190 if (sflags & 2) psmp->uFlags |= CHN_PINGPONGLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
191 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
192 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
193 chunk_pos += sizeof(DBMINSTRUMENT);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
194 m_nInstruments = iIns+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
195 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
196 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
197 // Volume Envelopes
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
198 if (chunk_id == DBM_ID_VENV)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
199 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
200 UINT nEnvelopes = lpStream[chunk_pos+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
201
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
202 chunk_pos += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
203 for (UINT iEnv=0; iEnv<nEnvelopes; iEnv++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
204 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
205 DBMENVELOPE *peh;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
206 UINT nins;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
207
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
208 if (chunk_pos + sizeof(DBMENVELOPE) > dwMemPos) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
209 peh = (DBMENVELOPE *)(lpStream+chunk_pos);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
210 nins = bswapBE16(peh->instrument);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
211 if ((nins) && (nins < MAX_INSTRUMENTS) && (Headers[nins]) && (peh->numpoints))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
212 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
213 INSTRUMENTHEADER *penv = Headers[nins];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
214
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
215 if (peh->flags & 1) penv->dwFlags |= ENV_VOLUME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
216 if (peh->flags & 2) penv->dwFlags |= ENV_VOLSUSTAIN;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
217 if (peh->flags & 4) penv->dwFlags |= ENV_VOLLOOP;
2218
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
218 penv->nVolEnv = peh->numpoints + 1;
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
219 if (penv->nVolEnv > MAX_ENVPOINTS) penv->nVolEnv = MAX_ENVPOINTS;
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
220 penv->nVolLoopStart = peh->loopbegin;
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
221 penv->nVolLoopEnd = peh->loopend;
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
222 penv->nVolSustainBegin = penv->nVolSustainEnd = peh->sustain1;
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
223 for (UINT i=0; i<penv->nVolEnv; i++)
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
224 {
2218
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
225 penv->VolPoints[i] = bswapBE16(peh->volenv[i*2]);
6907fc39b53f That didn't merge properly. I'll try again at some other point.
William Pitcock <nenolod@atheme.org>
parents: 2216
diff changeset
226 penv->VolEnv[i] = (BYTE)bswapBE16(peh->volenv[i*2+1]);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
227 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
228 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
229 chunk_pos += sizeof(DBMENVELOPE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
230 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
231 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
232 // Packed Pattern Data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
233 if (chunk_id == DBM_ID_PATT)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
234 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
235 if (nPatterns > MAX_PATTERNS) nPatterns = MAX_PATTERNS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
236 for (UINT iPat=0; iPat<nPatterns; iPat++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
237 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
238 DBMPATTERN *pph;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
239 DWORD pksize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
240 UINT nRows;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
241
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
242 if (chunk_pos + sizeof(DBMPATTERN) > dwMemPos) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
243 pph = (DBMPATTERN *)(lpStream+chunk_pos);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
244 pksize = bswapBE32(pph->packedsize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
245 if ((chunk_pos + pksize + 6 > dwMemPos) || (pksize > dwMemPos)) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
246 nRows = bswapBE16(pph->rows);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
247 if ((nRows >= 4) && (nRows <= 256))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
248 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
249 MODCOMMAND *m = AllocatePattern(nRows, m_nChannels);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
250 if (m)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
251 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
252 LPBYTE pkdata = (LPBYTE)&pph->patterndata;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
253 UINT row = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
254 UINT i = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
255
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
256 PatternSize[iPat] = nRows;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
257 Patterns[iPat] = m;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
258 while ((i+3<pksize) && (row < nRows))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
259 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
260 UINT ch = pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
261
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
262 if (ch)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
263 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
264 BYTE b = pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
265 ch--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
266 if (ch < m_nChannels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
267 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
268 if (b & 0x01)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
269 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
270 UINT note = pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
271
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
272 if (note == 0x1F) note = 0xFF; else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
273 if ((note) && (note < 0xFE))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
274 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
275 note = ((note >> 4)*12) + (note & 0x0F) + 13;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
276 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
277 m[ch].note = note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
278 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
279 if (b & 0x02) m[ch].instr = pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
280 if (b & 0x3C)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
281 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
282 UINT cmd1 = 0xFF, param1 = 0, cmd2 = 0xFF, param2 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
283 if (b & 0x04) cmd1 = (UINT)pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
284 if (b & 0x08) param1 = pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
285 if (b & 0x10) cmd2 = (UINT)pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
286 if (b & 0x20) param2 = pkdata[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
287 if (cmd1 == 0x0C)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
288 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
289 m[ch].volcmd = VOLCMD_VOLUME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
290 m[ch].vol = param1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
291 cmd1 = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
292 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
293 if (cmd2 == 0x0C)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
294 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
295 m[ch].volcmd = VOLCMD_VOLUME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
296 m[ch].vol = param2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
297 cmd2 = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
298 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
299 if ((cmd1 > 0x13) || ((cmd1 >= 0x10) && (cmd2 < 0x10)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
300 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
301 cmd1 = cmd2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
302 param1 = param2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
303 cmd2 = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
304 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
305 if (cmd1 <= 0x13)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
306 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
307 m[ch].command = cmd1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
308 m[ch].param = param1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
309 ConvertModCommand(&m[ch]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
310 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
311 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
312 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
313 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
314 if (b & 0x01) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
315 if (b & 0x02) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
316 if (b & 0x04) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
317 if (b & 0x08) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
318 if (b & 0x10) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
319 if (b & 0x20) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
320 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
321 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
322 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
323 row++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
324 m += m_nChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
325 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
326 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
327 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
328 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
329 chunk_pos += 6 + pksize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
330 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
331 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
332 // Reading Sample Data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
333 if (chunk_id == DBM_ID_SMPL)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
334 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
335 if (nSamples >= MAX_SAMPLES) nSamples = MAX_SAMPLES-1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
336 m_nSamples = nSamples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
337 for (UINT iSmp=1; iSmp<=nSamples; iSmp++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
338 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
339 MODINSTRUMENT *pins;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
340 DBMSAMPLE *psh;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
341 DWORD samplesize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
342 DWORD sampleflags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
343
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
344 if (chunk_pos + sizeof(DBMSAMPLE) >= dwMemPos) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
345 psh = (DBMSAMPLE *)(lpStream+chunk_pos);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
346 chunk_pos += 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
347 samplesize = bswapBE32(psh->samplesize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
348 sampleflags = bswapBE32(psh->flags);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
349 pins = &Ins[iSmp];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
350 pins->nLength = samplesize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
351 if (sampleflags & 2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
352 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
353 pins->uFlags |= CHN_16BIT;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
354 samplesize <<= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
355 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
356 if ((chunk_pos+samplesize > dwMemPos) || (samplesize > dwMemLength)) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
357 if (sampleflags & 3)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
358 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
359 ReadSample(pins, (pins->uFlags & CHN_16BIT) ? RS_PCM16M : RS_PCM8S,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
360 (LPSTR)(psh->sampledata), samplesize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
361 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
362 chunk_pos += samplesize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
363 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
364 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
365 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
366 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
367 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
368