Mercurial > audlegacy-plugins
annotate src/modplug/load_wav.cxx @ 2882:15754379dbd5
fixed the remove bonding bug and made it thread safe
author | Paula Stanciu <paula.stanciu@gmail.com> |
---|---|
date | Thu, 07 Aug 2008 20:00:52 +0300 |
parents | 107c1fed3d92 |
children |
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 */ |
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 #include "stdafx.h" |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
8 #include "sndfile.h" |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
9 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
10 #ifndef WAVE_FORMAT_EXTENSIBLE |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
11 #define WAVE_FORMAT_EXTENSIBLE 0xFFFE |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
12 #endif |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
13 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
14 ///////////////////////////////////////////////////////////// |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
15 // WAV file support |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
16 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
17 BOOL CSoundFile::ReadWav(const BYTE *lpStream, DWORD dwMemLength) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
18 //--------------------------------------------------------------- |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
19 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
20 DWORD dwMemPos = 0; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
21 WAVEFILEHEADER phdr; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
22 WAVEFORMATHEADER pfmt; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
23 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
24 if ((!lpStream) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
25 || (dwMemLength < (DWORD)(sizeof(WAVEFORMATHEADER)+sizeof(WAVEFILEHEADER)))) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
26 return FALSE; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
27 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
28 memcpy(&phdr, lpStream, sizeof(phdr)); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
29 memcpy(&pfmt, lpStream+sizeof(phdr), sizeof(pfmt)); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
30 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
31 phdr.id_RIFF = bswapLE32(phdr.id_RIFF); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
32 phdr.filesize = bswapLE32(phdr.filesize); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
33 phdr.id_WAVE = bswapLE32(phdr.id_WAVE); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
34 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
35 pfmt.id_fmt = bswapLE32(pfmt.id_fmt); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
36 pfmt.hdrlen = bswapLE32(pfmt.hdrlen); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
37 pfmt.format = bswapLE16(pfmt.format); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
38 pfmt.channels = bswapLE16(pfmt.channels); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
39 pfmt.freqHz = bswapLE32(pfmt.freqHz); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
40 pfmt.bytessec = bswapLE32(pfmt.bytessec); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
41 pfmt.samplesize = bswapLE16(pfmt.samplesize); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
42 pfmt.bitspersample = bswapLE16(pfmt.bitspersample); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
43 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
44 if ((phdr.id_RIFF != IFFID_RIFF) || (phdr.id_WAVE != IFFID_WAVE) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
45 || (pfmt.id_fmt != IFFID_fmt)) return FALSE; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
46 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
47 dwMemPos = sizeof(WAVEFILEHEADER) + 8 + pfmt.hdrlen; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
48 |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
49 if ((dwMemPos + 8 >= dwMemLength) |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
50 || ((pfmt.format != WAVE_FORMAT_PCM) && (pfmt.format != WAVE_FORMAT_EXTENSIBLE)) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
51 || (pfmt.channels > 4) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
52 || (!pfmt.channels) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
53 || (!pfmt.freqHz) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
54 || (pfmt.bitspersample & 7) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
55 || (pfmt.bitspersample < 8) |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
56 || (pfmt.bitspersample > 32)) return FALSE; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
57 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
58 WAVEDATAHEADER pdata; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
59 |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
60 for (;;) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
61 { |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
62 memcpy(&pdata, lpStream+dwMemPos, sizeof(pdata)); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
63 pdata.id_data = bswapLE32(pdata.id_data); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
64 pdata.length = bswapLE32(pdata.length); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
65 |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
66 if (pdata.id_data == IFFID_data) break; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
67 dwMemPos += pdata.length + 8; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
68 if (dwMemPos + 8 >= dwMemLength) return FALSE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
69 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
70 m_nType = MOD_TYPE_WAV; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
71 m_nSamples = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
72 m_nInstruments = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
73 m_nChannels = 4; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
74 m_nDefaultSpeed = 8; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
75 m_nDefaultTempo = 125; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
76 m_dwSongFlags |= SONG_LINEARSLIDES; // For no resampling |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
77 Order[0] = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
78 Order[1] = 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
79 PatternSize[0] = PatternSize[1] = 64; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
80 PatternAllocSize[0] = PatternAllocSize[1] = 64; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
81 if ((Patterns[0] = AllocatePattern(64, 4)) == NULL) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
82 if ((Patterns[1] = AllocatePattern(64, 4)) == NULL) return TRUE; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
83 UINT samplesize = (pfmt.channels * pfmt.bitspersample) >> 3; |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
84 UINT len = pdata.length, bytelen; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
85 if (dwMemPos + len > dwMemLength - 8) len = dwMemLength - dwMemPos - 8; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
86 len /= samplesize; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
87 bytelen = len; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
88 if (pfmt.bitspersample >= 16) bytelen *= 2; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
89 if (len > MAX_SAMPLE_LENGTH) len = MAX_SAMPLE_LENGTH; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
90 if (!len) return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
91 // Setting up module length |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
92 DWORD dwTime = ((len * 50) / pfmt.freqHz) + 1; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
93 DWORD framesperrow = (dwTime + 63) / 63; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
94 if (framesperrow < 4) framesperrow = 4; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
95 UINT norders = 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
96 while (framesperrow >= 0x20) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
97 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
98 Order[norders++] = 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
99 Order[norders] = 0xFF; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
100 framesperrow = (dwTime + (64 * norders - 1)) / (64 * norders); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
101 if (norders >= MAX_ORDERS-1) break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
102 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
103 m_nDefaultSpeed = framesperrow; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
104 for (UINT iChn=0; iChn<4; iChn++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
105 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
106 ChnSettings[iChn].nPan = (iChn & 1) ? 256 : 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
107 ChnSettings[iChn].nVolume = 64; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
108 ChnSettings[iChn].dwFlags = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
109 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
110 // Setting up speed command |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
111 MODCOMMAND *pcmd = Patterns[0]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
112 pcmd[0].command = CMD_SPEED; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
113 pcmd[0].param = (BYTE)m_nDefaultSpeed; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
114 pcmd[0].note = 5*12+1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
115 pcmd[0].instr = 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
116 pcmd[1].note = pcmd[0].note; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
117 pcmd[1].instr = pcmd[0].instr; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
118 m_nSamples = pfmt.channels; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
119 // Support for Multichannel Wave |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
120 for (UINT nChn=0; nChn<m_nSamples; nChn++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
121 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
122 MODINSTRUMENT *pins = &Ins[nChn+1]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
123 pcmd[nChn].note = pcmd[0].note; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
124 pcmd[nChn].instr = (BYTE)(nChn+1); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
125 pins->nLength = len; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
126 pins->nC4Speed = pfmt.freqHz; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
127 pins->nVolume = 256; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
128 pins->nPan = 128; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
129 pins->nGlobalVol = 64; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
130 pins->uFlags = (WORD)((pfmt.bitspersample >= 16) ? CHN_16BIT : 0); |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
131 pins->uFlags |= CHN_PANNING; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
132 if (m_nSamples > 1) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
133 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
134 switch(nChn) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
135 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
136 case 0: pins->nPan = 0; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
137 case 1: pins->nPan = 256; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
138 case 2: pins->nPan = (WORD)((m_nSamples == 3) ? 128 : 64); pcmd[nChn].command = CMD_S3MCMDEX; pcmd[nChn].param = 0x91; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
139 case 3: pins->nPan = 192; pcmd[nChn].command = CMD_S3MCMDEX; pcmd[nChn].param = 0x91; break; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
140 default: pins->nPan = 128; break; |
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 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
143 if ((pins->pSample = AllocateSample(bytelen+8)) == NULL) return TRUE; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
144 if (pfmt.bitspersample >= 16) |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
145 { |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
146 int slsize = pfmt.bitspersample >> 3; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
147 signed short *p = (signed short *)pins->pSample; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
148 signed char *psrc = (signed char *)(lpStream+dwMemPos+8+nChn*slsize+slsize-2); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
149 for (UINT i=0; i<len; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
150 { |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
151 p[i] = bswapLE16(*((signed short *)psrc)); |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
152 psrc += samplesize; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
153 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
154 p[len+1] = p[len] = p[len-1]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
155 } else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
156 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
157 signed char *p = (signed char *)pins->pSample; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
158 signed char *psrc = (signed char *)(lpStream+dwMemPos+8+nChn); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
159 for (UINT i=0; i<len; i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
160 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
161 p[i] = (signed char)((*psrc) + 0x80); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
162 psrc += samplesize; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
163 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
164 p[len+1] = p[len] = p[len-1]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
165 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
166 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
167 return TRUE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
168 } |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
169 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
170 |
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 // IMA ADPCM Support |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
173 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
174 #pragma pack(1) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
175 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
176 typedef struct IMAADPCMBLOCK |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
177 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
178 WORD sample; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
179 BYTE index; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
180 BYTE Reserved; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
181 } DVI_ADPCMBLOCKHEADER; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
182 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
183 #pragma pack() |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
184 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
185 static const int gIMAUnpackTable[90] = |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
186 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
187 7, 8, 9, 10, 11, 12, 13, 14, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
188 16, 17, 19, 21, 23, 25, 28, 31, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
189 34, 37, 41, 45, 50, 55, 60, 66, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
190 73, 80, 88, 97, 107, 118, 130, 143, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
191 157, 173, 190, 209, 230, 253, 279, 307, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
192 337, 371, 408, 449, 494, 544, 598, 658, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
193 724, 796, 876, 963, 1060, 1166, 1282, 1411, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
194 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
195 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
196 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
197 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
198 32767, 0 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
199 }; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
200 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
201 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
202 BOOL IMAADPCMUnpack16(signed short *pdest, UINT nLen, LPBYTE psrc, DWORD dwBytes, UINT pkBlkAlign) |
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 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
205 static const int gIMAIndexTab[8] = { -1, -1, -1, -1, 2, 4, 6, 8 }; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
206 UINT nPos; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
207 int value; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
208 |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
209 if ((nLen < 4) || (!pdest) || (!psrc) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
210 || (pkBlkAlign < 5) || (pkBlkAlign > dwBytes)) return FALSE; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
211 nPos = 0; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
212 while ((nPos < nLen) && (dwBytes > 4)) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
213 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
214 int nIndex; |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
215 value = bswapLE16(*((short int *)psrc)); |
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
216 nIndex = bswapLE16((short int)psrc[2]); |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
217 psrc += 4; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
218 dwBytes -= 4; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
219 pdest[nPos++] = (short int)value; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
220 for (UINT i=0; ((i<(pkBlkAlign-4)*2) && (nPos < nLen) && (dwBytes)); i++) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
221 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
222 BYTE delta; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
223 if (i & 1) |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
224 { |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
225 delta = (BYTE)(((*(psrc++)) >> 4) & 0x0F); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
226 dwBytes--; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
227 } else |
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 delta = (BYTE)((*psrc) & 0x0F); |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
230 } |
2337
107c1fed3d92
Port Schism modplug core.
"Tony Vroon <chainsaw@gentoo.org>"
parents:
2218
diff
changeset
|
231 int v = gIMAUnpackTable[nIndex % 90] >> 3; |
136
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
232 if (delta & 1) v += gIMAUnpackTable[nIndex] >> 2; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
233 if (delta & 2) v += gIMAUnpackTable[nIndex] >> 1; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
234 if (delta & 4) v += gIMAUnpackTable[nIndex]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
235 if (delta & 8) value -= v; else value += v; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
236 nIndex += gIMAIndexTab[delta & 7]; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
237 if (nIndex < 0) nIndex = 0; else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
238 if (nIndex > 88) nIndex = 88; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
239 if (value > 32767) value = 32767; else |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
240 if (value < -32768) value = -32768; |
6b5a52635b3b
[svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff
changeset
|
241 pdest[nPos++] = (short int)value; |
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 return TRUE; |
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 |