annotate src/modplug/load_it.cxx @ 2216:3673c7ec4ea2

Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
author William Pitcock <nenolod@atheme.org>
date Fri, 07 Dec 2007 12:08:47 -0600
parents 6b5a52635b3b
children 6907fc39b53f
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>,
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
5 * Adam Goode <adam@evdebs.org> (endian and char fixes for PPC)
136
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 #include "stdafx.h"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
9 #include "sndfile.h"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
10 #include "it_defs.h"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
11
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
12 /* blah, -mrsb.
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
13 this is a schism header */
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
14 #include "midi.h"
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
15
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
16 #ifdef MSC_VER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
17 #pragma warning(disable:4244)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
18 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
19
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
20 BYTE autovibit2xm[8] =
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
21 { 0, 3, 1, 4, 2, 0, 0, 0 };
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
22
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
23 BYTE autovibxm2it[8] =
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
24 { 0, 2, 4, 1, 3, 0, 0, 0 };
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
25
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
26 //////////////////////////////////////////////////////////
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
27 // Impulse Tracker IT file support (import only)
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
28
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
29
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
30 static inline UINT ConvertVolParam(UINT value)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
33 return (value > 9) ? 9 : value;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
34 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
37 BOOL CSoundFile::ITInstrToMPT(const void *p, INSTRUMENTHEADER *penv, UINT trkvers)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
38 //--------------------------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
39 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
40 if (trkvers < 0x0200)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
41 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
42 const ITOLDINSTRUMENT *pis = (const ITOLDINSTRUMENT *)p;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
43 memcpy(penv->name, pis->name, 26);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
44 memcpy(penv->filename, pis->filename, 12);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
45 penv->nFadeOut = bswapLE16(pis->fadeout) << 6;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
46 penv->nGlobalVol = 128;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
47 for (UINT j=0; j<120; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
48 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
49 UINT note = pis->keyboard[j*2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
50 UINT ins = pis->keyboard[j*2+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
51 if (ins < MAX_SAMPLES) penv->Keyboard[j] = ins;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
52 if (note < 128) penv->NoteMap[j] = note+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
53 else if (note >= 0xFE) penv->NoteMap[j] = note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
54 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
55 if (pis->flags & 0x01) penv->dwFlags |= ENV_VOLUME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
56 if (pis->flags & 0x02) penv->dwFlags |= ENV_VOLLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
57 if (pis->flags & 0x04) penv->dwFlags |= ENV_VOLSUSTAIN;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
58 penv->VolEnv.nLoopStart = pis->vls;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
59 penv->VolEnv.nLoopEnd = pis->vle;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
60 penv->VolEnv.nSustainStart = pis->sls;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
61 penv->VolEnv.nSustainEnd = pis->sle;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
62 penv->VolEnv.nNodes = 25;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
63 for (UINT ev=0; ev<25; ev++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
64 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
65 if ((penv->VolEnv.Ticks[ev] = pis->nodes[ev*2]) == 0xFF)
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
66 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
67 penv->VolEnv.nNodes = ev;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
68 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
69 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
70 penv->VolEnv.Values[ev] = pis->nodes[ev*2+1];
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
71 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
72 penv->nNNA = pis->nna;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
73 penv->nDCT = pis->dnc;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
74 penv->nPan = 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
75 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
76 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
77 const ITINSTRUMENT *pis = (const ITINSTRUMENT *)p;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
78 memcpy(penv->name, pis->name, 26);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
79 memcpy(penv->filename, pis->filename, 12);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
80 penv->nMidiProgram = pis->mpr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
81 penv->nMidiChannel = pis->mch;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
82 penv->wMidiBank = bswapLE16(pis->mbank);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
83 penv->nFadeOut = bswapLE16(pis->fadeout) << 5;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
84 penv->nGlobalVol = pis->gbv;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
85 if (penv->nGlobalVol > 128) penv->nGlobalVol = 128;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
86 for (UINT j=0; j<120; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
87 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
88 UINT note = pis->keyboard[j*2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
89 UINT ins = pis->keyboard[j*2+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
90 if (ins < MAX_SAMPLES) penv->Keyboard[j] = ins;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
91 if (note < 128) penv->NoteMap[j] = note+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
92 else if (note >= 0xFE) penv->NoteMap[j] = note;
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 // Volume Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
95 if (pis->volenv.flags & 1) penv->dwFlags |= ENV_VOLUME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
96 if (pis->volenv.flags & 2) penv->dwFlags |= ENV_VOLLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
97 if (pis->volenv.flags & 4) penv->dwFlags |= ENV_VOLSUSTAIN;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
98 if (pis->volenv.flags & 8) penv->dwFlags |= ENV_VOLCARRY;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
99 penv->VolEnv.nNodes = pis->volenv.num;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
100 if (penv->VolEnv.nNodes > 25) penv->VolEnv.nNodes = 25;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
101
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
102 penv->VolEnv.nLoopStart = pis->volenv.lpb;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
103 penv->VolEnv.nLoopEnd = pis->volenv.lpe;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
104 penv->VolEnv.nSustainStart = pis->volenv.slb;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
105 penv->VolEnv.nSustainEnd = pis->volenv.sle;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
106 // Panning Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
107 if (pis->panenv.flags & 1) penv->dwFlags |= ENV_PANNING;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
108 if (pis->panenv.flags & 2) penv->dwFlags |= ENV_PANLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
109 if (pis->panenv.flags & 4) penv->dwFlags |= ENV_PANSUSTAIN;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
110 if (pis->panenv.flags & 8) penv->dwFlags |= ENV_PANCARRY;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
111 penv->PanEnv.nNodes = pis->panenv.num;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
112 if (penv->PanEnv.nNodes > 25) penv->PanEnv.nNodes = 25;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
113 penv->PanEnv.nLoopStart = pis->panenv.lpb;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
114 penv->PanEnv.nLoopEnd = pis->panenv.lpe;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
115 penv->PanEnv.nSustainStart = pis->panenv.slb;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
116 penv->PanEnv.nSustainEnd = pis->panenv.sle;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
117 // Pitch Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
118 if (pis->pitchenv.flags & 1) penv->dwFlags |= ENV_PITCH;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
119 if (pis->pitchenv.flags & 2) penv->dwFlags |= ENV_PITCHLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
120 if (pis->pitchenv.flags & 4) penv->dwFlags |= ENV_PITCHSUSTAIN;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
121 if (pis->pitchenv.flags & 8) penv->dwFlags |= ENV_PITCHCARRY;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
122 if (pis->pitchenv.flags & 0x80) penv->dwFlags |= ENV_FILTER;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
123 penv->PitchEnv.nNodes = pis->pitchenv.num;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
124 if (penv->PitchEnv.nNodes > 25) penv->PitchEnv.nNodes = 25;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
125 penv->PitchEnv.nLoopStart = pis->pitchenv.lpb;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
126 penv->PitchEnv.nLoopEnd = pis->pitchenv.lpe;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
127 penv->PitchEnv.nSustainStart = pis->pitchenv.slb;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
128 penv->PitchEnv.nSustainEnd = pis->pitchenv.sle;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
129 // Envelopes Data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
130 for (UINT ev=0; ev<25; ev++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
131 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
132 penv->VolEnv.Values[ev] = pis->volenv.data[ev*3];
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
133 penv->VolEnv.Ticks[ev] = (pis->volenv.data[ev*3+2] << 8) | (pis->volenv.data[ev*3+1]);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
134 penv->PanEnv.Values[ev] = pis->panenv.data[ev*3] + 32;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
135 penv->PanEnv.Ticks[ev] = (pis->panenv.data[ev*3+2] << 8) | (pis->panenv.data[ev*3+1]);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
136 penv->PitchEnv.Values[ev] = pis->pitchenv.data[ev*3] + 32;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
137 penv->PitchEnv.Ticks[ev] = (pis->pitchenv.data[ev*3+2] << 8) | (pis->pitchenv.data[ev*3+1]);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
138 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
139 penv->nNNA = pis->nna % 4;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
140 penv->nDCT = pis->dct % 4;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
141 penv->nDNA = pis->dca % 3;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
142 penv->nPPS = pis->pps;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
143 penv->nPPC = pis->ppc;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
144 penv->nIFC = pis->ifc;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
145 penv->nIFR = pis->ifr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
146 penv->nVolSwing = pis->rv;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
147 penv->nPanSwing = pis->rp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
148 penv->nPan = (pis->dfp & 0x7F) << 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
149 if (penv->nPan > 256) penv->nPan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
150 if (pis->dfp < 0x80) penv->dwFlags |= ENV_SETPANNING;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
151 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
152 if ((penv->VolEnv.nLoopStart >= 25) || (penv->VolEnv.nLoopEnd >= 25)) penv->dwFlags &= ~ENV_VOLLOOP;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
153 if ((penv->VolEnv.nSustainStart >= 25) || (penv->VolEnv.nSustainEnd >= 25)) penv->dwFlags &= ~ENV_VOLSUSTAIN;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
154 return TRUE;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
157
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
158 BOOL CSoundFile::ReadIT(const BYTE *lpStream, DWORD dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
159 //--------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
160 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
161 ITFILEHEADER pifh = *(ITFILEHEADER *)lpStream;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
162 DWORD dwMemPos = sizeof(ITFILEHEADER);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
163 DWORD inspos[MAX_INSTRUMENTS];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
164 DWORD smppos[MAX_SAMPLES];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
165 DWORD patpos[MAX_PATTERNS];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
166 BYTE chnmask[64], channels_used[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
167 MODCOMMAND lastvalue[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
168
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
169 if ((!lpStream) || (dwMemLength < 0xc2)) return FALSE;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
170
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
171 pifh.id = bswapLE32(pifh.id);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
172 if (pifh.id == 0x49504D49) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
173 if (dwMemLength < 554) return FALSE;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
174
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
175 WORD tv;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
176 INSTRUMENTHEADER *zenv = new INSTRUMENTHEADER;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
177 if (!zenv) return FALSE;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
178 memset(zenv, 0, sizeof(INSTRUMENTHEADER));
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
179 memcpy(&tv, lpStream+0x1C, 2); /* trkvers */
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
180 if (!ITInstrToMPT(lpStream, zenv, tv)) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
181 delete zenv;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
182 return FALSE;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
183 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
184
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
185 /* okay, we need samples now */
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
186 unsigned int q = 554;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
187 BYTE expect_samples = lpStream[0x1E];
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
188
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
189 m_nType = MOD_TYPE_IT;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
190 m_nInstruments = 1;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
191 m_nSamples = expect_samples;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
192 m_dwSongFlags = SONG_INSTRUMENTMODE | SONG_LINEARSLIDES /* eh? */;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
193
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
194 memcpy(m_szNames[0], lpStream + 0x20, 26);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
195 m_szNames[0][26] = 0;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
196
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
197 if (q+(80*expect_samples) >= dwMemLength) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
198 delete zenv;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
199 return FALSE;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
200 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
201
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
202 for (UINT nsmp = 0; nsmp < expect_samples; nsmp++) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
203
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
204 ITSAMPLESTRUCT pis = *(ITSAMPLESTRUCT *)(lpStream+q);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
205 q += 80; /* length of ITS header */
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
206
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
207 pis.id = bswapLE32(pis.id);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
208 pis.length = bswapLE32(pis.length);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
209 pis.loopbegin = bswapLE32(pis.loopbegin);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
210 pis.loopend = bswapLE32(pis.loopend);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
211 pis.C5Speed = bswapLE32(pis.C5Speed);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
212 pis.susloopbegin = bswapLE32(pis.susloopbegin);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
213 pis.susloopend = bswapLE32(pis.susloopend);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
214 pis.samplepointer = bswapLE32(pis.samplepointer);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
215
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
216 if (pis.id == 0x53504D49)
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
217 {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
218 MODINSTRUMENT *pins = &Ins[nsmp+1];
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
219 memcpy(pins->name, pis.filename, 12);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
220 pins->uFlags = 0;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
221 pins->nLength = 0;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
222 pins->nLoopStart = pis.loopbegin;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
223 pins->nLoopEnd = pis.loopend;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
224 pins->nSustainStart = pis.susloopbegin;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
225 pins->nSustainEnd = pis.susloopend;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
226 pins->nC4Speed = pis.C5Speed;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
227 if (!pins->nC4Speed) pins->nC4Speed = 8363;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
228 //if (pis.C5Speed < 256) pins->nC4Speed = 256;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
229 pins->nVolume = pis.vol << 2;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
230 if (pins->nVolume > 256) pins->nVolume = 256;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
231 pins->nGlobalVol = pis.gvl;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
232 if (pins->nGlobalVol > 64) pins->nGlobalVol = 64;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
233 if (pis.flags & 0x10) pins->uFlags |= CHN_LOOP;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
234 if (pis.flags & 0x20) pins->uFlags |= CHN_SUSTAINLOOP;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
235 if (pis.flags & 0x40) pins->uFlags |= CHN_PINGPONGLOOP;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
236 if (pis.flags & 0x80) pins->uFlags |= CHN_PINGPONGSUSTAIN;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
237 pins->nPan = (pis.dfp & 0x7F) << 2;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
238 if (pins->nPan > 256) pins->nPan = 256;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
239 if (pis.dfp & 0x80) pins->uFlags |= CHN_PANNING;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
240 pins->nVibType = autovibit2xm[pis.vit & 7];
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
241 pins->nVibRate = pis.vis;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
242 pins->nVibDepth = pis.vid & 0x7F;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
243 pins->nVibSweep = pis.vir;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
244 if ((pis.samplepointer) && (pis.samplepointer < dwMemLength) && (pis.length))
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
245 {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
246 pins->nLength = pis.length;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
247 if (pins->nLength > MAX_SAMPLE_LENGTH) pins->nLength = MAX_SAMPLE_LENGTH;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
248 UINT flags = (pis.cvt & 1) ? RS_PCM8S : RS_PCM8U;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
249 if (pis.flags & 2)
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
250 {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
251 flags += 5;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
252 if (pis.flags & 4) flags |= RSF_STEREO;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
253 pins->uFlags |= CHN_16BIT;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
254 // IT 2.14 16-bit packed sample ?
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
255 if (pis.flags & 8) flags = ((pifh.cmwt >= 0x215) && (pis.cvt & 4)) ? RS_IT21516 : RS_IT21416;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
256 } else
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
257 {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
258 if (pis.flags & 4) flags |= RSF_STEREO;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
259 if (pis.cvt == 0xFF) flags = RS_ADPCM4; else
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
260 // IT 2.14 8-bit packed sample ?
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
261 if (pis.flags & 8) flags = ((pifh.cmwt >= 0x215) && (pis.cvt & 4)) ? RS_IT2158 : RS_IT2148;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
262 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
263 ReadSample(&Ins[nsmp+1], flags, (LPSTR)(lpStream+pis.samplepointer), dwMemLength - pis.samplepointer);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
264 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
265 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
266 memcpy(m_szNames[nsmp+1], pis.name, 26);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
267
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
268 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
269
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
270 Headers[1] = zenv;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
271 return TRUE;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
272 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
273
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
274
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
275 pifh.ordnum = bswapLE16(pifh.ordnum);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
276 pifh.insnum = bswapLE16(pifh.insnum);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
277 pifh.smpnum = bswapLE16(pifh.smpnum);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
278 pifh.patnum = bswapLE16(pifh.patnum);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
279 pifh.cwtv = bswapLE16(pifh.cwtv);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
280 pifh.cmwt = bswapLE16(pifh.cmwt);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
281 pifh.flags = bswapLE16(pifh.flags);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
282 pifh.special = bswapLE16(pifh.special);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
283 pifh.msglength = bswapLE16(pifh.msglength);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
284 pifh.msgoffset = bswapLE32(pifh.msgoffset);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
285 pifh.reserved2 = bswapLE32(pifh.reserved2);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
286
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
287
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
288
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
289 if ((pifh.id != 0x4D504D49) || (pifh.insnum >= MAX_INSTRUMENTS)
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
290 || (pifh.smpnum >= MAX_INSTRUMENTS)) return FALSE;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
291 if (dwMemPos + pifh.ordnum + pifh.insnum*4
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
292 + pifh.smpnum*4 + pifh.patnum*4 > dwMemLength) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
293 m_nType = MOD_TYPE_IT;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
294 if (!(pifh.flags & 0x01)) m_dwSongFlags |= SONG_NOSTEREO;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
295 if (pifh.flags & 0x04) m_dwSongFlags |= SONG_INSTRUMENTMODE;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
296 if (pifh.flags & 0x08) m_dwSongFlags |= SONG_LINEARSLIDES;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
297 if (pifh.flags & 0x10) m_dwSongFlags |= SONG_ITOLDEFFECTS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
298 if (pifh.flags & 0x20) m_dwSongFlags |= SONG_ITCOMPATMODE;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
299 if (pifh.flags & 0x40) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
300 midi_flags |= MIDI_PITCH_BEND;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
301 midi_pitch_depth = pifh.pwd;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
302 }
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
303 if (pifh.flags & 0x80) m_dwSongFlags |= SONG_EMBEDMIDICFG;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
304 if (pifh.flags & 0x1000) m_dwSongFlags |= SONG_EXFILTERRANGE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
305 memcpy(m_szNames[0], pifh.songname, 26);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
306 m_szNames[0][26] = 0;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
307 if (pifh.cwtv >= 0x0213) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
308 m_rowHighlightMinor = pifh.hilight_minor;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
309 m_rowHighlightMajor = pifh.hilight_major;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
310 } else {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
311 m_rowHighlightMinor = 4;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
312 m_rowHighlightMajor = 16;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
313 }
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
314 // Global Volume
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
315 m_nDefaultGlobalVolume = pifh.globalvol << 1;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
316 if (m_nDefaultGlobalVolume > 256) m_nDefaultGlobalVolume = 256;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
317 if (pifh.speed) m_nDefaultSpeed = pifh.speed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
318 if (pifh.tempo) m_nDefaultTempo = pifh.tempo;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
319 m_nSongPreAmp = pifh.mv;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
320 if (m_nSongPreAmp > 128)
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
321 m_nSongPreAmp = 128;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
322 m_nStereoSeparation = pifh.sep;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
323 // Reading Channels Pan Positions
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
324 for (int ipan=0; ipan<64; ipan++) if (pifh.chnpan[ipan] != 0xFF)
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 ChnSettings[ipan].nVolume = pifh.chnvol[ipan];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
327 ChnSettings[ipan].nPan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
328 if (pifh.chnpan[ipan] & 0x80) ChnSettings[ipan].dwFlags |= CHN_MUTE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
329 UINT n = pifh.chnpan[ipan] & 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
330 if (n <= 64) ChnSettings[ipan].nPan = n << 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
331 if (n == 100) ChnSettings[ipan].dwFlags |= CHN_SURROUND;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
332 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
333 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
334 // Reading Song Message
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
335 if ((pifh.special & 0x01) && (pifh.msglength) && (pifh.msgoffset + pifh.msglength < dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
336 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
337 m_lpszSongComments = new char[pifh.msglength+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
338 if (m_lpszSongComments)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
339 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
340 memcpy(m_lpszSongComments, lpStream+pifh.msgoffset, pifh.msglength);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
341 m_lpszSongComments[pifh.msglength] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
342 }
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 // Reading orders
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
345 UINT nordsize = pifh.ordnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
346 if (nordsize > MAX_ORDERS) nordsize = MAX_ORDERS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
347 memcpy(Order, lpStream+dwMemPos, nordsize);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
348
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
349 dwMemPos += pifh.ordnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
350 // Reading Instrument Offsets
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
351 memset(inspos, 0, sizeof(inspos));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
352 UINT inspossize = pifh.insnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
353 if (inspossize > MAX_INSTRUMENTS) inspossize = MAX_INSTRUMENTS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
354 inspossize <<= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
355 memcpy(inspos, lpStream+dwMemPos, inspossize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
356 for (UINT j=0; j < (inspossize>>2); j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
357 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
358 inspos[j] = bswapLE32(inspos[j]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
359 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
360 dwMemPos += pifh.insnum * 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
361 // Reading Samples Offsets
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
362 memset(smppos, 0, sizeof(smppos));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
363 UINT smppossize = pifh.smpnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
364 if (smppossize > MAX_SAMPLES) smppossize = MAX_SAMPLES;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
365 smppossize <<= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
366 memcpy(smppos, lpStream+dwMemPos, smppossize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
367 for (UINT j=0; j < (smppossize>>2); j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
368 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
369 smppos[j] = bswapLE32(smppos[j]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
370 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
371 dwMemPos += pifh.smpnum * 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
372 // Reading Patterns Offsets
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
373 memset(patpos, 0, sizeof(patpos));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
374 UINT patpossize = pifh.patnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
375 if (patpossize > MAX_PATTERNS) patpossize = MAX_PATTERNS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
376 patpossize <<= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
377 memcpy(patpos, lpStream+dwMemPos, patpossize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
378 for (UINT j=0; j < (patpossize>>2); j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
379 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
380 patpos[j] = bswapLE32(patpos[j]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
381 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
382 dwMemPos += pifh.patnum * 4;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
383
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
384 for (UINT i = 0; i < pifh.ordnum; i++) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
385 if (Order[i] >= pifh.patnum && Order[i] < MAX_PATTERNS) {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
386 pifh.patnum = Order[i];
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
387 for (UINT j = patpossize; j < (unsigned)(pifh.patnum>>2); j++)
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
388 patpos[j] = 0;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
389 patpossize = pifh.patnum;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
390 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
391 }
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
392
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
393
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
394 // Reading IT Extra Info
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
395 if (dwMemPos + 2 < dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
396 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
397 UINT nflt = bswapLE16(*((WORD *)(lpStream + dwMemPos)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
398 dwMemPos += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
399 if (dwMemPos + nflt * 8 < dwMemLength) dwMemPos += nflt * 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
400 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
401 // Reading Midi Output & Macros
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
402 if (m_dwSongFlags & SONG_EMBEDMIDICFG)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
403 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
404 if (dwMemPos + sizeof(MODMIDICFG) < dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
405 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
406 memcpy(&m_MidiCfg, lpStream+dwMemPos, sizeof(MODMIDICFG));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
407 dwMemPos += sizeof(MODMIDICFG);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
408 } else {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
409 ResetMidiCfg();
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
410 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
411 } else {
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
412 ResetMidiCfg();
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
413 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
414 #if 0
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
415 // Read pattern names: "PNAM"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
416 if ((dwMemPos + 8 < dwMemLength) && (bswapLE32(*((DWORD *)(lpStream+dwMemPos))) == 0x4d414e50))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
417 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
418 UINT len = bswapLE32(*((DWORD *)(lpStream+dwMemPos+4)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
419 dwMemPos += 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
420 if ((dwMemPos + len <= dwMemLength) && (len <= MAX_PATTERNS*MAX_PATTERNNAME) && (len >= MAX_PATTERNNAME))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
421 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
422 m_lpszPatternNames = new char[len];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
423 if (m_lpszPatternNames)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
424 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
425 m_nPatternNames = len / MAX_PATTERNNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
426 memcpy(m_lpszPatternNames, lpStream+dwMemPos, len);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
427 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
428 dwMemPos += len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
429 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
430 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
431 #endif
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
432 // 4-channels minimum
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
433 m_nChannels = 4;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
434 #if 0
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
435 // Read channel names: "CNAM"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
436 if ((dwMemPos + 8 < dwMemLength) && (bswapLE32(*((DWORD *)(lpStream+dwMemPos))) == 0x4d414e43))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
437 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
438 UINT len = bswapLE32(*((DWORD *)(lpStream+dwMemPos+4)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
439 dwMemPos += 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
440 if ((dwMemPos + len <= dwMemLength) && (len <= 64*MAX_CHANNELNAME))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
441 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
442 UINT n = len / MAX_CHANNELNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
443 if (n > m_nChannels) m_nChannels = n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
444 for (UINT i=0; i<n; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
445 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
446 memcpy(ChnSettings[i].szName, (lpStream+dwMemPos+i*MAX_CHANNELNAME), MAX_CHANNELNAME);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
447 ChnSettings[i].szName[MAX_CHANNELNAME-1] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
448 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
449 dwMemPos += len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
450 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
451 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
452 // Read mix plugins information
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
453 if (dwMemPos + 8 < dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
454 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
455 dwMemPos += LoadMixPlugins(lpStream+dwMemPos, dwMemLength-dwMemPos);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
456 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
457 #endif
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
458 // Checking for unused channels
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
459 UINT npatterns = pifh.patnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
460 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
461 for (UINT patchk=0; patchk<npatterns; patchk++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
462 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
463 memset(chnmask, 0, sizeof(chnmask));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
464 if ((!patpos[patchk]) || ((DWORD)patpos[patchk] + 4 >= dwMemLength)) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
465 UINT len = bswapLE16(*((WORD *)(lpStream+patpos[patchk])));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
466 UINT rows = bswapLE16(*((WORD *)(lpStream+patpos[patchk]+2)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
467 if ((rows < 4) || (rows > 256)) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
468 if (patpos[patchk]+8+len > dwMemLength) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
469 UINT i = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
470 const BYTE *p = lpStream+patpos[patchk]+8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
471 UINT nrow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
472 while (nrow<rows)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
473 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
474 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
475 BYTE b = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
476 if (!b)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
477 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
478 nrow++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
479 continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
480 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
481 UINT ch = b & 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
482 if (ch) ch = (ch - 1) & 0x3F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
483 if (b & 0x80)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
484 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
485 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
486 chnmask[ch] = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
487 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
488 // Channel used
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
489 if (chnmask[ch] & 0x0F)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
490 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
491 if ((ch >= m_nChannels) && (ch < 64)) m_nChannels = ch+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
492 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
493 // Note
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
494 if (chnmask[ch] & 1) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
495 // Instrument
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
496 if (chnmask[ch] & 2) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
497 // Volume
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
498 if (chnmask[ch] & 4) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
499 // Effect
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
500 if (chnmask[ch] & 8) i += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
501 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
502 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
503 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
504 // Reading Instruments
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
505 m_nInstruments = pifh.insnum;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
506 if (m_nInstruments >= MAX_INSTRUMENTS) m_nInstruments = MAX_INSTRUMENTS-1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
507 for (UINT nins=0; nins<m_nInstruments; nins++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
508 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
509 if ((inspos[nins] > 0) && (inspos[nins] < dwMemLength - sizeof(ITOLDINSTRUMENT)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
510 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
511 INSTRUMENTHEADER *penv = new INSTRUMENTHEADER;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
512 if (!penv) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
513 Headers[nins+1] = penv;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
514 memset(penv, 0, sizeof(INSTRUMENTHEADER));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
515 ITInstrToMPT(lpStream + inspos[nins], penv, pifh.cmwt);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
516 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
517 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
518 // Reading Samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
519 m_nSamples = pifh.smpnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
520 if (m_nSamples >= MAX_SAMPLES) m_nSamples = MAX_SAMPLES-1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
521 for (UINT nsmp=0; nsmp<pifh.smpnum; nsmp++) if ((smppos[nsmp]) && (smppos[nsmp] + sizeof(ITSAMPLESTRUCT) <= dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
522 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
523 ITSAMPLESTRUCT pis = *(ITSAMPLESTRUCT *)(lpStream+smppos[nsmp]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
524 pis.id = bswapLE32(pis.id);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
525 pis.length = bswapLE32(pis.length);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
526 pis.loopbegin = bswapLE32(pis.loopbegin);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
527 pis.loopend = bswapLE32(pis.loopend);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
528 pis.C5Speed = bswapLE32(pis.C5Speed);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
529 pis.susloopbegin = bswapLE32(pis.susloopbegin);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
530 pis.susloopend = bswapLE32(pis.susloopend);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
531 pis.samplepointer = bswapLE32(pis.samplepointer);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
532
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
533 if (pis.id == 0x53504D49)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
534 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
535 MODINSTRUMENT *pins = &Ins[nsmp+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
536 memcpy(pins->name, pis.filename, 12);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
537 pins->uFlags = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
538 pins->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
539 pins->nLoopStart = pis.loopbegin;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
540 pins->nLoopEnd = pis.loopend;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
541 pins->nSustainStart = pis.susloopbegin;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
542 pins->nSustainEnd = pis.susloopend;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
543 pins->nC4Speed = pis.C5Speed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
544 if (!pins->nC4Speed) pins->nC4Speed = 8363;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
545 //if (pis.C5Speed < 256) pins->nC4Speed = 256;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
546 pins->nVolume = pis.vol << 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
547 if (pins->nVolume > 256) pins->nVolume = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
548 pins->nGlobalVol = pis.gvl;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
549 if (pins->nGlobalVol > 64) pins->nGlobalVol = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
550 if (pis.flags & 0x10) pins->uFlags |= CHN_LOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
551 if (pis.flags & 0x20) pins->uFlags |= CHN_SUSTAINLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
552 if (pis.flags & 0x40) pins->uFlags |= CHN_PINGPONGLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
553 if (pis.flags & 0x80) pins->uFlags |= CHN_PINGPONGSUSTAIN;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
554 pins->nPan = (pis.dfp & 0x7F) << 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
555 if (pins->nPan > 256) pins->nPan = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
556 if (pis.dfp & 0x80) pins->uFlags |= CHN_PANNING;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
557 pins->nVibType = autovibit2xm[pis.vit & 7];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
558 pins->nVibRate = pis.vis;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
559 pins->nVibDepth = pis.vid & 0x7F;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
560 pins->nVibSweep = pis.vir;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
561 if ((pis.samplepointer) && (pis.samplepointer < dwMemLength) && (pis.length))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
562 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
563 pins->nLength = pis.length;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
564 if (pins->nLength > MAX_SAMPLE_LENGTH) pins->nLength = MAX_SAMPLE_LENGTH;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
565 UINT flags = (pis.cvt & 1) ? RS_PCM8S : RS_PCM8U;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
566 if (pis.flags & 2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
567 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
568 flags += 5;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
569 if (pis.flags & 4) flags |= RSF_STEREO;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
570 pins->uFlags |= CHN_16BIT;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
571 // IT 2.14 16-bit packed sample ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
572 if (pis.flags & 8) flags = ((pifh.cmwt >= 0x215) && (pis.cvt & 4)) ? RS_IT21516 : RS_IT21416;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
573 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
574 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
575 if (pis.flags & 4) flags |= RSF_STEREO;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
576 if (pis.cvt == 0xFF) flags = RS_ADPCM4; else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
577 // IT 2.14 8-bit packed sample ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
578 if (pis.flags & 8) flags = ((pifh.cmwt >= 0x215) && (pis.cvt & 4)) ? RS_IT2158 : RS_IT2148;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
579 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
580 ReadSample(&Ins[nsmp+1], flags, (LPSTR)(lpStream+pis.samplepointer), dwMemLength - pis.samplepointer);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
581 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
582 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
583 memcpy(m_szNames[nsmp+1], pis.name, 26);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
584 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
585 // Reading Patterns
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
586 for (UINT npat=0; npat<npatterns; npat++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
587 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
588 if ((!patpos[npat]) || ((DWORD)patpos[npat] + 4 >= dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
589 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
590 PatternSize[npat] = 64;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
591 PatternAllocSize[npat] = 64;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
592 Patterns[npat] = AllocatePattern(64, m_nChannels);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
593 continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
594 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
595
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
596 UINT len = bswapLE16(*((WORD *)(lpStream+patpos[npat])));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
597 UINT rows = bswapLE16(*((WORD *)(lpStream+patpos[npat]+2)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
598 if ((rows < 4) || (rows > 256)) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
599 if (patpos[npat]+8+len > dwMemLength) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
600 PatternSize[npat] = rows;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
601 PatternAllocSize[npat] = rows;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
602 if ((Patterns[npat] = AllocatePattern(rows, m_nChannels)) == NULL) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
603 memset(lastvalue, 0, sizeof(lastvalue));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
604 memset(chnmask, 0, sizeof(chnmask));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
605 MODCOMMAND *m = Patterns[npat];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
606 UINT i = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
607 const BYTE *p = lpStream+patpos[npat]+8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
608 UINT nrow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
609 while (nrow<rows)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
610 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
611 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
612 BYTE b = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
613 if (!b)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
614 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
615 nrow++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
616 m+=m_nChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
617 continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
618 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
619 UINT ch = b & 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
620 if (ch) ch = (ch - 1) & 0x3F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
621 if (b & 0x80)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
622 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
623 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
624 chnmask[ch] = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
625 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
626 if ((chnmask[ch] & 0x10) && (ch < m_nChannels))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
627 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
628 m[ch].note = lastvalue[ch].note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
629 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
630 if ((chnmask[ch] & 0x20) && (ch < m_nChannels))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
631 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
632 m[ch].instr = lastvalue[ch].instr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
633 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
634 if ((chnmask[ch] & 0x40) && (ch < m_nChannels))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
635 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
636 m[ch].volcmd = lastvalue[ch].volcmd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
637 m[ch].vol = lastvalue[ch].vol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
638 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
639 if ((chnmask[ch] & 0x80) && (ch < m_nChannels))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
640 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
641 m[ch].command = lastvalue[ch].command;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
642 m[ch].param = lastvalue[ch].param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
643 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
644 if (chnmask[ch] & 1) // Note
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
645 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
646 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
647 UINT note = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
648 if (ch < m_nChannels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
649 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
650 if (note < 0x80) note++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
651 m[ch].note = note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
652 lastvalue[ch].note = note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
653 channels_used[ch] = TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
654 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
655 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
656 if (chnmask[ch] & 2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
657 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
658 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
659 UINT instr = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
660 if (ch < m_nChannels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
661 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
662 m[ch].instr = instr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
663 lastvalue[ch].instr = instr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
664 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
665 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
666 if (chnmask[ch] & 4)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
667 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
668 if (i >= len) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
669 UINT vol = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
670 if (ch < m_nChannels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
671 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
672 // 0-64: Set Volume
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
673 if (vol <= 64) { m[ch].volcmd = VOLCMD_VOLUME; m[ch].vol = vol; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
674 // 128-192: Set Panning
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
675 if ((vol >= 128) && (vol <= 192)) { m[ch].volcmd = VOLCMD_PANNING; m[ch].vol = vol - 128; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
676 // 65-74: Fine Volume Up
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
677 if (vol < 75) { m[ch].volcmd = VOLCMD_FINEVOLUP; m[ch].vol = vol - 65; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
678 // 75-84: Fine Volume Down
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
679 if (vol < 85) { m[ch].volcmd = VOLCMD_FINEVOLDOWN; m[ch].vol = vol - 75; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
680 // 85-94: Volume Slide Up
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
681 if (vol < 95) { m[ch].volcmd = VOLCMD_VOLSLIDEUP; m[ch].vol = vol - 85; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
682 // 95-104: Volume Slide Down
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
683 if (vol < 105) { m[ch].volcmd = VOLCMD_VOLSLIDEDOWN; m[ch].vol = vol - 95; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
684 // 105-114: Pitch Slide Up
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
685 if (vol < 115) { m[ch].volcmd = VOLCMD_PORTADOWN; m[ch].vol = vol - 105; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
686 // 115-124: Pitch Slide Down
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
687 if (vol < 125) { m[ch].volcmd = VOLCMD_PORTAUP; m[ch].vol = vol - 115; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
688 // 193-202: Portamento To
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
689 if ((vol >= 193) && (vol <= 202)) { m[ch].volcmd = VOLCMD_TONEPORTAMENTO; m[ch].vol = vol - 193; } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
690 // 203-212: Vibrato
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
691 if ((vol >= 203) && (vol <= 212)) { m[ch].volcmd = VOLCMD_VIBRATO; m[ch].vol = vol - 203; }
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
692 lastvalue[ch].volcmd = m[ch].volcmd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
693 lastvalue[ch].vol = m[ch].vol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
694 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
695 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
696 // Reading command/param
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
697 if (chnmask[ch] & 8)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
698 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
699 if (i > len - 2) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
700 UINT cmd = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
701 UINT param = p[i++];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
702 if (ch < m_nChannels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
703 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
704 if (cmd)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
705 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
706 m[ch].command = cmd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
707 m[ch].param = param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
708 S3MConvert(&m[ch], TRUE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
709 lastvalue[ch].command = m[ch].command;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
710 lastvalue[ch].param = m[ch].param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
711 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
712 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
713 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
714 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
715 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
716 for (UINT ncu=0; ncu<MAX_BASECHANNELS; ncu++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
717 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
718 if (ncu>=m_nChannels)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
719 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
720 ChnSettings[ncu].nVolume = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
721 ChnSettings[ncu].dwFlags &= ~CHN_MUTE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
722 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
723 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
724 m_nMinPeriod = 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
725 m_nMaxPeriod = 0xF000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
726 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
727 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
728
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
729
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
730 #ifndef MODPLUG_NO_FILESAVE
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
731 //#define SAVEITTIMESTAMP
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
732
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
733 #ifdef MSC_VER
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
734 #pragma warning(disable:4100)
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
735 #endif
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
736
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
737 #if 0
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
738 BOOL CSoundFile::SaveIT(LPCSTR lpszFileName, UINT nPacking)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
739 //---------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
740 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
741 DWORD dwPatNamLen, dwChnNamLen;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
742 ITFILEHEADER header;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
743 ITINSTRUMENT iti;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
744 ITSAMPLESTRUCT itss;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
745 BYTE smpcount[MAX_SAMPLES];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
746 DWORD inspos[MAX_INSTRUMENTS];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
747 DWORD patpos[MAX_PATTERNS];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
748 DWORD smppos[MAX_SAMPLES];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
749 DWORD dwPos = 0, dwHdrPos = 0, dwExtra = 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
750 WORD patinfo[4];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
751 BYTE chnmask[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
752 BYTE buf[512];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
753 MODCOMMAND lastvalue[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
754 FILE *f;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
755
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
756
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
757 if ((!lpszFileName) || ((f = fopen(lpszFileName, "wb")) == NULL)) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
758 memset(inspos, 0, sizeof(inspos));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
759 memset(patpos, 0, sizeof(patpos));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
760 memset(smppos, 0, sizeof(smppos));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
761 // Writing Header
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
762 memset(&header, 0, sizeof(header));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
763 dwPatNamLen = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
764 dwChnNamLen = 0;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
765 header.id = 0x4D504D49;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
766 lstrcpyn(header.songname, m_szNames[0], 27);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
767 header.hilight_minor = m_rowHighlightMinor;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
768 header.hilight_major = m_rowHighlightMajor;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
769 header.ordnum = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
770 while ((header.ordnum < MAX_ORDERS) && (Order[header.ordnum] < 0xFF)) header.ordnum++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
771 if (header.ordnum < MAX_ORDERS) Order[header.ordnum++] = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
772 header.insnum = m_nInstruments;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
773 header.smpnum = m_nSamples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
774 header.patnum = MAX_PATTERNS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
775 while ((header.patnum > 0) && (!Patterns[header.patnum-1])) header.patnum--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
776 header.cwtv = 0x217;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
777 header.cmwt = 0x200;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
778 header.flags = 0x0001;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
779 header.special = 0x0006;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
780 if (m_dwSongFlags & SONG_INSTRUMENTMODE) header.flags |= 0x04;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
781 if (m_dwSongFlags & SONG_LINEARSLIDES) header.flags |= 0x08;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
782 if (m_dwSongFlags & SONG_ITOLDEFFECTS) header.flags |= 0x10;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
783 if (m_dwSongFlags & SONG_ITCOMPATMODE) header.flags |= 0x20;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
784 if (m_dwSongFlags & SONG_EXFILTERRANGE) header.flags |= 0x1000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
785 header.globalvol = m_nDefaultGlobalVolume >> 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
786 header.mv = m_nSongPreAmp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
787 header.speed = m_nDefaultSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
788 header.tempo = m_nDefaultTempo;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
789 header.sep = m_nStereoSeparation;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
790 dwHdrPos = sizeof(header) + header.ordnum;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
791 // Channel Pan and Volume
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
792 memset(header.chnpan, 0xFF, 64);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
793 memset(header.chnvol, 64, 64);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
794 for (UINT ich=0; ich<m_nChannels; ich++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
795 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
796 header.chnpan[ich] = ChnSettings[ich].nPan >> 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
797 if (ChnSettings[ich].dwFlags & CHN_SURROUND) header.chnpan[ich] = 100;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
798 header.chnvol[ich] = ChnSettings[ich].nVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
799 if (ChnSettings[ich].dwFlags & CHN_MUTE) header.chnpan[ich] |= 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
800 if (ChnSettings[ich].szName[0])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
801 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
802 dwChnNamLen = (ich+1) * MAX_CHANNELNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
803 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
804 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
805 if (dwChnNamLen) dwExtra += dwChnNamLen + 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
806 #ifdef SAVEITTIMESTAMP
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
807 dwExtra += 8; // Time Stamp
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
808 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
809 if (m_dwSongFlags & SONG_EMBEDMIDICFG)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
810 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
811 header.flags |= 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
812 header.special |= 0x08;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
813 dwExtra += sizeof(MODMIDICFG);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
814 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
815 // Pattern Names
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
816 if ((m_nPatternNames) && (m_lpszPatternNames))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
817 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
818 dwPatNamLen = m_nPatternNames * MAX_PATTERNNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
819 while ((dwPatNamLen >= MAX_PATTERNNAME) && (!m_lpszPatternNames[dwPatNamLen-MAX_PATTERNNAME])) dwPatNamLen -= MAX_PATTERNNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
820 if (dwPatNamLen < MAX_PATTERNNAME) dwPatNamLen = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
821 if (dwPatNamLen) dwExtra += dwPatNamLen + 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
822 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
823 // Mix Plugins
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
824 dwExtra += SaveMixPlugins(NULL, TRUE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
825 // Comments
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
826 if (m_lpszSongComments)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
827 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
828 header.special |= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
829 header.msglength = strlen(m_lpszSongComments)+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
830 header.msgoffset = dwHdrPos + dwExtra + header.insnum*4 + header.patnum*4 + header.smpnum*4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
831 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
832 // Write file header
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
833 fwrite(&header, 1, sizeof(header), f);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
834 fwrite(Order, 1, header.ordnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
835 if (header.insnum) fwrite(inspos, 4, header.insnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
836 if (header.smpnum) fwrite(smppos, 4, header.smpnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
837 if (header.patnum) fwrite(patpos, 4, header.patnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
838 // Writing editor history information
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
839 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
840 #ifdef SAVEITTIMESTAMP
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
841 SYSTEMTIME systime;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
842 FILETIME filetime;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
843 WORD timestamp[4];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
844 WORD nInfoEx = 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
845 memset(timestamp, 0, sizeof(timestamp));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
846 fwrite(&nInfoEx, 1, 2, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
847 GetSystemTime(&systime);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
848 SystemTimeToFileTime(&systime, &filetime);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
849 FileTimeToDosDateTime(&filetime, &timestamp[0], &timestamp[1]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
850 fwrite(timestamp, 1, 8, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
851 #else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
852 WORD nInfoEx = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
853 fwrite(&nInfoEx, 1, 2, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
854 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
855 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
856 // Writing midi cfg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
857 if (header.flags & 0x80)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
858 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
859 fwrite(&m_MidiCfg, 1, sizeof(MODMIDICFG), f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
860 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
861 // Writing pattern names
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
862 if (dwPatNamLen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
863 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
864 DWORD d = 0x4d414e50;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
865 fwrite(&d, 1, 4, f);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
866 fwrite(&dwPatNamLen, 1, 4, f);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
867 fwrite(m_lpszPatternNames, 1, dwPatNamLen, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
868 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
869 // Writing channel Names
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
870 if (dwChnNamLen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
871 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
872 DWORD d = 0x4d414e43;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
873 fwrite(&d, 1, 4, f);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
874 fwrite(&dwChnNamLen, 1, 4, f);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
875 UINT nChnNames = dwChnNamLen / MAX_CHANNELNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
876 for (UINT inam=0; inam<nChnNames; inam++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
877 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
878 fwrite(ChnSettings[inam].szName, 1, MAX_CHANNELNAME, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
879 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
880 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
881 // Writing mix plugins info
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
882 SaveMixPlugins(f, FALSE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
883 // Writing song message
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
884 dwPos = dwHdrPos + dwExtra + (header.insnum + header.smpnum + header.patnum) * 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
885 if (header.special & 1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
886 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
887 dwPos += strlen(m_lpszSongComments) + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
888 fwrite(m_lpszSongComments, 1, strlen(m_lpszSongComments)+1, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
889 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
890 // Writing instruments
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
891 for (UINT nins=1; nins<=header.insnum; nins++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
892 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
893 memset(&iti, 0, sizeof(iti));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
894 iti.id = 0x49504D49; // "IMPI"
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
895 iti.trkvers = 0x211;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
896 if (Headers[nins])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
897 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
898 INSTRUMENTHEADER *penv = Headers[nins];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
899 memset(smpcount, 0, sizeof(smpcount));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
900 memcpy(iti.filename, penv->filename, 12);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
901 memcpy(iti.name, penv->name, 26);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
902 iti.mbank = penv->wMidiBank;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
903 iti.mpr = penv->nMidiProgram;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
904 iti.mch = penv->nMidiChannel;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
905 iti.nna = penv->nNNA;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
906 iti.dct = penv->nDCT;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
907 iti.dca = penv->nDNA;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
908 iti.fadeout = penv->nFadeOut >> 5;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
909 iti.pps = penv->nPPS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
910 iti.ppc = penv->nPPC;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
911 iti.gbv = (BYTE)penv->nGlobalVol;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
912 iti.dfp = (BYTE)penv->nPan >> 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
913 if (!(penv->dwFlags & ENV_SETPANNING)) iti.dfp |= 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
914 iti.rv = penv->nVolSwing;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
915 iti.rp = penv->nPanSwing;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
916 iti.ifc = penv->nIFC;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
917 iti.ifr = penv->nIFR;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
918 iti.nos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
919 for (UINT i=0; i<120; i++) if (penv->Keyboard[i] < MAX_SAMPLES)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
920 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
921 UINT smp = penv->Keyboard[i];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
922 if ((smp) && (!smpcount[smp]))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
923 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
924 smpcount[smp] = 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
925 iti.nos++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
926 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
927 iti.keyboard[i*2] = penv->NoteMap[i] - 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
928 iti.keyboard[i*2+1] = smp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
929 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
930 // Writing Volume envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
931 if (penv->dwFlags & ENV_VOLUME) iti.volenv.flags |= 0x01;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
932 if (penv->dwFlags & ENV_VOLLOOP) iti.volenv.flags |= 0x02;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
933 if (penv->dwFlags & ENV_VOLSUSTAIN) iti.volenv.flags |= 0x04;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
934 if (penv->dwFlags & ENV_VOLCARRY) iti.volenv.flags |= 0x08;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
935 iti.volenv.num = (BYTE)penv->VolEnv.nNodes;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
936 iti.volenv.lpb = (BYTE)penv->VolEnv.nLoopStart;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
937 iti.volenv.lpe = (BYTE)penv->VolEnv.nLoopEnd;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
938 iti.volenv.slb = penv->VolEnv.nSustainStart;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
939 iti.volenv.sle = penv->VolEnv.nSustainEnd;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
940 // Writing Panning envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
941 if (penv->dwFlags & ENV_PANNING) iti.panenv.flags |= 0x01;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
942 if (penv->dwFlags & ENV_PANLOOP) iti.panenv.flags |= 0x02;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
943 if (penv->dwFlags & ENV_PANSUSTAIN) iti.panenv.flags |= 0x04;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
944 if (penv->dwFlags & ENV_PANCARRY) iti.panenv.flags |= 0x08;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
945 iti.panenv.num = (BYTE)penv->PanEnv.nNodes;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
946 iti.panenv.lpb = (BYTE)penv->PanEnv.nLoopStart;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
947 iti.panenv.lpe = (BYTE)penv->PanEnv.nLoopEnd;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
948 iti.panenv.slb = penv->PanEnv.nSustainStart;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
949 iti.panenv.sle = penv->PanEnv.nSustainEnd;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
950 // Writing Pitch Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
951 if (penv->dwFlags & ENV_PITCH) iti.pitchenv.flags |= 0x01;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
952 if (penv->dwFlags & ENV_PITCHLOOP) iti.pitchenv.flags |= 0x02;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
953 if (penv->dwFlags & ENV_PITCHSUSTAIN) iti.pitchenv.flags |= 0x04;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
954 if (penv->dwFlags & ENV_PITCHCARRY) iti.pitchenv.flags |= 0x08;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
955 if (penv->dwFlags & ENV_FILTER) iti.pitchenv.flags |= 0x80;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
956 iti.pitchenv.num = (BYTE)penv->PitchEnv.nNodes;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
957 iti.pitchenv.lpb = (BYTE)penv->PitchEnv.nLoopStart;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
958 iti.pitchenv.lpe = (BYTE)penv->PitchEnv.nLoopEnd;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
959 iti.pitchenv.slb = (BYTE)penv->PitchEnv.nSustainStart;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
960 iti.pitchenv.sle = (BYTE)penv->PitchEnv.nSustainEnd;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
961 // Writing Envelopes data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
962 for (UINT ev=0; ev<25; ev++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
963 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
964 iti.volenv.data[ev*3] = penv->VolEnv.Values[ev];
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
965 iti.volenv.data[ev*3+1] = penv->VolEnv.Ticks[ev] & 0xFF;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
966 iti.volenv.data[ev*3+2] = penv->VolEnv.Ticks[ev] >> 8;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
967 iti.panenv.data[ev*3] = penv->PanEnv.Values[ev] - 32;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
968 iti.panenv.data[ev*3+1] = penv->PanEnv.Ticks[ev] & 0xFF;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
969 iti.panenv.data[ev*3+2] = penv->PanEnv.Ticks[ev] >> 8;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
970 iti.pitchenv.data[ev*3] = penv->PitchEnv.Values[ev] - 32;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
971 iti.pitchenv.data[ev*3+1] = penv->PitchEnv.Ticks[ev] & 0xFF;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
972 iti.pitchenv.data[ev*3+2] = penv->PitchEnv.Ticks[ev] >> 8;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
973 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
974 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
975 // Save Empty Instrument
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
976 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
977 for (UINT i=0; i<120; i++) iti.keyboard[i*2] = i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
978 iti.ppc = 5*12;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
979 iti.gbv = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
980 iti.dfp = 0x20;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
981 iti.ifc = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
982 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
983 if (!iti.nos) iti.trkvers = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
984 // Writing instrument
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
985 inspos[nins-1] = dwPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
986 dwPos += sizeof(ITINSTRUMENT);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
987 fwrite(&iti, 1, sizeof(ITINSTRUMENT), f);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
988 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
989 // Writing sample headers
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
990 memset(&itss, 0, sizeof(itss));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
991 for (UINT hsmp=0; hsmp<header.smpnum; hsmp++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
992 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
993 smppos[hsmp] = dwPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
994 dwPos += sizeof(ITSAMPLESTRUCT);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
995 fwrite(&itss, 1, sizeof(ITSAMPLESTRUCT), f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
996 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
997 // Writing Patterns
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
998 for (UINT npat=0; npat<header.patnum; npat++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
999 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1000 DWORD dwPatPos = dwPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1001 UINT len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1002 if (!Patterns[npat]) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1003 patpos[npat] = dwPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1004 patinfo[0] = 0;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1005 patinfo[1] = PatternSize[npat];
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1006 patinfo[2] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1007 patinfo[3] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1008 // Check for empty pattern
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1009 if (PatternSize[npat] == 64)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1010 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1011 MODCOMMAND *pzc = Patterns[npat];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1012 UINT nz = PatternSize[npat] * m_nChannels;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1013 UINT iz;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1014 for (iz=0; iz<nz; iz++)
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1015 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1016 if ((pzc[iz].note) || (pzc[iz].instr)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1017 || (pzc[iz].volcmd) || (pzc[iz].command)) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1018 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1019 if (iz == nz)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1020 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1021 patpos[npat] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1022 continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1023 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1024 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1025 fwrite(patinfo, 8, 1, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1026 dwPos += 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1027 memset(chnmask, 0xFF, sizeof(chnmask));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1028 memset(lastvalue, 0, sizeof(lastvalue));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1029 MODCOMMAND *m = Patterns[npat];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1030 for (UINT row=0; row<PatternSize[npat]; row++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1031 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1032 len = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1033 for (UINT ch=0; ch<m_nChannels; ch++, m++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1034 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1035 BYTE b = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1036 UINT command = m->command;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1037 UINT param = m->param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1038 UINT vol = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1039 UINT note = m->note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1040 if (note) b |= 1;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1041 if ((note) && (note < 0x80)) note--;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1042 if (m->instr) b |= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1043 if (m->volcmd)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1044 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1045 UINT volcmd = m->volcmd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1046 switch(volcmd)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1047 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1048 case VOLCMD_VOLUME: vol = m->vol; if (vol > 64) vol = 64; break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1049 case VOLCMD_PANNING: vol = m->vol + 128; if (vol > 192) vol = 192; break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1050 case VOLCMD_VOLSLIDEUP: vol = 85 + ConvertVolParam(m->vol); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1051 case VOLCMD_VOLSLIDEDOWN: vol = 95 + ConvertVolParam(m->vol); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1052 case VOLCMD_FINEVOLUP: vol = 65 + ConvertVolParam(m->vol); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1053 case VOLCMD_FINEVOLDOWN: vol = 75 + ConvertVolParam(m->vol); break;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1054 case VOLCMD_VIBRATOSPEED: vol = 203; break;
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1055 case VOLCMD_VIBRATO: vol = 203 + ConvertVolParam(m->vol); break;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1056 case VOLCMD_TONEPORTAMENTO: vol = 193 + ConvertVolParam(m->vol); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1057 case VOLCMD_PORTADOWN: vol = 105 + ConvertVolParam(m->vol); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1058 case VOLCMD_PORTAUP: vol = 115 + ConvertVolParam(m->vol); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1059 default: vol = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1060 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1061 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1062 if (vol != 0xFF) b |= 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1063 if (command)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1064 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1065 S3MSaveConvert(&command, &param, TRUE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1066 if (command) b |= 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1067 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1068 // Packing information
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1069 if (b)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1070 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1071 // Same note ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1072 if (b & 1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1073 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1074 if ((note == lastvalue[ch].note) && (lastvalue[ch].volcmd & 1))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1075 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1076 b &= ~1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1077 b |= 0x10;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1078 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1079 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1080 lastvalue[ch].note = note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1081 lastvalue[ch].volcmd |= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1082 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1083 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1084 // Same instrument ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1085 if (b & 2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1086 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1087 if ((m->instr == lastvalue[ch].instr) && (lastvalue[ch].volcmd & 2))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1088 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1089 b &= ~2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1090 b |= 0x20;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1091 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1092 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1093 lastvalue[ch].instr = m->instr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1094 lastvalue[ch].volcmd |= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1095 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1096 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1097 // Same volume column byte ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1098 if (b & 4)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1099 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1100 if ((vol == lastvalue[ch].vol) && (lastvalue[ch].volcmd & 4))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1101 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1102 b &= ~4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1103 b |= 0x40;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1104 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1105 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1106 lastvalue[ch].vol = vol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1107 lastvalue[ch].volcmd |= 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1108 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1109 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1110 // Same command / param ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1111 if (b & 8)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1112 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1113 if ((command == lastvalue[ch].command) && (param == lastvalue[ch].param) && (lastvalue[ch].volcmd & 8))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1114 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1115 b &= ~8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1116 b |= 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1117 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1118 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1119 lastvalue[ch].command = command;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1120 lastvalue[ch].param = param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1121 lastvalue[ch].volcmd |= 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1122 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1123 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1124 if (b != chnmask[ch])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1125 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1126 chnmask[ch] = b;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1127 buf[len++] = (ch+1) | 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1128 buf[len++] = b;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1129 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1130 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1131 buf[len++] = ch+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1132 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1133 if (b & 1) buf[len++] = note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1134 if (b & 2) buf[len++] = m->instr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1135 if (b & 4) buf[len++] = vol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1136 if (b & 8)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1137 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1138 buf[len++] = command;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1139 buf[len++] = param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1140 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1141 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1142 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1143 buf[len++] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1144 dwPos += len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1145 patinfo[0] += len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1146 fwrite(buf, 1, len, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1147 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1148 fseek(f, dwPatPos, SEEK_SET);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1149 fwrite(patinfo, 8, 1, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1150 fseek(f, dwPos, SEEK_SET);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1151 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1152 // Writing Sample Data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1153 for (UINT nsmp=1; nsmp<=header.smpnum; nsmp++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1154 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1155 MODINSTRUMENT *psmp = &Ins[nsmp];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1156 memset(&itss, 0, sizeof(itss));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1157 memcpy(itss.filename, psmp->name, 12);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1158 memcpy(itss.name, m_szNames[nsmp], 26);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1159 itss.id = 0x53504D49;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1160 itss.gvl = (BYTE)psmp->nGlobalVol;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1161 if (m_dwSongFlags & SONG_INSTRUMENTMODE)
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1162 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1163 for (UINT iu=1; iu<=m_nInstruments; iu++) if (Headers[iu])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1164 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1165 INSTRUMENTHEADER *penv = Headers[iu];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1166 for (UINT ju=0; ju<128; ju++) if (penv->Keyboard[ju] == nsmp)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1167 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1168 itss.flags = 0x01;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1169 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1170 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1171 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1172 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1173 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1174 itss.flags = 0x01;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1175 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1176 if (psmp->uFlags & CHN_LOOP) itss.flags |= 0x10;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1177 if (psmp->uFlags & CHN_SUSTAINLOOP) itss.flags |= 0x20;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1178 if (psmp->uFlags & CHN_PINGPONGLOOP) itss.flags |= 0x40;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1179 if (psmp->uFlags & CHN_PINGPONGSUSTAIN) itss.flags |= 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1180 itss.C5Speed = psmp->nC4Speed;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1181 if (!itss.C5Speed) itss.C5Speed = 8363;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1182 itss.length = psmp->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1183 itss.loopbegin = psmp->nLoopStart;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1184 itss.loopend = psmp->nLoopEnd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1185 itss.susloopbegin = psmp->nSustainStart;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1186 itss.susloopend = psmp->nSustainEnd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1187 itss.vol = psmp->nVolume >> 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1188 itss.dfp = psmp->nPan >> 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1189 itss.vit = autovibxm2it[psmp->nVibType & 7];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1190 itss.vis = psmp->nVibRate;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1191 itss.vid = psmp->nVibDepth;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1192 itss.vir = psmp->nVibSweep;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1193 if (psmp->uFlags & CHN_PANNING) itss.dfp |= 0x80;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1194 if ((psmp->pSample) && (psmp->nLength)) itss.cvt = 0x01;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1195 UINT flags = RS_PCM8S;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1196 #ifndef NO_PACKING
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1197 if (nPacking)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1198 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1199 if ((!(psmp->uFlags & (CHN_16BIT|CHN_STEREO)))
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1200 && (CanPackSample(psmp->pSample, psmp->nLength, nPacking)))
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1201 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1202 flags = RS_ADPCM4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1203 itss.cvt = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1204 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1205 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1206 #endif // NO_PACKING
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1207 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1208 if (psmp->uFlags & CHN_STEREO)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1209 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1210 flags = RS_STPCM8S;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1211 itss.flags |= 0x04;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1212 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1213 if (psmp->uFlags & CHN_16BIT)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1214 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1215 itss.flags |= 0x02;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1216 flags = (psmp->uFlags & CHN_STEREO) ? RS_STPCM16S : RS_PCM16S;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1217 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1218 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1219 itss.samplepointer = dwPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1220 fseek(f, smppos[nsmp-1], SEEK_SET);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1221 fwrite(&itss, 1, sizeof(ITSAMPLESTRUCT), f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1222 fseek(f, dwPos, SEEK_SET);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1223 if ((psmp->pSample) && (psmp->nLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1224 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1225 dwPos += WriteSample(f, psmp, flags);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1226 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1227 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1228 // Updating offsets
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1229 fseek(f, dwHdrPos, SEEK_SET);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1230 if (header.insnum) fwrite(inspos, 4, header.insnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1231 if (header.smpnum) fwrite(smppos, 4, header.smpnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1232 if (header.patnum) fwrite(patpos, 4, header.patnum, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1233 fclose(f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1234 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1235 }
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1236 #endif
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1237
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1238 #ifdef MSC_VER
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1239 #pragma warning(default:4100)
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1240 #endif
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1241
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1242 #endif // MODPLUG_NO_FILESAVE
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1243
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1244 //////////////////////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1245 // IT 2.14 compression
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1246
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1247 DWORD ITReadBits(DWORD &bitbuf, UINT &bitnum, LPBYTE &ibuf, CHAR n)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1248 //-----------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1249 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1250 DWORD retval = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1251 UINT i = n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1252
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1253 if (n > 0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1254 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1255 do
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1256 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1257 if (!bitnum)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1258 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1259 bitbuf = *ibuf++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1260 bitnum = 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1261 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1262 retval >>= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1263 retval |= bitbuf << 31;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1264 bitbuf >>= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1265 bitnum--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1266 i--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1267 } while (i);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1268 i = n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1269 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1270 return (retval >> (32-i));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1271 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1272
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1273 #define IT215_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1274 void ITUnpack8Bit(signed char *pSample, DWORD dwLen, LPBYTE lpMemFile, DWORD dwMemLength, BOOL b215)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1275 //-------------------------------------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1276 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1277 signed char *pDst = pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1278 LPBYTE pSrc = lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1279 DWORD wHdr = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1280 DWORD wCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1281 DWORD bitbuf = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1282 UINT bitnum = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1283 BYTE bLeft = 0, bTemp = 0, bTemp2 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1284
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1285 while (dwLen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1286 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1287 if (!wCount)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1288 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1289 wCount = 0x8000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1290 wHdr = bswapLE16(*((LPWORD)pSrc));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1291 pSrc += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1292 bLeft = 9;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1293 bTemp = bTemp2 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1294 bitbuf = bitnum = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1295 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1296 DWORD d = wCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1297 if (d > dwLen) d = dwLen;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1298 // Unpacking
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1299 DWORD dwPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1300 do
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1301 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1302 WORD wBits = (WORD)ITReadBits(bitbuf, bitnum, pSrc, bLeft);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1303 if (bLeft < 7)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1304 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1305 DWORD i = 1 << (bLeft-1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1306 DWORD j = wBits & 0xFFFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1307 if (i != j) goto UnpackByte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1308 wBits = (WORD)(ITReadBits(bitbuf, bitnum, pSrc, 3) + 1) & 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1309 bLeft = ((BYTE)wBits < bLeft) ? (BYTE)wBits : (BYTE)((wBits+1) & 0xFF);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1310 goto Next;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1311 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1312 if (bLeft < 9)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1313 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1314 WORD i = (0xFF >> (9 - bLeft)) + 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1315 WORD j = i - 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1316 if ((wBits <= j) || (wBits > i)) goto UnpackByte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1317 wBits -= j;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1318 bLeft = ((BYTE)(wBits & 0xFF) < bLeft) ? (BYTE)(wBits & 0xFF) : (BYTE)((wBits+1) & 0xFF);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1319 goto Next;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1320 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1321 if (bLeft >= 10) goto SkipByte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1322 if (wBits >= 256)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1323 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1324 bLeft = (BYTE)(wBits + 1) & 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1325 goto Next;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1326 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1327 UnpackByte:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1328 if (bLeft < 8)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1329 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1330 BYTE shift = 8 - bLeft;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1331 signed char c = (signed char)(wBits << shift);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1332 c >>= shift;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1333 wBits = (WORD)c;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1334 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1335 wBits += bTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1336 bTemp = (BYTE)wBits;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1337 bTemp2 += bTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1338 #ifdef IT215_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1339 pDst[dwPos] = (b215) ? bTemp2 : bTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1340 #else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1341 pDst[dwPos] = bTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1342 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1343 SkipByte:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1344 dwPos++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1345 Next:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1346 if (pSrc >= lpMemFile+dwMemLength+1) return;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1347 } while (dwPos < d);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1348 // Move On
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1349 wCount -= d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1350 dwLen -= d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1351 pDst += d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1352 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1353 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1354
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1355
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1356 void ITUnpack16Bit(signed char *pSample, DWORD dwLen, LPBYTE lpMemFile, DWORD dwMemLength, BOOL b215)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1357 //--------------------------------------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1358 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1359 signed short *pDst = (signed short *)pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1360 LPBYTE pSrc = lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1361 DWORD wHdr = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1362 DWORD wCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1363 DWORD bitbuf = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1364 UINT bitnum = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1365 BYTE bLeft = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1366 signed short wTemp = 0, wTemp2 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1367
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1368 while (dwLen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1369 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1370 if (!wCount)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1371 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1372 wCount = 0x4000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1373 wHdr = bswapLE16(*((LPWORD)pSrc));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1374 pSrc += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1375 bLeft = 17;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1376 wTemp = wTemp2 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1377 bitbuf = bitnum = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1378 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1379 DWORD d = wCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1380 if (d > dwLen) d = dwLen;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1381 // Unpacking
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1382 DWORD dwPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1383 do
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1384 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1385 DWORD dwBits = ITReadBits(bitbuf, bitnum, pSrc, bLeft);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1386 if (bLeft < 7)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1387 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1388 DWORD i = 1 << (bLeft-1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1389 DWORD j = dwBits;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1390 if (i != j) goto UnpackByte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1391 dwBits = ITReadBits(bitbuf, bitnum, pSrc, 4) + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1392 bLeft = ((BYTE)(dwBits & 0xFF) < bLeft) ? (BYTE)(dwBits & 0xFF) : (BYTE)((dwBits+1) & 0xFF);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1393 goto Next;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1394 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1395 if (bLeft < 17)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1396 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1397 DWORD i = (0xFFFF >> (17 - bLeft)) + 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1398 DWORD j = (i - 16) & 0xFFFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1399 if ((dwBits <= j) || (dwBits > (i & 0xFFFF))) goto UnpackByte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1400 dwBits -= j;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1401 bLeft = ((BYTE)(dwBits & 0xFF) < bLeft) ? (BYTE)(dwBits & 0xFF) : (BYTE)((dwBits+1) & 0xFF);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1402 goto Next;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1403 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1404 if (bLeft >= 18) goto SkipByte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1405 if (dwBits >= 0x10000)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1406 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1407 bLeft = (BYTE)(dwBits + 1) & 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1408 goto Next;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1409 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1410 UnpackByte:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1411 if (bLeft < 16)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1412 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1413 BYTE shift = 16 - bLeft;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1414 signed short c = (signed short)(dwBits << shift);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1415 c >>= shift;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1416 dwBits = (DWORD)c;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1417 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1418 dwBits += wTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1419 wTemp = (signed short)dwBits;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1420 wTemp2 += wTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1421 #ifdef IT215_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1422 pDst[dwPos] = (b215) ? wTemp2 : wTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1423 #else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1424 pDst[dwPos] = wTemp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1425 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1426 SkipByte:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1427 dwPos++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1428 Next:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1429 if (pSrc >= lpMemFile+dwMemLength+1) return;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1430 } while (dwPos < d);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1431 // Move On
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1432 wCount -= d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1433 dwLen -= d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1434 pDst += d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1435 if (pSrc >= lpMemFile+dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1436 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1437 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1438
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1439
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1440 UINT CSoundFile::SaveMixPlugins(FILE *f, BOOL bUpdate)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1441 //----------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1442 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1443 DWORD chinfo[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1444 CHAR s[32];
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1445 DWORD nPluginSize;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1446 UINT nTotalSize = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1447 UINT nChInfo = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1448
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1449 for (UINT i=0; i<MAX_MIXPLUGINS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1450 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1451 PSNDMIXPLUGIN p = &m_MixPlugins[i];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1452 if ((p->Info.dwPluginId1) || (p->Info.dwPluginId2))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1453 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1454 nPluginSize = sizeof(SNDMIXPLUGININFO)+4; // plugininfo+4 (datalen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1455 if ((p->pMixPlugin) && (bUpdate))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1456 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1457 p->pMixPlugin->SaveAllParameters();
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1458 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1459 if (p->pPluginData)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1460 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1461 nPluginSize += p->nPluginDataSize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1462 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1463 if (f)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1464 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1465 s[0] = 'F';
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1466 s[1] = 'X';
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1467 s[2] = '0' + (i/10);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1468 s[3] = '0' + (i%10);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1469 fwrite(s, 1, 4, f);
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1470 fwrite(&nPluginSize, 1, 4, f);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1471 fwrite(&p->Info, 1, sizeof(SNDMIXPLUGININFO), f);
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1472 fwrite(&m_MixPlugins[i].nPluginDataSize, 1, 4, f);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1473 if (m_MixPlugins[i].pPluginData)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1474 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1475 fwrite(m_MixPlugins[i].pPluginData, 1, m_MixPlugins[i].nPluginDataSize, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1476 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1477 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1478 nTotalSize += nPluginSize + 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1479 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1480 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1481 for (UINT j=0; j<m_nChannels; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1482 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1483 if (j < 64)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1484 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1485 if ((chinfo[j] = ChnSettings[j].nMixPlugin) != 0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1486 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1487 nChInfo = j+1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1488 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1489 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1490 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1491 if (nChInfo)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1492 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1493 if (f)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1494 {
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1495 nPluginSize = 0x58464843;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1496 fwrite(&nPluginSize, 1, 4, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1497 nPluginSize = nChInfo*4;
2216
3673c7ec4ea2 Sync with schism's modplug engine. Suggested by G¸«ärkan Seng¸«än.
William Pitcock <nenolod@atheme.org>
parents: 136
diff changeset
1498 fwrite(&nPluginSize, 1, 4, f);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1499 fwrite(chinfo, 1, nPluginSize, f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1500 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1501 nTotalSize += nChInfo*4 + 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1502 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1503 return nTotalSize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1504 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1505
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1506
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1507 UINT CSoundFile::LoadMixPlugins(const void *pData, UINT nLen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1508 //-----------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1509 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1510 const BYTE *p = (const BYTE *)pData;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1511 UINT nPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1512
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1513 while (nPos+8 < nLen)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1514 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1515 DWORD nPluginSize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1516 UINT nPlugin;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1517
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1518 nPluginSize = bswapLE32(*(DWORD *)(p+nPos+4));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1519 if (nPluginSize > nLen-nPos-8) break;;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1520 if ((bswapLE32(*(DWORD *)(p+nPos))) == 0x58464843)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1521 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1522 for (UINT ch=0; ch<64; ch++) if (ch*4 < nPluginSize)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1523 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1524 ChnSettings[ch].nMixPlugin = bswapLE32(*(DWORD *)(p+nPos+8+ch*4));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1525 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1526 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1527 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1528 if ((p[nPos] != 'F') || (p[nPos+1] != 'X')
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1529 || (p[nPos+2] < '0') || (p[nPos+3] < '0'))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1530 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1531 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1532 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1533 nPlugin = (p[nPos+2]-'0')*10 + (p[nPos+3]-'0');
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1534 if ((nPlugin < MAX_MIXPLUGINS) && (nPluginSize >= sizeof(SNDMIXPLUGININFO)+4))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1535 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1536 DWORD dwExtra = bswapLE32(*(DWORD *)(p+nPos+8+sizeof(SNDMIXPLUGININFO)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1537 m_MixPlugins[nPlugin].Info = *(const SNDMIXPLUGININFO *)(p+nPos+8);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1538 m_MixPlugins[nPlugin].Info.dwPluginId1 = bswapLE32(m_MixPlugins[nPlugin].Info.dwPluginId1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1539 m_MixPlugins[nPlugin].Info.dwPluginId2 = bswapLE32(m_MixPlugins[nPlugin].Info.dwPluginId2);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1540 m_MixPlugins[nPlugin].Info.dwInputRouting = bswapLE32(m_MixPlugins[nPlugin].Info.dwInputRouting);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1541 m_MixPlugins[nPlugin].Info.dwOutputRouting = bswapLE32(m_MixPlugins[nPlugin].Info.dwOutputRouting);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1542 for (UINT j=0; j<4; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1543 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1544 m_MixPlugins[nPlugin].Info.dwReserved[j] = bswapLE32(m_MixPlugins[nPlugin].Info.dwReserved[j]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1545 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1546 if ((dwExtra) && (dwExtra <= nPluginSize-sizeof(SNDMIXPLUGININFO)-4))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1547 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1548 m_MixPlugins[nPlugin].nPluginDataSize = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1549 m_MixPlugins[nPlugin].pPluginData = new signed char [dwExtra];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1550 if (m_MixPlugins[nPlugin].pPluginData)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1551 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1552 m_MixPlugins[nPlugin].nPluginDataSize = dwExtra;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1553 memcpy(m_MixPlugins[nPlugin].pPluginData, p+nPos+8+sizeof(SNDMIXPLUGININFO)+4, dwExtra);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1554 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1555 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1556 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1557 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1558 nPos += nPluginSize + 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1559 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1560 return nPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1561 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1562