annotate src/modplug/sndfile.cxx @ 2916:223822ba79f2

writing bonded device to the config file so it can be unbounded at start-up when the player doesn't stop normaly
author Paula Stanciu <paula.stanciu@gmail.com>
date Sat, 16 Aug 2008 21:46:08 +0300
parents 585f2fc4134e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1 /*
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
2 * This source code is public domain.
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
3 *
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
4 * Authors: Olivier Lapicque <olivierl@jps.net>,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
5 * Adam Goode <adam@evdebs.org> (endian and char fixes for PPC)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
6 */
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
7
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
8 #include <math.h> //for GCCFIX
161
4095ceb0440b [svn] - fix libmodplug references
nenolod
parents: 143
diff changeset
9 #include "stdafx.h"
4095ceb0440b [svn] - fix libmodplug references
nenolod
parents: 143
diff changeset
10 #include "sndfile.h"
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
11
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
12 #define MMCMP_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
13
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
14 #ifdef MMCMP_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
15 extern BOOL MMCMP_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
16 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
17
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
18
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
19 // External decompressors
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
20 extern void AMSUnpack(const char *psrc, UINT inputlen, char *pdest, UINT dmax, char packcharacter);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
21 extern WORD MDLReadBits(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
22 extern int DMFUnpack(LPBYTE psample, LPBYTE ibuf, LPBYTE ibufmax, UINT maxlen);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
23 extern 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
24 extern 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
25 extern 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
26
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
27
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
28 #define MAX_PACK_TABLES 3
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
31 // Compression table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
32 static signed char UnpackTable[MAX_PACK_TABLES][16] =
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
33 //--------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
34 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
35 // CPU-generated dynamic table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
36 {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
37 // u-Law table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
38 {0, 1, 2, 4, 8, 16, 32, 64,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
39 -1, -2, -4, -8, -16, -32, -48, -64},
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
40 // Linear table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
41 {0, 1, 2, 3, 5, 7, 12, 19,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
42 -1, -2, -3, -5, -7, -12, -19, -31}
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
43 };
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
44
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
45
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
46 //////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
47 // CSoundFile
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 CSoundFile::CSoundFile()
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
50 //----------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
51 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
52 m_nType = MOD_TYPE_NONE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
53 m_dwSongFlags = 0;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
54 m_nStereoSeparation = 128;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
55 m_nChannels = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
56 m_nMixChannels = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
57 m_nSamples = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
58 m_nInstruments = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
59 m_nPatternNames = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
60 m_lpszPatternNames = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
61 m_lpszSongComments = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
62 m_nFreqFactor = m_nTempoFactor = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
63 m_nMasterVolume = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
64 m_nMinPeriod = 0x20;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
65 m_nMaxPeriod = 0x7FFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
66 m_nRepeatCount = 0;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
67 m_rowHighlightMajor = 16;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
68 m_rowHighlightMinor = 4;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
69 memset(Chn, 0, sizeof(Chn));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
70 memset(ChnMix, 0, sizeof(ChnMix));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
71 memset(Ins, 0, sizeof(Ins));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
72 memset(ChnSettings, 0, sizeof(ChnSettings));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
73 memset(Headers, 0, sizeof(Headers));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
74 memset(Order, 0xFF, sizeof(Order));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
75 memset(Patterns, 0, sizeof(Patterns));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
76 memset(m_szNames, 0, sizeof(m_szNames));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
77 memset(m_MixPlugins, 0, sizeof(m_MixPlugins));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
78 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
79
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
80
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
81 CSoundFile::~CSoundFile()
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
82 //-----------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
83 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
84 Destroy();
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
85 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
86
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
87
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
88 BOOL CSoundFile::Create(LPCBYTE lpStream, DWORD dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
89 //----------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
90 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
91 int i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
92
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
93 // deja vu...
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
94 m_nType = MOD_TYPE_NONE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
95 m_dwSongFlags = 0;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
96 m_nStereoSeparation = 128;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
97 m_nChannels = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
98 m_nMixChannels = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
99 m_nSamples = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
100 m_nInstruments = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
101 m_nFreqFactor = m_nTempoFactor = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
102 m_nMasterVolume = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
103 m_nDefaultGlobalVolume = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
104 m_nGlobalVolume = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
105 m_nOldGlbVolSlide = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
106 m_nDefaultSpeed = 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
107 m_nDefaultTempo = 125;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
108 m_nPatternDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
109 m_nFrameDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
110 m_nNextRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
111 m_nRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
112 m_nPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
113 m_nCurrentPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
114 m_nNextPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
115 m_nRestartPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
116 m_nMinPeriod = 16;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
117 m_nMaxPeriod = 32767;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
118 m_nSongPreAmp = 0x30;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
119 m_nPatternNames = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
120 m_lpszPatternNames = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
121 m_lpszSongComments = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
122 memset(Ins, 0, sizeof(Ins));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
123 memset(ChnMix, 0, sizeof(ChnMix));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
124 memset(Chn, 0, sizeof(Chn));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
125 memset(Headers, 0, sizeof(Headers));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
126 memset(Order, 0xFF, sizeof(Order));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
127 memset(Patterns, 0, sizeof(Patterns));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
128 memset(m_szNames, 0, sizeof(m_szNames));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
129 memset(m_MixPlugins, 0, sizeof(m_MixPlugins));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
130 ResetMidiCfg();
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
131 for (UINT npt=0; npt<MAX_PATTERNS; npt++) {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
132 PatternSize[npt] = 64;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
133 PatternAllocSize[npt] = 64;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
134 }
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
135 for (UINT nch=0; nch<MAX_BASECHANNELS; nch++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
136 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
137 ChnSettings[nch].nPan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
138 ChnSettings[nch].nVolume = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
139 ChnSettings[nch].dwFlags = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
140 ChnSettings[nch].szName[0] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
141 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
142 if (lpStream)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
143 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
144 #ifdef MMCMP_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
145 BOOL bMMCmp = MMCMP_Unpack(&lpStream, &dwMemLength);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
146 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
147 if ((!ReadXM(lpStream, dwMemLength))
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
148 && (!Read669(lpStream, dwMemLength))
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
149 && (!ReadS3M(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
150 && (!ReadIT(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
151 && (!ReadWav(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
152 && (!ReadSTM(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
153 && (!ReadMed(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
154 && (!ReadMTM(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
155 && (!ReadMDL(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
156 && (!ReadDBM(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
157 && (!ReadFAR(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
158 && (!ReadAMS(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
159 && (!ReadOKT(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
160 && (!ReadPTM(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
161 && (!ReadUlt(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
162 && (!ReadDMF(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
163 && (!ReadDSM(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
164 && (!ReadUMX(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
165 && (!ReadAMF(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
166 && (!ReadPSM(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
167 && (!ReadMT2(lpStream, dwMemLength))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
168 && (!ReadMod(lpStream, dwMemLength))) m_nType = MOD_TYPE_NONE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
169 #ifdef MMCMP_SUPPORT
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
170 if (bMMCmp)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
171 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
172 GlobalFreePtr(lpStream);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
173 lpStream = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
174 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
175 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
176 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
177 // Adjust channels
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
178 for (i=0; i<MAX_BASECHANNELS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
179 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
180 if (ChnSettings[i].nVolume > 64) ChnSettings[i].nVolume = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
181 if (ChnSettings[i].nPan > 256) ChnSettings[i].nPan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
182 Chn[i].nPan = ChnSettings[i].nPan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
183 Chn[i].nGlobalVol = ChnSettings[i].nVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
184 Chn[i].dwFlags = ChnSettings[i].dwFlags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
185 Chn[i].nVolume = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
186 Chn[i].nCutOff = 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
187 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
188 // Checking instruments
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
189 MODINSTRUMENT *pins = Ins;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
190
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
191 for (i=0; i<MAX_INSTRUMENTS; i++, pins++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
192 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
193 if (pins->pSample)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
194 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
195 if (pins->nLoopEnd > pins->nLength) pins->nLoopEnd = pins->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
196 if (pins->nSustainEnd > pins->nLength) pins->nSustainEnd = pins->nLength;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
197 } else {
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
198 pins->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
199 pins->nLoopStart = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
200 pins->nLoopEnd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
201 pins->nSustainStart = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
202 pins->nSustainEnd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
203 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
204 if (!pins->nLoopEnd) pins->uFlags &= ~CHN_LOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
205 if (!pins->nSustainEnd) pins->uFlags &= ~CHN_SUSTAINLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
206 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
207 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
208 // Check invalid instruments
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
209 while ((m_nInstruments > 0) && (!Headers[m_nInstruments])) m_nInstruments--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
210 // Set default values
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
211 if (m_nDefaultTempo < 31) m_nDefaultTempo = 31;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
212 if (!m_nDefaultSpeed) m_nDefaultSpeed = 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
213 m_nMusicSpeed = m_nDefaultSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
214 m_nMusicTempo = m_nDefaultTempo;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
215 m_nGlobalVolume = m_nDefaultGlobalVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
216 m_nNextPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
217 m_nCurrentPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
218 m_nPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
219 m_nBufferCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
220 m_nTickCount = m_nMusicSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
221 m_nNextRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
222 m_nRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
223 if ((m_nRestartPos >= MAX_ORDERS) || (Order[m_nRestartPos] >= MAX_PATTERNS)) m_nRestartPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
224 // Load plugins
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
225 if (gpMixPluginCreateProc)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
226 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
227 for (UINT iPlug=0; iPlug<MAX_MIXPLUGINS; iPlug++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
228 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
229 if ((m_MixPlugins[iPlug].Info.dwPluginId1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
230 || (m_MixPlugins[iPlug].Info.dwPluginId2))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
231 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
232 gpMixPluginCreateProc(&m_MixPlugins[iPlug]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
233 if (m_MixPlugins[iPlug].pMixPlugin)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
234 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
235 m_MixPlugins[iPlug].pMixPlugin->RestoreAllParameters();
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
236 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
237 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
238 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
239 }
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
240 return m_nType ? TRUE : FALSE;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
241 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
242
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
243
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
244 BOOL CSoundFile::Destroy()
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
245
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
246 //------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
247 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
248 int i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
249 for (i=0; i<MAX_PATTERNS; i++) if (Patterns[i])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
250 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
251 FreePattern(Patterns[i]);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
252 Patterns[i] = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
253 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
254 m_nPatternNames = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
255 if (m_lpszPatternNames)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
256 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
257 delete m_lpszPatternNames;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
258 m_lpszPatternNames = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
259 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
260 if (m_lpszSongComments)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
261 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
262 delete m_lpszSongComments;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
263 m_lpszSongComments = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
264 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
265 for (i=1; i<MAX_SAMPLES; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
266 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
267 MODINSTRUMENT *pins = &Ins[i];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
268 if (pins->pSample)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
269 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
270 FreeSample(pins->pSample);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
271 pins->pSample = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
272 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
273 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
274 for (i=0; i<MAX_INSTRUMENTS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
275 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
276 if (Headers[i])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
277 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
278 delete Headers[i];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
279 Headers[i] = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
280 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
281 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
282 for (i=0; i<MAX_MIXPLUGINS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
283 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
284 if ((m_MixPlugins[i].nPluginDataSize) && (m_MixPlugins[i].pPluginData))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
285 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
286 m_MixPlugins[i].nPluginDataSize = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
287 delete [] (signed char*)m_MixPlugins[i].pPluginData;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
288 m_MixPlugins[i].pPluginData = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
289 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
290 m_MixPlugins[i].pMixState = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
291 if (m_MixPlugins[i].pMixPlugin)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
292 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
293 m_MixPlugins[i].pMixPlugin->Release();
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
294 m_MixPlugins[i].pMixPlugin = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
295 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
296 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
297 m_nType = MOD_TYPE_NONE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
298 m_nChannels = m_nSamples = m_nInstruments = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
299 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
300 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
301
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
302
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
303 //////////////////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
304 // Memory Allocation
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
305
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
306 MODCOMMAND *CSoundFile::AllocatePattern(UINT rows, UINT nchns)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
307 //------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
308 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
309 MODCOMMAND *p = new MODCOMMAND[rows*nchns];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
310 if (p) memset(p, 0, rows*nchns*sizeof(MODCOMMAND));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
311 return p;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
312 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
313
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
314
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
315 void CSoundFile::FreePattern(LPVOID pat)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
316 //--------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
317 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
318 if (pat) delete [] (signed char*)pat;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
319 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
320
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
321
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
322 signed char* CSoundFile::AllocateSample(UINT nbytes)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
323 //-------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
324 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
325 signed char * p = (signed char *)GlobalAllocPtr(GHND, (nbytes+39) & ~7);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
326 if (p) p += 16;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
327 return p;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
328 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
329
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
330
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
331 void CSoundFile::FreeSample(LPVOID p)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
334 if (p)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
335 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
336 GlobalFreePtr(((LPSTR)p)-16);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
337 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
338 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
339
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
340
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
341 //////////////////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
342 // Misc functions
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 void CSoundFile::ResetMidiCfg()
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
345 //-----------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
346 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
347 memset(&m_MidiCfg, 0, sizeof(m_MidiCfg));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
348 lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_START*32], "FF");
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
349 lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_STOP*32], "FC");
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
350 lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEON*32], "9c n v");
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
351 lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_NOTEOFF*32], "9c n 0");
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
352 lstrcpy(&m_MidiCfg.szMidiGlb[MIDIOUT_PROGRAM*32], "Cc p");
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
353 lstrcpy(&m_MidiCfg.szMidiSFXExt[0], "F0F000z");
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
354 for (int iz=0; iz<16; iz++) wsprintf(&m_MidiCfg.szMidiZXXExt[iz*32], "F0F001%02X", iz*8);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
355 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
356
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 UINT CSoundFile::GetNumChannels() const
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
361 UINT n = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
362 for (UINT i=0; i<m_nChannels; i++) if (ChnSettings[i].nVolume) n++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
363 return n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
364 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
365
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
366
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
367 UINT CSoundFile::GetSongComments(LPSTR s, UINT len, UINT linesize)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
370 LPCSTR p = m_lpszSongComments;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
371 if (!p) return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
372 UINT i = 2, ln=0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
373 if ((len) && (s)) s[0] = '\x0D';
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
374 if ((len > 1) && (s)) s[1] = '\x0A';
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
375 while ((*p) && (i+2 < len))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
376 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
377 BYTE c = (BYTE)*p++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
378 if ((c == 0x0D) || ((c == ' ') && (ln >= linesize)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
379 { if (s) { s[i++] = '\x0D'; s[i++] = '\x0A'; } else i+= 2; ln=0; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
380 else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
381 if (c >= 0x20) { if (s) s[i++] = c; else i++; ln++; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
382 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
383 if (s) s[i] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
384 return i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
385 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
386
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
387
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
388 UINT CSoundFile::GetRawSongComments(LPSTR s, UINT len, UINT linesize)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
389 //-------------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
390 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
391 LPCSTR p = m_lpszSongComments;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
392 if (!p) return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
393 UINT i = 0, ln=0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
394 while ((*p) && (i < len-1))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
395 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
396 BYTE c = (BYTE)*p++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
397 if ((c == 0x0D) || (c == 0x0A))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
398 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
399 if (ln)
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 while (ln < linesize) { if (s) s[i] = ' '; i++; ln++; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
402 ln = 0;
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 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
405 if ((c == ' ') && (!ln))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
406 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
407 UINT k=0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
408 while ((p[k]) && (p[k] >= ' ')) k++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
409 if (k <= linesize)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
410 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
411 if (s) s[i] = ' ';
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
412 i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
413 ln++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
414 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
415 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
416 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
417 if (s) s[i] = c;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
418 i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
419 ln++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
420 if (ln == linesize) ln = 0;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
423 if (ln)
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 while ((ln < linesize) && (i < len))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
426 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
427 if (s) s[i] = ' ';
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
428 i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
429 ln++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
430 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
431 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
432 if (s) s[i] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
433 return i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
434 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
435
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
436
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
437 BOOL CSoundFile::SetWaveConfig(UINT nRate,UINT nBits,UINT nChannels,BOOL bMMX)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
438 //----------------------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
439 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
440 BOOL bReset = FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
441 DWORD d = gdwSoundSetup & ~SNDMIX_ENABLEMMX;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
442 if (bMMX) d |= SNDMIX_ENABLEMMX;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
443 if ((gdwMixingFreq != nRate) || (gnBitsPerSample != nBits) || (gnChannels != nChannels) || (d != gdwSoundSetup)) bReset = TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
444 gnChannels = nChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
445 gdwSoundSetup = d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
446 gdwMixingFreq = nRate;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
447 gnBitsPerSample = nBits;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
448 InitPlayer(bReset);
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
449 //printf("Rate=%u Bits=%u Channels=%u MMX=%u\n",gdwMixingFreq,gnBitsPerSample,gnChannels,bMMX);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
450 return TRUE;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
453
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
454 BOOL CSoundFile::SetResamplingMode(UINT nMode)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
455 //--------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
456 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
457 DWORD d = gdwSoundSetup & ~(SNDMIX_NORESAMPLING|SNDMIX_HQRESAMPLER|SNDMIX_ULTRAHQSRCMODE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
458 switch(nMode)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
459 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
460 case SRCMODE_NEAREST: d |= SNDMIX_NORESAMPLING; break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
461 case SRCMODE_LINEAR: break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
462 case SRCMODE_SPLINE: d |= SNDMIX_HQRESAMPLER; break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
463 case SRCMODE_POLYPHASE: d |= (SNDMIX_HQRESAMPLER|SNDMIX_ULTRAHQSRCMODE); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
464 default:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
465 return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
466 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
467 gdwSoundSetup = d;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
468 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
469 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
470
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
471
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
472 BOOL CSoundFile::SetMasterVolume(UINT nVol, BOOL bAdjustAGC)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
475 if (nVol < 1) nVol = 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
476 if (nVol > 0x200) nVol = 0x200; // x4 maximum
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
477 if ((gdwSoundSetup & SNDMIX_AGC) && (bAdjustAGC))
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
478 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
479 gnAGC = gnAGC * m_nMasterVolume / nVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
480 if (gnAGC > AGC_UNITY) gnAGC = AGC_UNITY;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
481 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
482 m_nMasterVolume = nVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
483 return TRUE;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
486
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
487 void CSoundFile::SetAGC(BOOL b)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
488 //-----------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
489 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
490 if (b)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
491 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
492 if (!(gdwSoundSetup & SNDMIX_AGC))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
493 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
494 gdwSoundSetup |= SNDMIX_AGC;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
495 gnAGC = AGC_UNITY;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
496 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
497 } else gdwSoundSetup &= ~SNDMIX_AGC;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
498 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
499
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
500
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
501 UINT CSoundFile::GetNumPatterns() const
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 UINT i = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
505 while ((i < MAX_ORDERS) && (Order[i] < 0xFF)) i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
506 return i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
507 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
510 UINT CSoundFile::GetNumInstruments() const
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
511 //----------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
512 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
513 UINT n=0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
514 for (UINT i=0; i<MAX_INSTRUMENTS; i++) if (Ins[i].pSample) n++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
515 return n;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
519 UINT CSoundFile::GetMaxPosition() const
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
520 //-------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
521 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
522 UINT max = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
523 UINT i = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
524
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
525 while ((i < MAX_ORDERS) && (Order[i] != 0xFF))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
526 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
527 if (Order[i] < MAX_PATTERNS) max += PatternSize[Order[i]];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
528 i++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
529 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
530 return max;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
531 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
534 UINT CSoundFile::GetCurrentPos() const
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
535 //------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
536 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
537 UINT pos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
538
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
539 for (UINT i=0; i<m_nCurrentPattern; i++) if (Order[i] < MAX_PATTERNS)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
540 pos += PatternSize[Order[i]];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
541 return pos + m_nRow;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
542 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
543
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
544
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
545 void CSoundFile::SetCurrentPos(UINT nPos)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
546 //---------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
547 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
548 UINT i, nPattern;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
549
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
550 for (i=0; i<MAX_CHANNELS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
551 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
552 Chn[i].nNote = Chn[i].nNewNote = Chn[i].nNewIns = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
553 Chn[i].pInstrument = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
554 Chn[i].pHeader = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
555 Chn[i].nPortamentoDest = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
556 Chn[i].nCommand = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
557 Chn[i].nPatternLoopCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
558 Chn[i].nPatternLoop = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
559 Chn[i].nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
560 Chn[i].dwFlags |= CHN_KEYOFF|CHN_NOTEFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
561 Chn[i].nTremorCount = 0;
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 if (!nPos)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
564 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
565 for (i=0; i<MAX_CHANNELS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
566 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
567 Chn[i].nPeriod = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
568 Chn[i].nPos = Chn[i].nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
569 Chn[i].nLoopStart = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
570 Chn[i].nLoopEnd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
571 Chn[i].nROfs = Chn[i].nLOfs = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
572 Chn[i].pSample = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
573 Chn[i].pInstrument = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
574 Chn[i].pHeader = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
575 Chn[i].nCutOff = 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
576 Chn[i].nResonance = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
577 Chn[i].nLeftVol = Chn[i].nRightVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
578 Chn[i].nNewLeftVol = Chn[i].nNewRightVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
579 Chn[i].nLeftRamp = Chn[i].nRightRamp = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
580 Chn[i].nVolume = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
581 if (i < MAX_BASECHANNELS)
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 Chn[i].dwFlags = ChnSettings[i].dwFlags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
584 Chn[i].nPan = ChnSettings[i].nPan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
585 Chn[i].nGlobalVol = ChnSettings[i].nVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
586 } else
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 Chn[i].dwFlags = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
589 Chn[i].nPan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
590 Chn[i].nGlobalVol = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
591 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
592 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
593 m_nGlobalVolume = m_nDefaultGlobalVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
594 m_nMusicSpeed = m_nDefaultSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
595 m_nMusicTempo = m_nDefaultTempo;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
596 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
597 m_dwSongFlags &= ~(SONG_PATTERNLOOP|SONG_CPUVERYHIGH|SONG_FADINGSONG|SONG_ENDREACHED|SONG_GLOBALFADE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
598 for (nPattern = 0; nPattern < MAX_ORDERS; nPattern++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
599 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
600 UINT ord = Order[nPattern];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
601 if (ord == 0xFE) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
602 if (ord == 0xFF) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
603 if (ord < MAX_PATTERNS)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
604 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
605 if (nPos < (UINT)PatternSize[ord]) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
606 nPos -= PatternSize[ord];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
607 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
608 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
609 // Buggy position ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
610 if ((nPattern >= MAX_ORDERS)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
611 || (Order[nPattern] >= MAX_PATTERNS)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
612 || (nPos >= PatternSize[Order[nPattern]]))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
613 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
614 nPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
615 nPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
616 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
617 UINT nRow = nPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
618 if ((nRow) && (Order[nPattern] < MAX_PATTERNS))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
619 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
620 MODCOMMAND *p = Patterns[Order[nPattern]];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
621 if ((p) && (nRow < PatternSize[Order[nPattern]]))
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 BOOL bOk = FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
624 while ((!bOk) && (nRow > 0))
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 UINT n = nRow * m_nChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
627 for (UINT k=0; k<m_nChannels; k++, n++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
628 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
629 if (p[n].note)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
630 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
631 bOk = TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
632 break;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
635 if (!bOk) nRow--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
636 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
637 }
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 m_nNextPattern = nPattern;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
640 m_nNextRow = nRow;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
641 m_nTickCount = m_nMusicSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
642 m_nBufferCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
643 m_nPatternDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
644 m_nFrameDelay = 0;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
647
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
648 void CSoundFile::SetCurrentOrder(UINT nPos)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
651 while ((nPos < MAX_ORDERS) && (Order[nPos] == 0xFE)) nPos++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
652 if ((nPos >= MAX_ORDERS) || (Order[nPos] >= MAX_PATTERNS)) return;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
653 for (UINT j=0; j<MAX_CHANNELS; j++)
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 Chn[j].nPeriod = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
656 Chn[j].nNote = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
657 Chn[j].nPortamentoDest = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
658 Chn[j].nCommand = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
659 Chn[j].nPatternLoopCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
660 Chn[j].nPatternLoop = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
661 Chn[j].nTremorCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
662 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
663 if (!nPos)
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 SetCurrentPos(0);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
666 } else
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 m_nNextPattern = nPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
669 m_nRow = m_nNextRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
670 m_nPattern = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
671 m_nTickCount = m_nMusicSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
672 m_nBufferCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
673 m_nTotalCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
674 m_nPatternDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
675 m_nFrameDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
676 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
677 m_dwSongFlags &= ~(SONG_PATTERNLOOP|SONG_CPUVERYHIGH|SONG_FADINGSONG|SONG_ENDREACHED|SONG_GLOBALFADE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
678 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
679
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
680 void CSoundFile::ResetChannels()
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
681 //------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
682 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
683 m_dwSongFlags &= ~(SONG_CPUVERYHIGH|SONG_FADINGSONG|SONG_ENDREACHED|SONG_GLOBALFADE);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
684 m_nBufferCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
685 for (UINT i=0; i<MAX_CHANNELS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
686 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
687 Chn[i].nROfs = Chn[i].nLOfs = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
688 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
689 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
690
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
691
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
692 void CSoundFile::ResetTimestamps()
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
693 //--------------------------------
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
694 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
695 int n;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
696
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
697 for (n = 1; n < MAX_SAMPLES; n++) {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
698 Ins[n].played = 0;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
699 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
700 for (n = 1; n < MAX_INSTRUMENTS; n++) {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
701 if (Headers[n])
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
702 Headers[n]->played = 0;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
703 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
704 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
705
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
706
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
707 void CSoundFile::LoopPattern(int nPat, int nRow)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
708 //----------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
709 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
710 if ((nPat < 0) || (nPat >= MAX_PATTERNS) || (!Patterns[nPat]))
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 m_dwSongFlags &= ~SONG_PATTERNLOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
713 } else
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 if ((nRow < 0) || (nRow >= PatternSize[nPat])) nRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
716 m_nPattern = nPat;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
717 m_nRow = m_nNextRow = nRow;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
718 m_nTickCount = m_nMusicSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
719 m_nPatternDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
720 m_nFrameDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
721 m_nBufferCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
722 m_dwSongFlags |= SONG_PATTERNLOOP;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
725
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
726
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
727 UINT CSoundFile::GetBestSaveFormat() const
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 if ((!m_nSamples) || (!m_nChannels)) return MOD_TYPE_NONE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
731 if (!m_nType) return MOD_TYPE_NONE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
732 if (m_nType & (MOD_TYPE_MOD|MOD_TYPE_OKT))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
733 return MOD_TYPE_MOD;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
734 if (m_nType & (MOD_TYPE_S3M|MOD_TYPE_STM|MOD_TYPE_ULT|MOD_TYPE_FAR|MOD_TYPE_PTM))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
735 return MOD_TYPE_S3M;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
736 if (m_nType & (MOD_TYPE_XM|MOD_TYPE_MED|MOD_TYPE_MTM|MOD_TYPE_MT2))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
737 return MOD_TYPE_XM;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
738 return MOD_TYPE_IT;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
742 UINT CSoundFile::GetSaveFormats() const
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
743 //-------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
744 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
745 UINT n = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
746 if ((!m_nSamples) || (!m_nChannels) || (m_nType == MOD_TYPE_NONE)) return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
747 switch(m_nType)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
748 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
749 case MOD_TYPE_MOD: n = MOD_TYPE_MOD;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
750 case MOD_TYPE_S3M: n = MOD_TYPE_S3M;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
751 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
752 n |= MOD_TYPE_XM | MOD_TYPE_IT;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
753 if (!(m_dwSongFlags & SONG_INSTRUMENTMODE))
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
754 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
755 if (m_nSamples < 32) n |= MOD_TYPE_MOD;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
756 n |= MOD_TYPE_S3M;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
757 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
758 return n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
759 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
760
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
761
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
762 UINT CSoundFile::GetSampleName(UINT nSample,LPSTR s) const
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
763 //--------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
764 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
765 char sztmp[40] = ""; // changed from CHAR
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
766 memcpy(sztmp, m_szNames[nSample],32);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
767 sztmp[31] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
768 if (s) strcpy(s, sztmp);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
769 return strlen(sztmp);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
770 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
771
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
772
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
773 UINT CSoundFile::GetInstrumentName(UINT nInstr,LPSTR s) const
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
774 //-----------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
775 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
776 char sztmp[40] = ""; // changed from CHAR
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
777 if ((nInstr >= MAX_INSTRUMENTS) || (!Headers[nInstr]))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
778 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
779 if (s) *s = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
780 return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
781 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
782 INSTRUMENTHEADER *penv = Headers[nInstr];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
783 memcpy(sztmp, penv->name, 32);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
784 sztmp[31] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
785 if (s) strcpy(s, sztmp);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
786 return strlen(sztmp);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
787 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
788
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
789
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
790 #ifndef NO_PACKING
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
791 UINT CSoundFile::PackSample(int &sample, int next)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
792 //------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
793 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
794 UINT i = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
795 int delta = next - sample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
796 if (delta >= 0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
797 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
798 for (i=0; i<7; i++) if (delta <= (int)CompressionTable[i+1]) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
799 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
800 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
801 for (i=8; i<15; i++) if (delta >= (int)CompressionTable[i+1]) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
802 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
803 sample += (int)CompressionTable[i];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
804 return i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
805 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
806
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
807
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
808 BOOL CSoundFile::CanPackSample(LPSTR pSample, UINT nLen, UINT nPacking, BYTE *result)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
809 //-----------------------------------------------------------------------------------
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 int pos, old, oldpos, besttable = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
812 DWORD dwErr, dwTotal, dwResult;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
813 int i,j;
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 if (result) *result = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
816 if ((!pSample) || (nLen < 1024)) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
817 // Try packing with different tables
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
818 dwResult = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
819 for (j=1; j<MAX_PACK_TABLES; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
820 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
821 memcpy(CompressionTable, UnpackTable[j], 16);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
822 dwErr = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
823 dwTotal = 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
824 old = pos = oldpos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
825 for (i=0; i<(int)nLen; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
826 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
827 int s = (int)pSample[i];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
828 PackSample(pos, s);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
829 dwErr += abs(pos - oldpos);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
830 dwTotal += abs(s - old);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
831 old = s;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
832 oldpos = pos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
833 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
834 dwErr = _muldiv(dwErr, 100, dwTotal);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
835 if (dwErr >= dwResult)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
836 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
837 dwResult = dwErr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
838 besttable = j;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
841 memcpy(CompressionTable, UnpackTable[besttable], 16);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
842 if (result)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
843 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
844 if (dwResult > 100) *result = 100; else *result = (BYTE)dwResult;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
845 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
846 return (dwResult >= nPacking) ? TRUE : FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
847 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
848 #endif // NO_PACKING
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
849
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
850
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
851
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
852 // Flags:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
853 // 0 = signed 8-bit PCM data (default)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
854 // 1 = unsigned 8-bit PCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
855 // 2 = 8-bit ADPCM data with linear table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
856 // 3 = 4-bit ADPCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
857 // 4 = 16-bit ADPCM data with linear table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
858 // 5 = signed 16-bit PCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
859 // 6 = unsigned 16-bit PCM data
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
862 UINT CSoundFile::ReadSample(MODINSTRUMENT *pIns, UINT nFlags, LPCSTR lpMemFile, DWORD dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
863 //------------------------------------------------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
864 {
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
865 UINT len = 0, mem = pIns->nLength+6;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
866
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
867 if ((!pIns) || (pIns->nLength < 1) || (!lpMemFile)) return 0;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
868 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
869 pIns->uFlags &= ~(CHN_16BIT|CHN_STEREO);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
870 if (nFlags & RSF_16BIT)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
871 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
872 mem *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
873 pIns->uFlags |= CHN_16BIT;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
874 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
875 if (nFlags & RSF_STEREO)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
876 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
877 mem *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
878 pIns->uFlags |= CHN_STEREO;
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 if ((pIns->pSample = AllocateSample(mem)) == NULL)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
881 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
882 pIns->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
883 return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
884 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
885 switch(nFlags)
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 // 1: 8-bit unsigned PCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
888 case RS_PCM8U:
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 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
891 if (len > dwMemLength) len = pIns->nLength = dwMemLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
892 signed char *pSample = pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
893 for (UINT j=0; j<len; j++) pSample[j] = (signed char)(lpMemFile[j] - 0x80);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
894 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
895 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
896
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
897 // 2: 8-bit ADPCM data with linear table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
898 case RS_PCM8D:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
899 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
900 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
901 if (len > dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
902 signed char *pSample = pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
903 const signed char *p = (const signed char *)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
904 int delta = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
905
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
906 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
907 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
908 delta += p[j];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
909 *pSample++ = (signed char)delta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
910 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
911 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
912 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
913
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
914 // 3: 4-bit ADPCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
915 case RS_ADPCM4:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
916 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
917 len = (pIns->nLength + 1) / 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
918 if (len > dwMemLength - 16) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
919 memcpy(CompressionTable, lpMemFile, 16);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
920 lpMemFile += 16;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
921 signed char *pSample = pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
922 signed char delta = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
923 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
924 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
925 BYTE b0 = (BYTE)lpMemFile[j];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
926 BYTE b1 = (BYTE)(lpMemFile[j] >> 4);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
927 delta = (signed char)GetDeltaValue((int)delta, b0);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
928 pSample[0] = delta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
929 delta = (signed char)GetDeltaValue((int)delta, b1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
930 pSample[1] = delta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
931 pSample += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
932 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
933 len += 16;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
934 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
935 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
936
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
937 // 4: 16-bit ADPCM data with linear table
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
938 case RS_PCM16D:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
939 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
940 len = pIns->nLength * 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
941 if (len > dwMemLength) break;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
942 short *pSample = (short *)pIns->pSample;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
943 short *p = (short *)lpMemFile;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
944 unsigned short tmp;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
945 int delta16 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
946 for (UINT j=0; j<len; j+=2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
947 {
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
948 tmp = *((unsigned short *)p++);
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
949 delta16 += bswapLE16(tmp);
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
950 *pSample++ = (short) delta16;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
951 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
952 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
953 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
954
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
955 // 5: 16-bit signed PCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
956 case RS_PCM16S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
957 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
958 len = pIns->nLength * 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
959 if (len <= dwMemLength) memcpy(pIns->pSample, lpMemFile, len);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
960 short int *pSample = (short int *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
961 for (UINT j=0; j<len; j+=2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
962 {
963
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 161
diff changeset
963 *pSample = bswapLE16(*pSample);
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
964 pSample++;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
965 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
966 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
967 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
968
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
969 // 16-bit signed mono PCM motorola byte order
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
970 case RS_PCM16M:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
971 len = pIns->nLength * 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
972 if (len > dwMemLength) len = dwMemLength & ~1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
973 if (len > 1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
974 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
975 signed char *pSample = (signed char *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
976 signed char *pSrc = (signed char *)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
977 for (UINT j=0; j<len; j+=2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
978 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
979 // pSample[j] = pSrc[j+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
980 // pSample[j+1] = pSrc[j];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
981 *((unsigned short *)(pSample+j)) = bswapBE16(*((unsigned short *)(pSrc+j)));
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
984 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
985
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
986 // 6: 16-bit unsigned PCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
987 case RS_PCM16U:
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
988 {
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
989 len = pIns->nLength * 2;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
990 if (len <= dwMemLength) memcpy(pIns->pSample, lpMemFile, len);
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
991 short int *pSample = (short int *)pIns->pSample;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
992 for (UINT j=0; j<len; j+=2)
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
993 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
994 *pSample = bswapLE16(*pSample) - 0x8000;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
995 pSample++;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
996 }
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
997 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
998 break;
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 // 16-bit signed stereo big endian
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1001 case RS_STPCM16M:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1002 len = pIns->nLength * 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1003 if (len*2 <= dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1004 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1005 signed char *pSample = (signed char *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1006 signed char *pSrc = (signed char *)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1007 for (UINT j=0; j<len; j+=2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1008 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1009 // pSample[j*2] = pSrc[j+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1010 // pSample[j*2+1] = pSrc[j];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1011 // pSample[j*2+2] = pSrc[j+1+len];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1012 // pSample[j*2+3] = pSrc[j+len];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1013 *((unsigned short *)(pSample+j*2)) = bswapBE16(*((unsigned short *)(pSrc+j)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1014 *((unsigned short *)(pSample+j*2+2)) = bswapBE16(*((unsigned short *)(pSrc+j+len)));
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 len *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1017 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1018 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1019
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1020 // 8-bit stereo samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1021 case RS_STPCM8S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1022 case RS_STPCM8U:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1023 case RS_STPCM8D:
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 int iadd_l = 0, iadd_r = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1026 if (nFlags == RS_STPCM8U) { iadd_l = iadd_r = -128; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1027 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1028 signed char *psrc = (signed char *)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1029 signed char *pSample = (signed char *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1030 if (len*2 > dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1031 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1032 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1033 pSample[j*2] = (signed char)(psrc[0] + iadd_l);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1034 pSample[j*2+1] = (signed char)(psrc[len] + iadd_r);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1035 psrc++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1036 if (nFlags == RS_STPCM8D)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1037 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1038 iadd_l = pSample[j*2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1039 iadd_r = pSample[j*2+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1040 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1041 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1042 len *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1043 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1044 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1045
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1046 // 16-bit stereo samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1047 case RS_STPCM16S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1048 case RS_STPCM16U:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1049 case RS_STPCM16D:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1050 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1051 int iadd_l = 0, iadd_r = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1052 if (nFlags == RS_STPCM16U) { iadd_l = iadd_r = -0x8000; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1053 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1054 short int *psrc = (short int *)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1055 short int *pSample = (short int *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1056 if (len*4 > dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1057 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1058 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1059 pSample[j*2] = (short int) (bswapLE16(psrc[0]) + iadd_l);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1060 pSample[j*2+1] = (short int) (bswapLE16(psrc[len]) + iadd_r);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1061 psrc++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1062 if (nFlags == RS_STPCM16D)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1063 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1064 iadd_l = pSample[j*2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1065 iadd_r = pSample[j*2+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1066 }
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 len *= 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1069 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1070 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1071
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1072 // IT 2.14 compressed samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1073 case RS_IT2148:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1074 case RS_IT21416:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1075 case RS_IT2158:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1076 case RS_IT21516:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1077 len = dwMemLength;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1078 if (len < 2) break;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1079 if ((nFlags == RS_IT2148) || (nFlags == RS_IT2158))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1080 ITUnpack8Bit(pIns->pSample, pIns->nLength, (LPBYTE)lpMemFile, dwMemLength, (nFlags == RS_IT2158));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1081 else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1082 ITUnpack16Bit(pIns->pSample, pIns->nLength, (LPBYTE)lpMemFile, dwMemLength, (nFlags == RS_IT21516));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1083 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1084
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1085 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1086 // 8-bit interleaved stereo samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1087 case RS_STIPCM8S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1088 case RS_STIPCM8U:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1089 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1090 int iadd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1091 if (nFlags == RS_STIPCM8U) { iadd = -0x80; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1092 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1093 if (len*2 > dwMemLength) len = dwMemLength >> 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1094 LPBYTE psrc = (LPBYTE)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1095 LPBYTE pSample = (LPBYTE)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1096 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1097 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1098 pSample[j*2] = (signed char)(psrc[0] + iadd);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1099 pSample[j*2+1] = (signed char)(psrc[1] + iadd);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1100 psrc+=2;
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 len *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1103 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1104 break;
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 // 16-bit interleaved stereo samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1107 case RS_STIPCM16S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1108 case RS_STIPCM16U:
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 int iadd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1111 if (nFlags == RS_STIPCM16U) iadd = -32768;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1112 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1113 if (len*4 > dwMemLength) len = dwMemLength >> 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1114 short int *psrc = (short int *)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1115 short int *pSample = (short int *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1116 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1117 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1118 pSample[j*2] = (short int)(bswapLE16(psrc[0]) + iadd);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1119 pSample[j*2+1] = (short int)(bswapLE16(psrc[1]) + iadd);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1120 psrc += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1121 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1122 len *= 4;
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 break;
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 // AMS compressed samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1127 case RS_AMS8:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1128 case RS_AMS16:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1129 len = 9;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1130 if (dwMemLength > 9)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1131 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1132 const char *psrc = lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1133 char packcharacter = lpMemFile[8], *pdest = (char *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1134 len += bswapLE32(*((LPDWORD)(lpMemFile+4)));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1135 if (len > dwMemLength) len = dwMemLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1136 UINT dmax = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1137 if (pIns->uFlags & CHN_16BIT) dmax <<= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1138 AMSUnpack(psrc+9, len-9, pdest, dmax, packcharacter);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1139 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1140 break;
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 // PTM 8bit delta to 16-bit sample
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1143 case RS_PTM8DTO16:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1144 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1145 len = pIns->nLength * 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1146 if (len > dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1147 signed char *pSample = (signed char *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1148 signed char delta8 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1149 for (UINT j=0; j<len; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1150 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1151 delta8 += lpMemFile[j];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1152 *pSample++ = delta8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1153 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1154 WORD *pSampleW = (WORD *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1155 for (UINT j=0; j<len; j+=2) // swaparoni!
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1156 {
963
9549fea94794 [svn] Warning fixes from SuSe.
chainsaw
parents: 161
diff changeset
1157 *pSampleW = bswapLE16(*pSampleW);
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1158 *pSampleW++;
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1159 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1160 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1161 break;
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 // Huffman MDL compressed samples
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1164 case RS_MDL8:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1165 case RS_MDL16:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1166 len = dwMemLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1167 if (len >= 4)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1168 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1169 LPBYTE pSample = (LPBYTE)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1170 LPBYTE ibuf = (LPBYTE)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1171 DWORD bitbuf = bswapLE32(*((DWORD *)ibuf));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1172 UINT bitnum = 32;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1173 BYTE dlt = 0, lowbyte = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1174 ibuf += 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1175 for (UINT j=0; j<pIns->nLength; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1176 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1177 BYTE hibyte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1178 BYTE sign;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1179 if (nFlags == RS_MDL16) lowbyte = (BYTE)MDLReadBits(bitbuf, bitnum, ibuf, 8);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1180 sign = (BYTE)MDLReadBits(bitbuf, bitnum, ibuf, 1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1181 if (MDLReadBits(bitbuf, bitnum, ibuf, 1))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1182 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1183 hibyte = (BYTE)MDLReadBits(bitbuf, bitnum, ibuf, 3);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1184 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1185 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1186 hibyte = 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1187 while (!MDLReadBits(bitbuf, bitnum, ibuf, 1)) hibyte += 0x10;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1188 hibyte += MDLReadBits(bitbuf, bitnum, ibuf, 4);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1189 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1190 if (sign) hibyte = ~hibyte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1191 dlt += hibyte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1192 if (nFlags != RS_MDL16)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1193 pSample[j] = dlt;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1194 else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1195 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1196 pSample[j<<1] = lowbyte;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1197 pSample[(j<<1)+1] = dlt;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1200 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1201 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1202
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1203 case RS_DMF8:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1204 case RS_DMF16:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1205 len = dwMemLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1206 if (len >= 4)
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 UINT maxlen = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1209 if (pIns->uFlags & CHN_16BIT) maxlen <<= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1210 LPBYTE ibuf = (LPBYTE)lpMemFile, ibufmax = (LPBYTE)(lpMemFile+dwMemLength);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1211 len = DMFUnpack((LPBYTE)pIns->pSample, ibuf, ibufmax, maxlen);
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 break;
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 #ifdef MODPLUG_TRACKER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1216 // PCM 24-bit signed -> load sample, and normalize it to 16-bit
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1217 case RS_PCM24S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1218 case RS_PCM32S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1219 len = pIns->nLength * 3;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1220 if (nFlags == RS_PCM32S) len += pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1221 if (len > dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1222 if (len > 4*8)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1223 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1224 UINT slsize = (nFlags == RS_PCM32S) ? 4 : 3;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1225 LPBYTE pSrc = (LPBYTE)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1226 LONG max = 255;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1227 if (nFlags == RS_PCM32S) pSrc++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1228 for (UINT j=0; j<len; j+=slsize)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1229 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1230 LONG l = ((((pSrc[j+2] << 8) + pSrc[j+1]) << 8) + pSrc[j]) << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1231 l /= 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1232 if (l > max) max = l;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1233 if (-l > max) max = -l;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1234 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1235 max = (max / 128) + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1236 signed short *pDest = (signed short *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1237 for (UINT k=0; k<len; k+=slsize)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1238 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1239 LONG l = ((((pSrc[k+2] << 8) + pSrc[k+1]) << 8) + pSrc[k]) << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1240 *pDest++ = (signed short)(l / max);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1241 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1242 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1243 break;
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 // Stereo PCM 24-bit signed -> load sample, and normalize it to 16-bit
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1246 case RS_STIPCM24S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1247 case RS_STIPCM32S:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1248 len = pIns->nLength * 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1249 if (nFlags == RS_STIPCM32S) len += pIns->nLength * 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1250 if (len > dwMemLength) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1251 if (len > 8*8)
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 UINT slsize = (nFlags == RS_STIPCM32S) ? 4 : 3;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1254 LPBYTE pSrc = (LPBYTE)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1255 LONG max = 255;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1256 if (nFlags == RS_STIPCM32S) pSrc++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1257 for (UINT j=0; j<len; j+=slsize)
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 LONG l = ((((pSrc[j+2] << 8) + pSrc[j+1]) << 8) + pSrc[j]) << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1260 l /= 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1261 if (l > max) max = l;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1262 if (-l > max) max = -l;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1263 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1264 max = (max / 128) + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1265 signed short *pDest = (signed short *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1266 for (UINT k=0; k<len; k+=slsize)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1267 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1268 LONG lr = ((((pSrc[k+2] << 8) + pSrc[k+1]) << 8) + pSrc[k]) << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1269 k += slsize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1270 LONG ll = ((((pSrc[k+2] << 8) + pSrc[k+1]) << 8) + pSrc[k]) << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1271 pDest[0] = (signed short)ll;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1272 pDest[1] = (signed short)lr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1273 pDest += 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1274 }
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 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1277
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1278 // 16-bit signed big endian interleaved stereo
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1279 case RS_STIPCM16M:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1280 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1281 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1282 if (len*4 > dwMemLength) len = dwMemLength >> 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1283 LPCBYTE psrc = (LPCBYTE)lpMemFile;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1284 short int *pSample = (short int *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1285 for (UINT j=0; j<len; j++)
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 pSample[j*2] = (signed short)(((UINT)psrc[0] << 8) | (psrc[1]));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1288 pSample[j*2+1] = (signed short)(((UINT)psrc[2] << 8) | (psrc[3]));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1289 psrc += 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1290 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1291 len *= 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1292 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1293 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1294
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1295 #endif // MODPLUG_TRACKER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1296 #endif // !MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1297
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1298 // Default: 8-bit signed PCM data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1299 default:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1300 len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1301 if (len > dwMemLength) len = pIns->nLength = dwMemLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1302 memcpy(pIns->pSample, lpMemFile, len);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1303 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1304 if (len > dwMemLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1305 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1306 if (pIns->pSample)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1307 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1308 pIns->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1309 FreeSample(pIns->pSample);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1310 pIns->pSample = NULL;
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 return 0;
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 AdjustSampleLoop(pIns);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1315 return len;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1316 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1317
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1318
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1319 void CSoundFile::AdjustSampleLoop(MODINSTRUMENT *pIns)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1322 if (!pIns->pSample) return;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1323 if (pIns->nLoopEnd > pIns->nLength) pIns->nLoopEnd = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1324 if (pIns->nLoopStart+2 >= pIns->nLoopEnd)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1325 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1326 pIns->nLoopStart = pIns->nLoopEnd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1327 pIns->uFlags &= ~CHN_LOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1328 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1329 UINT len = pIns->nLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1330 if (pIns->uFlags & CHN_16BIT)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1331 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1332 short int *pSample = (short int *)pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1333 // Adjust end of sample
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1334 if (pIns->uFlags & CHN_STEREO)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1335 {
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1336 pSample[len*2+6] = pSample[len*2+4] = pSample[len*2+2] = pSample[len*2] = pSample[len*2-2];
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1337 pSample[len*2+7] = pSample[len*2+5] = pSample[len*2+3] = pSample[len*2+1] = pSample[len*2-1];
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1338 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1339 {
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1340 pSample[len+4] = pSample[len+3] = pSample[len+2] = pSample[len+1] = pSample[len] = pSample[len-1];
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1341 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1342 if ((pIns->uFlags & (CHN_LOOP|CHN_PINGPONGLOOP|CHN_STEREO)) == CHN_LOOP)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1343 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1344 // Fix bad loops
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1345 if ((pIns->nLoopEnd+3 >= pIns->nLength) || (m_nType & MOD_TYPE_S3M))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1346 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1347 pSample[pIns->nLoopEnd] = pSample[pIns->nLoopStart];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1348 pSample[pIns->nLoopEnd+1] = pSample[pIns->nLoopStart+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1349 pSample[pIns->nLoopEnd+2] = pSample[pIns->nLoopStart+2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1350 pSample[pIns->nLoopEnd+3] = pSample[pIns->nLoopStart+3];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1351 pSample[pIns->nLoopEnd+4] = pSample[pIns->nLoopStart+4];
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 } else
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 signed char *pSample = pIns->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1357 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1358 // Crappy samples (except chiptunes) ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1359 if ((pIns->nLength > 0x100) && (m_nType & (MOD_TYPE_MOD|MOD_TYPE_S3M))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1360 && (!(pIns->uFlags & CHN_STEREO)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1361 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1362 int smpend = pSample[pIns->nLength-1], smpfix = 0, kscan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1363 for (kscan=pIns->nLength-1; kscan>0; kscan--)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1364 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1365 smpfix = pSample[kscan-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1366 if (smpfix != smpend) break;
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 int delta = smpfix - smpend;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1369 if (((!(pIns->uFlags & CHN_LOOP)) || (kscan > (int)pIns->nLoopEnd))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1370 && ((delta < -8) || (delta > 8)))
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 while (kscan<(int)pIns->nLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1373 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1374 if (!(kscan & 7))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1375 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1376 if (smpfix > 0) smpfix--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1377 if (smpfix < 0) smpfix++;
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 pSample[kscan] = (signed char)smpfix;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1380 kscan++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1381 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1382 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1383 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1384 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1385 // Adjust end of sample
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1386 if (pIns->uFlags & CHN_STEREO)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1387 {
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1388 pSample[len*2+6] = pSample[len*2+4] = pSample[len*2+2] = pSample[len*2] = pSample[len*2-2];
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1389 pSample[len*2+7] = pSample[len*2+5] = pSample[len*2+3] = pSample[len*2+1] = pSample[len*2-1];
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1390 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1391 {
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1392 pSample[len+4] = pSample[len+3] = pSample[len+2] = pSample[len+1] = pSample[len] = pSample[len-1];
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1393 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1394 if ((pIns->uFlags & (CHN_LOOP|CHN_PINGPONGLOOP|CHN_STEREO)) == CHN_LOOP)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1395 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1396 if ((pIns->nLoopEnd+3 >= pIns->nLength) || (m_nType & (MOD_TYPE_MOD|MOD_TYPE_S3M)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1397 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1398 pSample[pIns->nLoopEnd] = pSample[pIns->nLoopStart];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1399 pSample[pIns->nLoopEnd+1] = pSample[pIns->nLoopStart+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1400 pSample[pIns->nLoopEnd+2] = pSample[pIns->nLoopStart+2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1401 pSample[pIns->nLoopEnd+3] = pSample[pIns->nLoopStart+3];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1402 pSample[pIns->nLoopEnd+4] = pSample[pIns->nLoopStart+4];
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1405 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1408
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 // Transpose <-> Frequency conversions
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1411
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1412 // returns 8363*2^((transp*128+ftune)/(12*128))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1413 DWORD CSoundFile::TransposeToFrequency(int transp, int ftune)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1414 //-----------------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1415 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1416 //---GCCFIX: Removed assembly.
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1417 #ifdef MSC_VER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1418 const float _fbase = 8363;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1419 const float _factor = 1.0f/(12.0f*128.0f);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1420 int result;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1421 DWORD freq;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1422
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1423 transp = (transp << 7) + ftune;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1424 _asm {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1425 fild transp
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1426 fld _factor
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1427 fmulp st(1), st(0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1428 fist result
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1429 fisub result
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1430 f2xm1
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1431 fild result
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1432 fld _fbase
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1433 fscale
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1434 fstp st(1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1435 fmul st(1), st(0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1436 faddp st(1), st(0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1437 fistp freq
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 UINT derr = freq % 11025;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1440 if (derr <= 8) freq -= derr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1441 if (derr >= 11015) freq += 11025-derr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1442 derr = freq % 1000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1443 if (derr <= 5) freq -= derr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1444 if (derr >= 995) freq += 1000-derr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1445 return freq;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1446 #else
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1447 return (DWORD) (8363.0 * pow(2, (transp * 128.0 + ftune) / 1536.0));
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1448 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1449 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1452 // returns 12*128*log2(freq/8363)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1453 int CSoundFile::FrequencyToTranspose(DWORD freq)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1454 //----------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1455 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1456 //---GCCFIX: Removed assembly.
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1457 #ifdef MSC_VER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1458 const float _f1_8363 = 1.0f / 8363.0f;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1459 const float _factor = 128 * 12;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1460 LONG result;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1461
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1462 if (!freq) return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1463 _asm {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1464 fld _factor
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1465 fild freq
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1466 fld _f1_8363
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1467 fmulp st(1), st(0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1468 fyl2x
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1469 fistp result
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1470 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1471 return result;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1472 #else
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1473 return (int) (1536.0 * (log(freq / 8363.0) / log(2)));
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1474 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1475 }
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 void CSoundFile::FrequencyToTranspose(MODINSTRUMENT *psmp)
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 int f2t = FrequencyToTranspose(psmp->nC4Speed);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1482 int transp = f2t >> 7;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1483 int ftune = f2t & 0x7F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1484 if (ftune > 80)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1485 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1486 transp++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1487 ftune -= 128;
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 if (transp > 127) transp = 127;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1490 if (transp < -127) transp = -127;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1491 psmp->RelativeTone = transp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1492 psmp->nFineTune = ftune;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1493 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1494
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1495
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1496 void CSoundFile::CheckCPUUsage(UINT nCPU)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1497 //---------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1498 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1499 if (nCPU > 100) nCPU = 100;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1500 gnCPUUsage = nCPU;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1501 if (nCPU < 90)
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 m_dwSongFlags &= ~SONG_CPUVERYHIGH;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1504 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1505 if ((m_dwSongFlags & SONG_CPUVERYHIGH) && (nCPU >= 94))
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 i=MAX_CHANNELS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1508 while (i >= 8)
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 i--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1511 if (Chn[i].nLength)
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 Chn[i].nLength = Chn[i].nPos = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1514 nCPU -= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1515 if (nCPU < 94) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1516 }
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 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1519 if (nCPU > 90)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1520 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1521 m_dwSongFlags |= SONG_CPUVERYHIGH;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1522 }
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
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 BOOL CSoundFile::SetPatternName(UINT nPat, LPCSTR lpszName)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1529 char szName[MAX_PATTERNNAME] = ""; // changed from CHAR
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1530 if (nPat >= MAX_PATTERNS) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1531 if (lpszName) lstrcpyn(szName, lpszName, MAX_PATTERNNAME);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1532 szName[MAX_PATTERNNAME-1] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1533 if (!m_lpszPatternNames) m_nPatternNames = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1534 if (nPat >= m_nPatternNames)
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 if (!lpszName[0]) return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1537 UINT len = (nPat+1)*MAX_PATTERNNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1538 char *p = new char[len]; // changed from CHAR
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1539 if (!p) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1540 memset(p, 0, len);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1541 if (m_lpszPatternNames)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1542 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1543 memcpy(p, m_lpszPatternNames, m_nPatternNames * MAX_PATTERNNAME);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1544 delete m_lpszPatternNames;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1545 m_lpszPatternNames = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1546 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1547 m_lpszPatternNames = p;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1548 m_nPatternNames = nPat + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1549 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1550 memcpy(m_lpszPatternNames + nPat * MAX_PATTERNNAME, szName, MAX_PATTERNNAME);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1551 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1552 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1553
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 BOOL CSoundFile::GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize) const
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 if ((!lpszName) || (!cbSize)) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1559 lpszName[0] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1560 if (cbSize > MAX_PATTERNNAME) cbSize = MAX_PATTERNNAME;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1561 if ((m_lpszPatternNames) && (nPat < m_nPatternNames))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1562 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1563 memcpy(lpszName, m_lpszPatternNames + nPat * MAX_PATTERNNAME, cbSize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1564 lpszName[cbSize-1] = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1565 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1566 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1567 return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1568 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1569
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1570 UINT CSoundFile::GetHighestUsedChannel()
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1571 //------------------------------
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1572 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1573 UINT highchan = 0;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1574
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1575 for (UINT ipat=0; ipat<MAX_PATTERNS; ipat++)
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1576 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1577 MODCOMMAND *p = Patterns[ipat];
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1578 if (p)
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1579 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1580 UINT jmax = PatternSize[ipat] * m_nChannels;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1581 for (UINT j=0; j<jmax; j++, p++)
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1582 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1583 if ((p->note) && (p->note <= 120))
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1584 {
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1585 if ((j % m_nChannels) > highchan)
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1586 highchan = j % m_nChannels;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1587 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1588 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1589 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1590 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1591
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1592 return highchan;
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1593 }
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1594
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1595
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1596
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1597 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1598
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1599 UINT CSoundFile::DetectUnusedSamples(BOOL *pbIns)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1600 //-----------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1601 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1602 UINT nExt = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1603
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1604 if (!pbIns) return 0;
2337
107c1fed3d92 Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents: 2218
diff changeset
1605 if (m_dwSongFlags & SONG_INSTRUMENTMODE)
136
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1606 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1607 memset(pbIns, 0, MAX_SAMPLES * sizeof(BOOL));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1608 for (UINT ipat=0; ipat<MAX_PATTERNS; ipat++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1609 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1610 MODCOMMAND *p = Patterns[ipat];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1611 if (p)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1612 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1613 UINT jmax = PatternSize[ipat] * m_nChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1614 for (UINT j=0; j<jmax; j++, p++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1615 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1616 if ((p->note) && (p->note <= 120))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1617 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1618 if ((p->instr) && (p->instr < MAX_INSTRUMENTS))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1619 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1620 INSTRUMENTHEADER *penv = Headers[p->instr];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1621 if (penv)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1622 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1623 UINT n = penv->Keyboard[p->note-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1624 if (n < MAX_SAMPLES) pbIns[n] = TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1625 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1626 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1627 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1628 for (UINT k=1; k<=m_nInstruments; k++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1629 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1630 INSTRUMENTHEADER *penv = Headers[k];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1631 if (penv)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1632 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1633 UINT n = penv->Keyboard[p->note-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1634 if (n < MAX_SAMPLES) pbIns[n] = TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1635 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1636 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1637 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1638 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1639 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1640 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1641 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1642 for (UINT ichk=1; ichk<=m_nSamples; ichk++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1643 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1644 if ((!pbIns[ichk]) && (Ins[ichk].pSample)) nExt++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1645 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1646 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1647 return nExt;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1648 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1649
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1650
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1651 BOOL CSoundFile::RemoveSelectedSamples(BOOL *pbIns)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1652 //-------------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1653 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1654 if (!pbIns) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1655 for (UINT j=1; j<MAX_SAMPLES; j++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1656 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1657 if ((!pbIns[j]) && (Ins[j].pSample))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1658 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1659 DestroySample(j);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1660 if ((j == m_nSamples) && (j > 1)) m_nSamples--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1661 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1662 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1663 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1664 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1665
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1666
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1667 BOOL CSoundFile::DestroySample(UINT nSample)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1668 //------------------------------------------
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1669 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1670 if ((!nSample) || (nSample >= MAX_SAMPLES)) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1671 if (!Ins[nSample].pSample) return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1672 MODINSTRUMENT *pins = &Ins[nSample];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1673 signed char *pSample = pins->pSample;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1674 pins->pSample = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1675 pins->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1676 pins->uFlags &= ~(CHN_16BIT);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1677 for (UINT i=0; i<MAX_CHANNELS; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1678 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1679 if (Chn[i].pSample == pSample)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1680 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1681 Chn[i].nPos = Chn[i].nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1682 Chn[i].pSample = Chn[i].pCurrentSample = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1683 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1684 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1685 FreeSample(pSample);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1686 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1687 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1688
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1689 #endif // MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1690