annotate src/modplug/sndmix.cxx @ 2168:3c9527d25346

fix a crash bug in mp4_is_our_file().
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sat, 17 Nov 2007 03:41:41 +0900
parents a76855c7942e
children 3673c7ec4ea2
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 */
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
6
161
4095ceb0440b [svn] - fix libmodplug references
nenolod
parents: 136
diff changeset
7 #include "stdafx.h"
4095ceb0440b [svn] - fix libmodplug references
nenolod
parents: 136
diff changeset
8 #include "sndfile.h"
136
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 #ifdef MODPLUG_TRACKER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
11 #define ENABLE_STEREOVU
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 // Volume ramp length, in 1/10 ms
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
15 #define VOLUMERAMPLEN 146 // 1.46ms = 64 samples at 44.1kHz
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 // VU-Meter
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
18 #define VUMETER_DECAY 4
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 // SNDMIX: These are global flags for playback control
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
21 UINT CSoundFile::m_nStereoSeparation = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
22 LONG CSoundFile::m_nStreamVolume = 0x8000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
23 UINT CSoundFile::m_nMaxMixChannels = 32;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
24 // Mixing Configuration (SetWaveConfig)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
25 DWORD CSoundFile::gdwSysInfo = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
26 DWORD CSoundFile::gnChannels = 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
27 DWORD CSoundFile::gdwSoundSetup = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
28 DWORD CSoundFile::gdwMixingFreq = 44100;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
29 DWORD CSoundFile::gnBitsPerSample = 16;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
30 // Mixing data initialized in
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
31 UINT CSoundFile::gnAGC = AGC_UNITY;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
32 UINT CSoundFile::gnVolumeRampSamples = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
33 UINT CSoundFile::gnVUMeter = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
34 UINT CSoundFile::gnCPUUsage = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
35 LPSNDMIXHOOKPROC CSoundFile::gpSndMixHook = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
36 PMIXPLUGINCREATEPROC CSoundFile::gpMixPluginCreateProc = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
37 LONG gnDryROfsVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
38 LONG gnDryLOfsVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
39 LONG gnRvbROfsVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
40 LONG gnRvbLOfsVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
41 int gbInitPlugins = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
42
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
43 typedef DWORD (MPPASMCALL * LPCONVERTPROC)(LPVOID, int *, DWORD, LPLONG, LPLONG);
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 extern DWORD MPPASMCALL X86_Convert32To8(LPVOID lpBuffer, int *, DWORD nSamples, LPLONG, LPLONG);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
46 extern DWORD MPPASMCALL X86_Convert32To16(LPVOID lpBuffer, int *, DWORD nSamples, LPLONG, LPLONG);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
47 extern DWORD MPPASMCALL X86_Convert32To24(LPVOID lpBuffer, int *, DWORD nSamples, LPLONG, LPLONG);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
48 extern DWORD MPPASMCALL X86_Convert32To32(LPVOID lpBuffer, int *, DWORD nSamples, LPLONG, LPLONG);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
49 extern UINT MPPASMCALL X86_AGC(int *pBuffer, UINT nSamples, UINT nAGC);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
50 extern VOID MPPASMCALL X86_Dither(int *pBuffer, UINT nSamples, UINT nBits);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
51 extern VOID MPPASMCALL X86_InterleaveFrontRear(int *pFrontBuf, int *pRearBuf, DWORD nSamples);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
52 extern VOID MPPASMCALL X86_StereoFill(int *pBuffer, UINT nSamples, LPLONG lpROfs, LPLONG lpLOfs);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
53 extern VOID MPPASMCALL X86_MonoFromStereo(int *pMixBuf, UINT nSamples);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
54
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
55 extern short int ModSinusTable[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
56 extern short int ModRampDownTable[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
57 extern short int ModSquareTable[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
58 extern short int ModRandomTable[64];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
59 extern DWORD LinearSlideUpTable[256];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
60 extern DWORD LinearSlideDownTable[256];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
61 extern DWORD FineLinearSlideUpTable[16];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
62 extern DWORD FineLinearSlideDownTable[16];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
63 extern signed char ft2VibratoTable[256]; // -64 .. +64
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
64 extern int MixSoundBuffer[MIXBUFFERSIZE*4];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
65 extern int MixRearBuffer[MIXBUFFERSIZE*2];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
66 UINT gnReverbSend;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
67
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
68
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
69 // Log tables for pre-amp
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
70 // We don't want the tracker to get too loud
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
71 const UINT PreAmpTable[16] =
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
72 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
73 0x60, 0x60, 0x60, 0x70, // 0-7
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
74 0x80, 0x88, 0x90, 0x98, // 8-15
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
75 0xA0, 0xA4, 0xA8, 0xB0, // 16-23
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
76 0xB4, 0xB8, 0xBC, 0xC0, // 24-31
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
77 };
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 const UINT PreAmpAGCTable[16] =
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 0x60, 0x60, 0x60, 0x60,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
82 0x68, 0x70, 0x78, 0x80,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
83 0x84, 0x88, 0x8C, 0x90,
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
84 0x94, 0x98, 0x9C, 0xA0,
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 // Return (a*b)/c - no divide error
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
89 int _muldiv(long a, long b, long c)
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 #ifdef MSC_VER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
92 int sign, result;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
93 _asm {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
94 mov eax, a
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
95 mov ebx, b
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
96 or eax, eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
97 mov edx, eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
98 jge aneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
99 neg eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
100 aneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
101 xor edx, ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
102 or ebx, ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
103 mov ecx, c
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
104 jge bneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
105 neg ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
106 bneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
107 xor edx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
108 or ecx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
109 mov sign, edx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
110 jge cneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
111 neg ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
112 cneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
113 mul ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
114 cmp edx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
115 jae diverr
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
116 div ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
117 jmp ok
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
118 diverr:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
119 mov eax, 0x7fffffff
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
120 ok:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
121 mov edx, sign
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
122 or edx, edx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
123 jge rneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
124 neg eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
125 rneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
126 mov result, eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
127 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
128 return result;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
129 #else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
130 return ((unsigned long long) a * (unsigned long long) b ) / c;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
131 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
132 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
135 // Return (a*b+c/2)/c - no divide error
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
136 int _muldivr(long a, long b, long c)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
137 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
138 #ifdef MSC_VER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
139 int sign, result;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
140 _asm {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
141 mov eax, a
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
142 mov ebx, b
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
143 or eax, eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
144 mov edx, eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
145 jge aneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
146 neg eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
147 aneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
148 xor edx, ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
149 or ebx, ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
150 mov ecx, c
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
151 jge bneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
152 neg ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
153 bneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
154 xor edx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
155 or ecx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
156 mov sign, edx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
157 jge cneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
158 neg ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
159 cneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
160 mul ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
161 mov ebx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
162 shr ebx, 1
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
163 add eax, ebx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
164 adc edx, 0
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
165 cmp edx, ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
166 jae diverr
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
167 div ecx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
168 jmp ok
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
169 diverr:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
170 mov eax, 0x7fffffff
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
171 ok:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
172 mov edx, sign
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
173 or edx, edx
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
174 jge rneg
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
175 neg eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
176 rneg:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
177 mov result, eax
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
178 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
179 return result;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
180 #else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
181 return ((unsigned long long) a * (unsigned long long) b + (c >> 1)) / c;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
182 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
183 }
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
186 BOOL CSoundFile::InitPlayer(BOOL bReset)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
189 if (m_nMaxMixChannels > MAX_CHANNELS) m_nMaxMixChannels = MAX_CHANNELS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
190 if (gdwMixingFreq < 4000) gdwMixingFreq = 4000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
191 if (gdwMixingFreq > MAX_SAMPLE_RATE) gdwMixingFreq = MAX_SAMPLE_RATE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
192 gnVolumeRampSamples = (gdwMixingFreq * VOLUMERAMPLEN) / 100000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
193 if (gnVolumeRampSamples < 8) gnVolumeRampSamples = 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
194 gnDryROfsVol = gnDryLOfsVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
195 gnRvbROfsVol = gnRvbLOfsVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
196 if (bReset)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
197 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
198 gnVUMeter = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
199 gnCPUUsage = 0;
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 gbInitPlugins = (bReset) ? 3 : 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
202 InitializeDSP(bReset);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
203 return TRUE;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
206
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
207 BOOL CSoundFile::FadeSong(UINT msec)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
210 LONG nsamples = _muldiv(msec, gdwMixingFreq, 1000);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
211 if (nsamples <= 0) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
212 if (nsamples > 0x100000) nsamples = 0x100000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
213 m_nBufferCount = nsamples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
214 LONG nRampLength = m_nBufferCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
215 // Ramp everything down
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
216 for (UINT noff=0; noff < m_nMixChannels; noff++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
217 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
218 MODCHANNEL *pramp = &Chn[ChnMix[noff]];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
219 if (!pramp) continue;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
220 pramp->nNewLeftVol = pramp->nNewRightVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
221 pramp->nRightRamp = (-pramp->nRightVol << VOLUMERAMPPRECISION) / nRampLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
222 pramp->nLeftRamp = (-pramp->nLeftVol << VOLUMERAMPPRECISION) / nRampLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
223 pramp->nRampRightVol = pramp->nRightVol << VOLUMERAMPPRECISION;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
224 pramp->nRampLeftVol = pramp->nLeftVol << VOLUMERAMPPRECISION;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
225 pramp->nRampLength = nRampLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
226 pramp->dwFlags |= CHN_VOLUMERAMP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
227 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
228 m_dwSongFlags |= SONG_FADINGSONG;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
229 return TRUE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
230 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
231
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
232
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
233 BOOL CSoundFile::GlobalFadeSong(UINT msec)
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 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
236 if (m_dwSongFlags & SONG_GLOBALFADE) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
237 m_nGlobalFadeMaxSamples = _muldiv(msec, gdwMixingFreq, 1000);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
238 m_nGlobalFadeSamples = m_nGlobalFadeMaxSamples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
239 m_dwSongFlags |= SONG_GLOBALFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
240 return TRUE;
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 UINT CSoundFile::Read(LPVOID lpDestBuffer, UINT cbBuffer)
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 LPBYTE lpBuffer = (LPBYTE)lpDestBuffer;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
248 LPCONVERTPROC pCvt = X86_Convert32To8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
249 UINT lRead, lMax, lSampleSize, lCount, lSampleCount, nStat=0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
250 LONG nVUMeterMin = 0x7FFFFFFF, nVUMeterMax = -0x7FFFFFFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
251 UINT nMaxPlugins;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
252
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 nMaxPlugins = MAX_MIXPLUGINS;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
255 while ((nMaxPlugins > 0) && (!m_MixPlugins[nMaxPlugins-1].pMixPlugin)) nMaxPlugins--;
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 m_nMixStat = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
258 lSampleSize = gnChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
259 if (gnBitsPerSample == 16) { lSampleSize *= 2; pCvt = X86_Convert32To16; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
260 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
261 else if (gnBitsPerSample == 24) { lSampleSize *= 3; pCvt = X86_Convert32To24; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
262 else if (gnBitsPerSample == 32) { lSampleSize *= 4; pCvt = X86_Convert32To32; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
263 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
264 lMax = cbBuffer / lSampleSize;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
265 if ((!lMax) || (!lpBuffer) || (!m_nChannels)) return 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
266 lRead = lMax;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
267 if (m_dwSongFlags & SONG_ENDREACHED) goto MixDone;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
268 while (lRead > 0)
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 // Update Channel Data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
271 if (!m_nBufferCount)
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 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
274 if (m_dwSongFlags & SONG_FADINGSONG)
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 m_dwSongFlags |= SONG_ENDREACHED;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
277 m_nBufferCount = lRead;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
278 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
279 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
280 if (!ReadNote())
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 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
283 if (!FadeSong(FADESONGDELAY))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
284 #endif
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_dwSongFlags |= SONG_ENDREACHED;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
287 if (lRead == lMax) goto MixDone;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
288 m_nBufferCount = lRead;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
291 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
292 lCount = m_nBufferCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
293 if (lCount > MIXBUFFERSIZE) lCount = MIXBUFFERSIZE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
294 if (lCount > lRead) lCount = lRead;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
295 if (!lCount) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
296 lSampleCount = lCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
297 #ifndef MODPLUG_NO_REVERB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
298 gnReverbSend = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
299 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
300 // Resetting sound buffer
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
301 X86_StereoFill(MixSoundBuffer, lSampleCount, &gnDryROfsVol, &gnDryLOfsVol);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
302 if (gnChannels >= 2)
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 lSampleCount *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
305 m_nMixStat += CreateStereoMix(lCount);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
306 ProcessStereoDSP(lCount);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
307 } else
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 m_nMixStat += CreateStereoMix(lCount);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
310 ProcessStereoDSP(lCount);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
311 X86_MonoFromStereo(MixSoundBuffer, lCount);
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 nStat++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
314 #ifndef NO_AGC
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
315 // Automatic Gain Control
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
316 if (gdwSoundSetup & SNDMIX_AGC) ProcessAGC(lSampleCount);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
317 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
318 UINT lTotalSampleCount = lSampleCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
319 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
320 // Multichannel
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
321 if (gnChannels > 2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
322 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
323 X86_InterleaveFrontRear(MixSoundBuffer, MixRearBuffer, lSampleCount);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
324 lTotalSampleCount *= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
325 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
326 // Hook Function
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
327 if (gpSndMixHook)
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 gpSndMixHook(MixSoundBuffer, lTotalSampleCount, gnChannels);
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 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
332 // Perform clipping + VU-Meter
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
333 lpBuffer += pCvt(lpBuffer, MixSoundBuffer, lTotalSampleCount, &nVUMeterMin, &nVUMeterMax);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
334 // Buffer ready
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
335 lRead -= lCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
336 m_nBufferCount -= lCount;
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 MixDone:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
339 if (lRead) memset(lpBuffer, (gnBitsPerSample == 8) ? 0x80 : 0, lRead * lSampleSize);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
340 // VU-Meter
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
341 nVUMeterMin >>= (24-MIXING_ATTENUATION);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
342 nVUMeterMax >>= (24-MIXING_ATTENUATION);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
343 if (nVUMeterMax < nVUMeterMin) nVUMeterMax = nVUMeterMin;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
344 if ((gnVUMeter = (UINT)(nVUMeterMax - nVUMeterMin)) > 0xFF) gnVUMeter = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
345 if (nStat) { m_nMixStat += nStat-1; m_nMixStat /= nStat; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
346 return lMax - lRead;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
347 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
348
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
349
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
350
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
351 /////////////////////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
352 // Handles navigation/effects
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
353
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
354 BOOL CSoundFile::ProcessRow()
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 if (++m_nTickCount >= m_nMusicSpeed * (m_nPatternDelay+1) + m_nFrameDelay)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
358 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
359 m_nPatternDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
360 m_nFrameDelay = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
361 m_nTickCount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
362 m_nRow = m_nNextRow;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
363 // Reset Pattern Loop Effect
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
364 if (m_nCurrentPattern != m_nNextPattern) m_nCurrentPattern = m_nNextPattern;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
365 // Check if pattern is valid
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
366 if (!(m_dwSongFlags & SONG_PATTERNLOOP))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
367 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
368 m_nPattern = (m_nCurrentPattern < MAX_ORDERS) ? Order[m_nCurrentPattern] : 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
369 if ((m_nPattern < MAX_PATTERNS) && (!Patterns[m_nPattern])) m_nPattern = 0xFE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
370 while (m_nPattern >= MAX_PATTERNS)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
371 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
372 // End of song ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
373 if ((m_nPattern == 0xFF) || (m_nCurrentPattern >= MAX_ORDERS))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
374 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
375 //if (!m_nRepeatCount)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
376 return FALSE; //never repeat entire song
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
377 if (!m_nRestartPos)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
378 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
379 m_nMusicSpeed = m_nDefaultSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
380 m_nMusicTempo = m_nDefaultTempo;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
381 m_nGlobalVolume = m_nDefaultGlobalVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
382 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
383 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
384 Chn[i].dwFlags |= CHN_NOTEFADE | CHN_KEYOFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
385 Chn[i].nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
386 if (i < m_nChannels)
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 Chn[i].nGlobalVol = ChnSettings[i].nVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
389 Chn[i].nVolume = ChnSettings[i].nVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
390 Chn[i].nPan = ChnSettings[i].nPan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
391 Chn[i].nPanSwing = Chn[i].nVolSwing = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
392 Chn[i].nOldVolParam = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
393 Chn[i].nOldOffset = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
394 Chn[i].nOldHiOffset = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
395 Chn[i].nPortamentoDest = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
396 if (!Chn[i].nLength)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
397 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
398 Chn[i].dwFlags = ChnSettings[i].dwFlags;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
399 Chn[i].nLoopStart = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
400 Chn[i].nLoopEnd = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
401 Chn[i].pHeader = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
402 Chn[i].pSample = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
403 Chn[i].pInstrument = NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
404 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
405 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
406 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
407 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
408 // if (m_nRepeatCount > 0) m_nRepeatCount--;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
409 m_nCurrentPattern = m_nRestartPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
410 m_nRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
411 if ((Order[m_nCurrentPattern] >= MAX_PATTERNS) || (!Patterns[Order[m_nCurrentPattern]])) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
412 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
413 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
414 m_nCurrentPattern++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
415 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
416 m_nPattern = (m_nCurrentPattern < MAX_ORDERS) ? Order[m_nCurrentPattern] : 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
417 if ((m_nPattern < MAX_PATTERNS) && (!Patterns[m_nPattern])) m_nPattern = 0xFE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
418 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
419 m_nNextPattern = m_nCurrentPattern;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
420 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
421 // Weird stuff?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
422 if ((m_nPattern >= MAX_PATTERNS) || (!Patterns[m_nPattern])) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
423 // Should never happen
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
424 if (m_nRow >= PatternSize[m_nPattern]) m_nRow = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
425 m_nNextRow = m_nRow + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
426 if (m_nNextRow >= PatternSize[m_nPattern])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
427 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
428 if (!(m_dwSongFlags & SONG_PATTERNLOOP)) m_nNextPattern = m_nCurrentPattern + 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
429 m_nNextRow = 0;
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 // Reset channel values
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
432 MODCHANNEL *pChn = Chn;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
433 MODCOMMAND *m = Patterns[m_nPattern] + m_nRow * m_nChannels;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
434 for (UINT nChn=0; nChn<m_nChannels; pChn++, nChn++, m++)
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 pChn->nRowNote = m->note;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
437 pChn->nRowInstr = m->instr;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
438 pChn->nRowVolCmd = m->volcmd;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
439 pChn->nRowVolume = m->vol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
440 pChn->nRowCommand = m->command;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
441 pChn->nRowParam = m->param;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
442
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
443 pChn->nLeftVol = pChn->nNewLeftVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
444 pChn->nRightVol = pChn->nNewRightVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
445 pChn->dwFlags &= ~(CHN_PORTAMENTO | CHN_VIBRATO | CHN_TREMOLO | CHN_PANBRELLO);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
446 pChn->nCommand = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
447 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
448 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
449 // Should we process tick0 effects?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
450 if (!m_nMusicSpeed) m_nMusicSpeed = 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
451 m_dwSongFlags |= SONG_FIRSTTICK;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
452 if (m_nTickCount)
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 m_dwSongFlags &= ~SONG_FIRSTTICK;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
455 if ((!(m_nType & MOD_TYPE_XM)) && (m_nTickCount < m_nMusicSpeed * (1 + m_nPatternDelay)))
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 if (!(m_nTickCount % m_nMusicSpeed)) m_dwSongFlags |= SONG_FIRSTTICK;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
458 }
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
461 // Update Effects
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
462 return ProcessEffects();
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
463 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
464
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
465
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 // Handles envelopes & mixer setup
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
468
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
469 BOOL CSoundFile::ReadNote()
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 if (!ProcessRow()) return FALSE;
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 m_nTotalCount++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
475 if (!m_nMusicTempo) return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
476 m_nBufferCount = (gdwMixingFreq * 5 * m_nTempoFactor) / (m_nMusicTempo << 8);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
477 // Master Volume + Pre-Amplification / Attenuation setup
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
478 DWORD nMasterVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
479 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
480 int nchn32 = (m_nChannels < 32) ? m_nChannels : 31;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
481 if ((m_nType & MOD_TYPE_IT) && (m_nInstruments) && (nchn32 < 6)) nchn32 = 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
482 int realmastervol = m_nMasterVolume;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
483 if (realmastervol > 0x80)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
484 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
485 realmastervol = 0x80 + ((realmastervol - 0x80) * (nchn32+4)) / 16;
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 UINT attenuation = (gdwSoundSetup & SNDMIX_AGC) ? PreAmpAGCTable[nchn32>>1] : PreAmpTable[nchn32>>1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
488 DWORD mastervol = (realmastervol * (m_nSongPreAmp + 0x10)) >> 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
489 if (mastervol > 0x200) mastervol = 0x200;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
490 if ((m_dwSongFlags & SONG_GLOBALFADE) && (m_nGlobalFadeMaxSamples))
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 mastervol = _muldiv(mastervol, m_nGlobalFadeSamples, m_nGlobalFadeMaxSamples);
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 nMasterVol = (mastervol << 7) / attenuation;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
495 if (nMasterVol > 0x180) nMasterVol = 0x180;
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 ////////////////////////////////////////////////////////////////////////////////////
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
498 // Update channels data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
499 m_nMixChannels = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
500 MODCHANNEL *pChn = Chn;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
501 for (UINT nChn=0; nChn<MAX_CHANNELS; nChn++,pChn++)
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 if ((pChn->dwFlags & CHN_NOTEFADE) && (!(pChn->nFadeOutVol|pChn->nRightVol|pChn->nLeftVol)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
504 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
505 pChn->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
506 pChn->nROfs = pChn->nLOfs = 0;
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 // Check for unused channel
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
509 if ((pChn->dwFlags & CHN_MUTE) || ((nChn >= m_nChannels) && (!pChn->nLength)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
510 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
511 pChn->nVUMeter = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
512 #ifdef ENABLE_STEREOVU
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
513 pChn->nLeftVU = pChn->nRightVU = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
514 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
515 continue;
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 // Reset channel data
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
518 pChn->nInc = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
519 pChn->nRealVolume = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
520 pChn->nRealPan = pChn->nPan + pChn->nPanSwing;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
521 if (pChn->nRealPan < 0) pChn->nRealPan = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
522 if (pChn->nRealPan > 256) pChn->nRealPan = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
523 pChn->nRampLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
524 // Calc Frequency
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
525 if ((pChn->nPeriod) && (pChn->nLength))
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 int vol = pChn->nVolume + pChn->nVolSwing;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
528
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
529 if (vol < 0) vol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
530 if (vol > 256) vol = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
531 // Tremolo
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
532 if (pChn->dwFlags & CHN_TREMOLO)
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 trempos = pChn->nTremoloPos & 0x3F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
535 if (vol > 0)
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 int tremattn = (m_nType & MOD_TYPE_XM) ? 5 : 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
538 switch (pChn->nTremoloType & 0x03)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
539 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
540 case 1:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
541 vol += (ModRampDownTable[trempos] * (int)pChn->nTremoloDepth) >> tremattn;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
542 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
543 case 2:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
544 vol += (ModSquareTable[trempos] * (int)pChn->nTremoloDepth) >> tremattn;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
545 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
546 case 3:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
547 vol += (ModRandomTable[trempos] * (int)pChn->nTremoloDepth) >> tremattn;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
548 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
549 default:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
550 vol += (ModSinusTable[trempos] * (int)pChn->nTremoloDepth) >> tremattn;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
553 if ((m_nTickCount) || ((m_nType & (MOD_TYPE_STM|MOD_TYPE_S3M|MOD_TYPE_IT)) && (!(m_dwSongFlags & SONG_ITOLDEFFECTS))))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
554 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
555 pChn->nTremoloPos = (trempos + pChn->nTremoloSpeed) & 0x3F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
556 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
557 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
558 // Tremor
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
559 if (pChn->nCommand == CMD_TREMOR)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
560 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
561 UINT n = (pChn->nTremorParam >> 4) + (pChn->nTremorParam & 0x0F);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
562 UINT ontime = pChn->nTremorParam >> 4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
563 if ((!(m_nType & MOD_TYPE_IT)) || (m_dwSongFlags & SONG_ITOLDEFFECTS)) { n += 2; ontime++; }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
564 UINT tremcount = (UINT)pChn->nTremorCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
565 if (tremcount >= n) tremcount = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
566 if ((m_nTickCount) || (m_nType & (MOD_TYPE_S3M|MOD_TYPE_IT)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
567 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
568 if (tremcount >= ontime) vol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
569 pChn->nTremorCount = (BYTE)(tremcount + 1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
570 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
571 pChn->dwFlags |= CHN_FASTVOLRAMP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
572 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
573 // Clip volume
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
574 if (vol < 0) vol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
575 if (vol > 0x100) vol = 0x100;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
576 vol <<= 6;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
577 // Process Envelopes
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
578 if (pChn->pHeader)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
579 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
580 INSTRUMENTHEADER *penv = pChn->pHeader;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
581 // Volume Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
582 if ((pChn->dwFlags & CHN_VOLENV) && (penv->nVolEnv))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
583 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
584 int envpos = pChn->nVolEnvPosition;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
585 UINT pt = penv->nVolEnv - 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
586 for (UINT i=0; i<(UINT)(penv->nVolEnv-1); i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
587 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
588 if (envpos <= penv->VolPoints[i])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
589 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
590 pt = i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
591 break;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
594 int x2 = penv->VolPoints[pt];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
595 int x1, envvol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
596 if (envpos >= x2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
597 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
598 envvol = penv->VolEnv[pt] << 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
599 x1 = x2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
600 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
601 if (pt)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
602 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
603 envvol = penv->VolEnv[pt-1] << 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
604 x1 = penv->VolPoints[pt-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
605 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
606 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
607 envvol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
608 x1 = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
609 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
610 if (envpos > x2) envpos = x2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
611 if ((x2 > x1) && (envpos > x1))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
612 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
613 envvol += ((envpos - x1) * (((int)penv->VolEnv[pt]<<2) - envvol)) / (x2 - x1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
614 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
615 if (envvol < 0) envvol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
616 if (envvol > 256) envvol = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
617 vol = (vol * envvol) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
618 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
619 // Panning Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
620 if ((pChn->dwFlags & CHN_PANENV) && (penv->nPanEnv))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
621 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
622 int envpos = pChn->nPanEnvPosition;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
623 UINT pt = penv->nPanEnv - 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
624 for (UINT i=0; i<(UINT)(penv->nPanEnv-1); i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
625 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
626 if (envpos <= penv->PanPoints[i])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
627 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
628 pt = i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
629 break;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
632 int x2 = penv->PanPoints[pt], y2 = penv->PanEnv[pt];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
633 int x1, envpan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
634 if (envpos >= x2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
635 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
636 envpan = y2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
637 x1 = x2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
638 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
639 if (pt)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
640 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
641 envpan = penv->PanEnv[pt-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
642 x1 = penv->PanPoints[pt-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
643 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
644 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
645 envpan = 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
646 x1 = 0;
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 if ((x2 > x1) && (envpos > x1))
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 envpan += ((envpos - x1) * (y2 - envpan)) / (x2 - x1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
651 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
652 if (envpan < 0) envpan = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
653 if (envpan > 64) envpan = 64;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
654 int pan = pChn->nPan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
655 if (pan >= 128)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
656 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
657 pan += ((envpan - 32) * (256 - pan)) / 32;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
658 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
659 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
660 pan += ((envpan - 32) * (pan)) / 32;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
661 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
662 if (pan < 0) pan = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
663 if (pan > 256) pan = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
664 pChn->nRealPan = pan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
665 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
666 // FadeOut volume
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
667 if (pChn->dwFlags & CHN_NOTEFADE)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
668 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
669 UINT fadeout = penv->nFadeOut;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
670 if (fadeout)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
671 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
672 pChn->nFadeOutVol -= fadeout << 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
673 if (pChn->nFadeOutVol <= 0) pChn->nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
674 vol = (vol * pChn->nFadeOutVol) >> 16;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
675 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
676 if (!pChn->nFadeOutVol)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
677 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
678 vol = 0;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
681 // Pitch/Pan separation
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
682 if ((penv->nPPS) && (pChn->nRealPan) && (pChn->nNote))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
683 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
684 int pandelta = (int)pChn->nRealPan + (int)((int)(pChn->nNote - penv->nPPC - 1) * (int)penv->nPPS) / (int)8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
685 if (pandelta < 0) pandelta = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
686 if (pandelta > 256) pandelta = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
687 pChn->nRealPan = pandelta;
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 } else
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 // No Envelope: key off => note cut
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
692 if (pChn->dwFlags & CHN_NOTEFADE) // 1.41-: CHN_KEYOFF|CHN_NOTEFADE
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
693 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
694 pChn->nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
695 vol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
696 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
697 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
698 // vol is 14-bits
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
699 if (vol)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
700 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
701 // IMPORTANT: pChn->nRealVolume is 14 bits !!!
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
702 // -> _muldiv( 14+8, 6+6, 18); => RealVolume: 14-bit result (22+12-20)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
703 pChn->nRealVolume = _muldiv(vol * m_nGlobalVolume, pChn->nGlobalVol * pChn->nInsVol, 1 << 20);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
704 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
705 if (pChn->nPeriod < m_nMinPeriod) pChn->nPeriod = m_nMinPeriod;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
706 int period = pChn->nPeriod;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
707 if ((pChn->dwFlags & (CHN_GLISSANDO|CHN_PORTAMENTO)) == (CHN_GLISSANDO|CHN_PORTAMENTO))
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 period = GetPeriodFromNote(GetNoteFromPeriod(period), pChn->nFineTune, pChn->nC4Speed);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
710 }
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 // Arpeggio ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
713 if (pChn->nCommand == CMD_ARPEGGIO)
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 switch(m_nTickCount % 3)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
716 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
717 case 1: period = GetPeriodFromNote(pChn->nNote + (pChn->nArpeggio >> 4), pChn->nFineTune, pChn->nC4Speed); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
718 case 2: period = GetPeriodFromNote(pChn->nNote + (pChn->nArpeggio & 0x0F), pChn->nFineTune, pChn->nC4Speed); break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
719 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
720 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
721
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
722 if (m_dwSongFlags & SONG_AMIGALIMITS)
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 if (period < 113*4) period = 113*4;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
725 if (period > 856*4) period = 856*4;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
728 // Pitch/Filter Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
729 if ((pChn->pHeader) && (pChn->dwFlags & CHN_PITCHENV) && (pChn->pHeader->nPitchEnv))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
730 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
731 INSTRUMENTHEADER *penv = pChn->pHeader;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
732 int envpos = pChn->nPitchEnvPosition;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
733 UINT pt = penv->nPitchEnv - 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
734 for (UINT i=0; i<(UINT)(penv->nPitchEnv-1); i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
735 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
736 if (envpos <= penv->PitchPoints[i])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
737 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
738 pt = i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
739 break;
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 int x2 = penv->PitchPoints[pt];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
743 int x1, envpitch;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
744 if (envpos >= x2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
745 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
746 envpitch = (((int)penv->PitchEnv[pt]) - 32) * 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
747 x1 = x2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
748 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
749 if (pt)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
750 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
751 envpitch = (((int)penv->PitchEnv[pt-1]) - 32) * 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
752 x1 = penv->PitchPoints[pt-1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
753 } else
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 envpitch = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
756 x1 = 0;
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 if (envpos > x2) envpos = x2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
759 if ((x2 > x1) && (envpos > x1))
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 int envpitchdest = (((int)penv->PitchEnv[pt]) - 32) * 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
762 envpitch += ((envpos - x1) * (envpitchdest - envpitch)) / (x2 - x1);
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 if (envpitch < -256) envpitch = -256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
765 if (envpitch > 256) envpitch = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
766 // Filter Envelope: controls cutoff frequency
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
767 if (penv->dwFlags & ENV_FILTER)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
768 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
769 #ifndef NO_FILTER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
770 SetupChannelFilter(pChn, (pChn->dwFlags & CHN_FILTER) ? FALSE : TRUE, envpitch);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
771 #endif // NO_FILTER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
772 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
773 // Pitch Envelope
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 int l = envpitch;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
776 if (l < 0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
777 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
778 l = -l;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
779 if (l > 255) l = 255;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
780 period = _muldiv(period, LinearSlideUpTable[l], 0x10000);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
781 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
782 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
783 if (l > 255) l = 255;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
784 period = _muldiv(period, LinearSlideDownTable[l], 0x10000);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
785 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
786 }
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 // Vibrato
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
790 if (pChn->dwFlags & CHN_VIBRATO)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
791 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
792 UINT vibpos = pChn->nVibratoPos;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
793 LONG vdelta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
794 switch (pChn->nVibratoType & 0x03)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
795 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
796 case 1:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
797 vdelta = ModRampDownTable[vibpos];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
798 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
799 case 2:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
800 vdelta = ModSquareTable[vibpos];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
801 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
802 case 3:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
803 vdelta = ModRandomTable[vibpos];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
804 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
805 default:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
806 vdelta = ModSinusTable[vibpos];
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 UINT vdepth = ((m_nType != MOD_TYPE_IT) || (m_dwSongFlags & SONG_ITOLDEFFECTS)) ? 6 : 7;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
809 vdelta = (vdelta * (int)pChn->nVibratoDepth) >> vdepth;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
810 if ((m_dwSongFlags & SONG_LINEARSLIDES) && (m_nType & MOD_TYPE_IT))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
811 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
812 LONG l = vdelta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
813 if (l < 0)
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 l = -l;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
816 vdelta = _muldiv(period, LinearSlideDownTable[l >> 2], 0x10000) - period;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
817 if (l & 0x03) vdelta += _muldiv(period, FineLinearSlideDownTable[l & 0x03], 0x10000) - period;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
818
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
819 } else
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 vdelta = _muldiv(period, LinearSlideUpTable[l >> 2], 0x10000) - period;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
822 if (l & 0x03) vdelta += _muldiv(period, FineLinearSlideUpTable[l & 0x03], 0x10000) - period;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
823
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
824 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
825 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
826 period += vdelta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
827 if ((m_nTickCount) || ((m_nType & MOD_TYPE_IT) && (!(m_dwSongFlags & SONG_ITOLDEFFECTS))))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
828 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
829 pChn->nVibratoPos = (vibpos + pChn->nVibratoSpeed) & 0x3F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
830 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
831 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
832 // Panbrello
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
833 if (pChn->dwFlags & CHN_PANBRELLO)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
834 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
835 UINT panpos = ((pChn->nPanbrelloPos+0x10) >> 2) & 0x3F;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
836 LONG pdelta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
837 switch (pChn->nPanbrelloType & 0x03)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
838 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
839 case 1:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
840 pdelta = ModRampDownTable[panpos];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
841 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
842 case 2:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
843 pdelta = ModSquareTable[panpos];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
844 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
845 case 3:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
846 pdelta = ModRandomTable[panpos];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
847 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
848 default:
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
849 pdelta = ModSinusTable[panpos];
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 pChn->nPanbrelloPos += pChn->nPanbrelloSpeed;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
852 pdelta = ((pdelta * (int)pChn->nPanbrelloDepth) + 2) >> 3;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
853 pdelta += pChn->nRealPan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
854 if (pdelta < 0) pdelta = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
855 if (pdelta > 256) pdelta = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
856 pChn->nRealPan = pdelta;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
857 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
858 int nPeriodFrac = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
859 // Instrument Auto-Vibrato
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
860 if ((pChn->pInstrument) && (pChn->pInstrument->nVibDepth))
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 MODINSTRUMENT *pins = pChn->pInstrument;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
863 if (pins->nVibSweep == 0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
864 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
865 pChn->nAutoVibDepth = pins->nVibDepth << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
866 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
867 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
868 if (m_nType & MOD_TYPE_IT)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
869 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
870 pChn->nAutoVibDepth += pins->nVibSweep << 3;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
871 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
872 if (!(pChn->dwFlags & CHN_KEYOFF))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
873 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
874 pChn->nAutoVibDepth += (pins->nVibDepth << 8) / pins->nVibSweep;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
875 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
876 if ((pChn->nAutoVibDepth >> 8) > pins->nVibDepth)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
877 pChn->nAutoVibDepth = pins->nVibDepth << 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
878 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
879 pChn->nAutoVibPos += pins->nVibRate;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
880 int val;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
881 switch(pins->nVibType)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
882 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
883 case 4: // Random
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
884 val = ModRandomTable[pChn->nAutoVibPos & 0x3F];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
885 pChn->nAutoVibPos++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
886 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
887 case 3: // Ramp Down
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
888 val = ((0x40 - (pChn->nAutoVibPos >> 1)) & 0x7F) - 0x40;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
889 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
890 case 2: // Ramp Up
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
891 val = ((0x40 + (pChn->nAutoVibPos >> 1)) & 0x7f) - 0x40;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
892 break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
893 case 1: // Square
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
894 val = (pChn->nAutoVibPos & 128) ? +64 : -64;
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 default: // Sine
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
897 val = ft2VibratoTable[pChn->nAutoVibPos & 255];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
898 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
899 int n = ((val * pChn->nAutoVibDepth) >> 8);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
900 if (m_nType & MOD_TYPE_IT)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
901 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
902 int df1, df2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
903 if (n < 0)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
904 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
905 n = -n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
906 UINT n1 = n >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
907 df1 = LinearSlideUpTable[n1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
908 df2 = LinearSlideUpTable[n1+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
909 } else
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 UINT n1 = n >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
912 df1 = LinearSlideDownTable[n1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
913 df2 = LinearSlideDownTable[n1+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
914 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
915 n >>= 2;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
916 period = _muldiv(period, df1 + ((df2-df1)*(n&0x3F)>>6), 256);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
917 nPeriodFrac = period & 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
918 period >>= 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
919 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
920 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
921 period += (n >> 6);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
922 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
923 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
924 // Final Period
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
925 if (period <= m_nMinPeriod)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
926 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
927 if (m_nType & MOD_TYPE_S3M) pChn->nLength = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
928 period = m_nMinPeriod;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
929 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
930 if (period > m_nMaxPeriod)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
931 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
932 if ((m_nType & MOD_TYPE_IT) || (period >= 0x100000))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
933 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
934 pChn->nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
935 pChn->dwFlags |= CHN_NOTEFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
936 pChn->nRealVolume = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
937 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
938 period = m_nMaxPeriod;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
939 nPeriodFrac = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
940 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
941 UINT freq = GetFreqFromPeriod(period, pChn->nC4Speed, nPeriodFrac);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
942 if ((m_nType & MOD_TYPE_IT) && (freq < 256))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
943 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
944 pChn->nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
945 pChn->dwFlags |= CHN_NOTEFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
946 pChn->nRealVolume = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
947 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
948 UINT ninc = _muldiv(freq, 0x10000, gdwMixingFreq);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
949 if ((ninc >= 0xFFB0) && (ninc <= 0x10090)) ninc = 0x10000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
950 if (m_nFreqFactor != 128) ninc = (ninc * m_nFreqFactor) >> 7;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
951 if (ninc > 0xFF0000) ninc = 0xFF0000;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
952 pChn->nInc = (ninc+1) & ~3;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
953 }
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 // Increment envelope position
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
956 if (pChn->pHeader)
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 INSTRUMENTHEADER *penv = pChn->pHeader;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
959 // Volume Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
960 if (pChn->dwFlags & CHN_VOLENV)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
961 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
962 // Increase position
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
963 pChn->nVolEnvPosition++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
964 // Volume Loop ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
965 if (penv->dwFlags & ENV_VOLLOOP)
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 UINT volloopend = penv->VolPoints[penv->nVolLoopEnd];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
968 if (m_nType != MOD_TYPE_XM) volloopend++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
969 if (pChn->nVolEnvPosition == volloopend)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
970 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
971 pChn->nVolEnvPosition = penv->VolPoints[penv->nVolLoopStart];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
972 if ((penv->nVolLoopEnd == penv->nVolLoopStart) && (!penv->VolEnv[penv->nVolLoopStart])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
973 && ((!(m_nType & MOD_TYPE_XM)) || (penv->nVolLoopEnd+1 == penv->nVolEnv)))
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 pChn->dwFlags |= CHN_NOTEFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
976 pChn->nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
977 }
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
980 // Volume Sustain ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
981 if ((penv->dwFlags & ENV_VOLSUSTAIN) && (!(pChn->dwFlags & CHN_KEYOFF)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
982 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
983 if (pChn->nVolEnvPosition == (UINT)penv->VolPoints[penv->nVolSustainEnd]+1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
984 pChn->nVolEnvPosition = penv->VolPoints[penv->nVolSustainBegin];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
985 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
986 // End of Envelope ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
987 if (pChn->nVolEnvPosition > penv->VolPoints[penv->nVolEnv - 1])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
988 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
989 if ((m_nType & MOD_TYPE_IT) || (pChn->dwFlags & CHN_KEYOFF)) pChn->dwFlags |= CHN_NOTEFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
990 pChn->nVolEnvPosition = penv->VolPoints[penv->nVolEnv - 1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
991 if ((!penv->VolEnv[penv->nVolEnv-1]) && ((nChn >= m_nChannels) || (m_nType & MOD_TYPE_IT)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
992 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
993 pChn->dwFlags |= CHN_NOTEFADE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
994 pChn->nFadeOutVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
995
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
996 pChn->nRealVolume = 0;
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 }
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 // Panning Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1001 if (pChn->dwFlags & CHN_PANENV)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1002 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1003 pChn->nPanEnvPosition++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1004 if (penv->dwFlags & ENV_PANLOOP)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1005 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1006 UINT panloopend = penv->PanPoints[penv->nPanLoopEnd];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1007 if (m_nType != MOD_TYPE_XM) panloopend++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1008 if (pChn->nPanEnvPosition == panloopend)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1009 pChn->nPanEnvPosition = penv->PanPoints[penv->nPanLoopStart];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1010 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1011 // Panning Sustain ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1012 if ((penv->dwFlags & ENV_PANSUSTAIN) && (pChn->nPanEnvPosition == (UINT)penv->PanPoints[penv->nPanSustainEnd]+1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1013 && (!(pChn->dwFlags & CHN_KEYOFF)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1014 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1015 // Panning sustained
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1016 pChn->nPanEnvPosition = penv->PanPoints[penv->nPanSustainBegin];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1017 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1018 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1019 if (pChn->nPanEnvPosition > penv->PanPoints[penv->nPanEnv - 1])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1020 pChn->nPanEnvPosition = penv->PanPoints[penv->nPanEnv - 1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1021 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1022 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1023 // Pitch Envelope
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1024 if (pChn->dwFlags & CHN_PITCHENV)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1025 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1026 // Increase position
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1027 pChn->nPitchEnvPosition++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1028 // Pitch Loop ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1029 if (penv->dwFlags & ENV_PITCHLOOP)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1030 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1031 if (pChn->nPitchEnvPosition >= penv->PitchPoints[penv->nPitchLoopEnd])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1032 pChn->nPitchEnvPosition = penv->PitchPoints[penv->nPitchLoopStart];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1033 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1034 // Pitch Sustain ?
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1035 if ((penv->dwFlags & ENV_PITCHSUSTAIN) && (!(pChn->dwFlags & CHN_KEYOFF)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1036 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1037 if (pChn->nPitchEnvPosition == (UINT)penv->PitchPoints[penv->nPitchSustainEnd]+1)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1038 pChn->nPitchEnvPosition = penv->PitchPoints[penv->nPitchSustainBegin];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1039 } else
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 if (pChn->nPitchEnvPosition > penv->PitchPoints[penv->nPitchEnv - 1])
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1042 pChn->nPitchEnvPosition = penv->PitchPoints[penv->nPitchEnv - 1];
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 }
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 #ifdef MODPLUG_PLAYER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1047 // Limit CPU -> > 80% -> don't ramp
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1048 if ((gnCPUUsage >= 80) && (!pChn->nRealVolume))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1049 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1050 pChn->nLeftVol = pChn->nRightVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1051 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1052 #endif // MODPLUG_PLAYER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1053 // Volume ramping
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1054 pChn->dwFlags &= ~CHN_VOLUMERAMP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1055 if ((pChn->nRealVolume) || (pChn->nLeftVol) || (pChn->nRightVol))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1056 pChn->dwFlags |= CHN_VOLUMERAMP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1057 #ifdef MODPLUG_PLAYER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1058 // Decrease VU-Meter
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1059 if (pChn->nVUMeter > VUMETER_DECAY) pChn->nVUMeter -= VUMETER_DECAY; else pChn->nVUMeter = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1060 #endif // MODPLUG_PLAYER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1061 #ifdef ENABLE_STEREOVU
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1062 if (pChn->nLeftVU > VUMETER_DECAY) pChn->nLeftVU -= VUMETER_DECAY; else pChn->nLeftVU = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1063 if (pChn->nRightVU > VUMETER_DECAY) pChn->nRightVU -= VUMETER_DECAY; else pChn->nRightVU = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1064 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1065 // Check for too big nInc
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1066 if (((pChn->nInc >> 16) + 1) >= (LONG)(pChn->nLoopEnd - pChn->nLoopStart)) pChn->dwFlags &= ~CHN_LOOP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1067 pChn->nNewRightVol = pChn->nNewLeftVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1068 pChn->pCurrentSample = ((pChn->pSample) && (pChn->nLength) && (pChn->nInc)) ? pChn->pSample : NULL;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1069 if (pChn->pCurrentSample)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1070 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1071 // Update VU-Meter (nRealVolume is 14-bit)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1072 #ifdef MODPLUG_PLAYER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1073 UINT vutmp = pChn->nRealVolume >> (14 - 8);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1074 if (vutmp > 0xFF) vutmp = 0xFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1075 if (pChn->nVUMeter >= 0x100) pChn->nVUMeter = vutmp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1076 vutmp >>= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1077 if (pChn->nVUMeter < vutmp) pChn->nVUMeter = vutmp;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1078 #endif // MODPLUG_PLAYER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1079 #ifdef ENABLE_STEREOVU
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1080 UINT vul = (pChn->nRealVolume * pChn->nRealPan) >> 14;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1081 if (vul > 127) vul = 127;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1082 if (pChn->nLeftVU > 127) pChn->nLeftVU = (BYTE)vul;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1083 vul >>= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1084 if (pChn->nLeftVU < vul) pChn->nLeftVU = (BYTE)vul;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1085 UINT vur = (pChn->nRealVolume * (256-pChn->nRealPan)) >> 14;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1086 if (vur > 127) vur = 127;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1087 if (pChn->nRightVU > 127) pChn->nRightVU = (BYTE)vur;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1088 vur >>= 1;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1089 if (pChn->nRightVU < vur) pChn->nRightVU = (BYTE)vur;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1090 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1091 #ifdef MODPLUG_TRACKER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1092 UINT kChnMasterVol = (pChn->dwFlags & CHN_EXTRALOUD) ? 0x100 : nMasterVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1093 #else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1094 #define kChnMasterVol nMasterVol
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1095 #endif // MODPLUG_TRACKER
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1096 // Adjusting volumes
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1097 if (gnChannels >= 2)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1098 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1099 int pan = ((int)pChn->nRealPan) - 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1100 pan *= (int)m_nStereoSeparation;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1101 pan /= 128;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1102 pan += 128;
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 if (pan < 0) pan = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1105 if (pan > 256) pan = 256;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1106 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1107 if (gdwSoundSetup & SNDMIX_REVERSESTEREO) pan = 256 - pan;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1108 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1109 LONG realvol = (pChn->nRealVolume * kChnMasterVol) >> (8-1);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1110 if (gdwSoundSetup & SNDMIX_SOFTPANNING)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1111 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1112 if (pan < 128)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1113 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1114 pChn->nNewLeftVol = (realvol * pan) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1115 pChn->nNewRightVol = (realvol * 128) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1116 } else
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 pChn->nNewLeftVol = (realvol * 128) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1119 pChn->nNewRightVol = (realvol * (256 - pan)) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1120 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1121 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1122 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1123 pChn->nNewLeftVol = (realvol * pan) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1124 pChn->nNewRightVol = (realvol * (256 - pan)) >> 8;
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 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1127 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1128 pChn->nNewRightVol = (pChn->nRealVolume * kChnMasterVol) >> 8;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1129 pChn->nNewLeftVol = pChn->nNewRightVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1130 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1131 // Clipping volumes
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1132 if (pChn->nNewRightVol > 0xFFFF) pChn->nNewRightVol = 0xFFFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1133 if (pChn->nNewLeftVol > 0xFFFF) pChn->nNewLeftVol = 0xFFFF;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1134 // Check IDO
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1135 if (gdwSoundSetup & SNDMIX_NORESAMPLING)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1136 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1137 pChn->dwFlags |= CHN_NOIDO;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1138 } else
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 pChn->dwFlags &= ~(CHN_NOIDO|CHN_HQSRC);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1141 if( pChn->nInc == 0x10000 )
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1142 { pChn->dwFlags |= CHN_NOIDO;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1143 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1144 else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1145 { if( ((gdwSoundSetup & SNDMIX_HQRESAMPLER) == 0) && ((gdwSoundSetup & SNDMIX_ULTRAHQSRCMODE) == 0) )
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1146 { if (pChn->nInc >= 0xFF00) pChn->dwFlags |= CHN_NOIDO;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1147 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1148 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1149 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1150 pChn->nNewRightVol >>= MIXING_ATTENUATION;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1151 pChn->nNewLeftVol >>= MIXING_ATTENUATION;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1152 pChn->nRightRamp = pChn->nLeftRamp = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1153 // Dolby Pro-Logic Surround
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1154 if ((pChn->dwFlags & CHN_SURROUND) && (gnChannels <= 2)) pChn->nNewLeftVol = - pChn->nNewLeftVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1155 // Checking Ping-Pong Loops
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1156 if (pChn->dwFlags & CHN_PINGPONGFLAG) pChn->nInc = -pChn->nInc;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1157 // Setting up volume ramp
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1158 if ((pChn->dwFlags & CHN_VOLUMERAMP)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1159 && ((pChn->nRightVol != pChn->nNewRightVol)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1160 || (pChn->nLeftVol != pChn->nNewLeftVol)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1161 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1162 LONG nRampLength = gnVolumeRampSamples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1163 LONG nRightDelta = ((pChn->nNewRightVol - pChn->nRightVol) << VOLUMERAMPPRECISION);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1164 LONG nLeftDelta = ((pChn->nNewLeftVol - pChn->nLeftVol) << VOLUMERAMPPRECISION);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1165 #ifndef MODPLUG_FASTSOUNDLIB
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1166 if ((gdwSoundSetup & SNDMIX_DIRECTTODISK)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1167 || ((gdwSysInfo & (SYSMIX_ENABLEMMX|SYSMIX_FASTCPU))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1168 && (gdwSoundSetup & SNDMIX_HQRESAMPLER) && (gnCPUUsage <= 20)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1169 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1170 if ((pChn->nRightVol|pChn->nLeftVol) && (pChn->nNewRightVol|pChn->nNewLeftVol) && (!(pChn->dwFlags & CHN_FASTVOLRAMP)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1171 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1172 nRampLength = m_nBufferCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1173 if (nRampLength > (1 << (VOLUMERAMPPRECISION-1))) nRampLength = (1 << (VOLUMERAMPPRECISION-1));
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1174 if (nRampLength < (LONG)gnVolumeRampSamples) nRampLength = gnVolumeRampSamples;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1175 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1176 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1177 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1178 pChn->nRightRamp = nRightDelta / nRampLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1179 pChn->nLeftRamp = nLeftDelta / nRampLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1180 pChn->nRightVol = pChn->nNewRightVol - ((pChn->nRightRamp * nRampLength) >> VOLUMERAMPPRECISION);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1181 pChn->nLeftVol = pChn->nNewLeftVol - ((pChn->nLeftRamp * nRampLength) >> VOLUMERAMPPRECISION);
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1182 if (pChn->nRightRamp|pChn->nLeftRamp)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1183 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1184 pChn->nRampLength = nRampLength;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1185 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1186 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1187 pChn->dwFlags &= ~CHN_VOLUMERAMP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1188 pChn->nRightVol = pChn->nNewRightVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1189 pChn->nLeftVol = pChn->nNewLeftVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1190 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1191 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1192 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1193 pChn->dwFlags &= ~CHN_VOLUMERAMP;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1194 pChn->nRightVol = pChn->nNewRightVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1195 pChn->nLeftVol = pChn->nNewLeftVol;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1196 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1197 pChn->nRampRightVol = pChn->nRightVol << VOLUMERAMPPRECISION;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1198 pChn->nRampLeftVol = pChn->nLeftVol << VOLUMERAMPPRECISION;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1199 // Adding the channel in the channel list
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1200 ChnMix[m_nMixChannels++] = nChn;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1201 if (m_nMixChannels >= MAX_CHANNELS) break;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1202 } else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1203 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1204 #ifdef ENABLE_STEREOVU
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1205 // Note change but no sample
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1206 if (pChn->nLeftVU > 128) pChn->nLeftVU = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1207 if (pChn->nRightVU > 128) pChn->nRightVU = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1208 #endif
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1209 if (pChn->nVUMeter > 0xFF) pChn->nVUMeter = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1210 pChn->nLeftVol = pChn->nRightVol = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1211 pChn->nLength = 0;
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 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1214 // Checking Max Mix Channels reached: ordering by volume
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1215 if ((m_nMixChannels >= m_nMaxMixChannels) && (!(gdwSoundSetup & SNDMIX_DIRECTTODISK)))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1216 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1217 for (UINT i=0; i<m_nMixChannels; i++)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1218 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1219 UINT j=i;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1220 while ((j+1<m_nMixChannels) && (Chn[ChnMix[j]].nRealVolume < Chn[ChnMix[j+1]].nRealVolume))
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1221 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1222 UINT n = ChnMix[j];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1223 ChnMix[j] = ChnMix[j+1];
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1224 ChnMix[j+1] = n;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1225 j++;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1226 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1227 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1228 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1229 if (m_dwSongFlags & SONG_GLOBALFADE)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1230 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1231 if (!m_nGlobalFadeSamples)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1232 {
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1233 m_dwSongFlags |= SONG_ENDREACHED;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1234 return FALSE;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1235 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1236 if (m_nGlobalFadeSamples > m_nBufferCount)
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1237 m_nGlobalFadeSamples -= m_nBufferCount;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1238 else
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1239 m_nGlobalFadeSamples = 0;
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1240 }
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1241 return TRUE;
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
6b5a52635b3b [svn] - like with so many other things, modplug is now maintained by us.
nenolod
parents:
diff changeset
1244