diff options
Diffstat (limited to 'apps/plugins/mikmod/virtch_common.c')
-rw-r--r-- | apps/plugins/mikmod/virtch_common.c | 193 |
1 files changed, 102 insertions, 91 deletions
diff --git a/apps/plugins/mikmod/virtch_common.c b/apps/plugins/mikmod/virtch_common.c index e13f6d1c51..3395120a47 100644 --- a/apps/plugins/mikmod/virtch_common.c +++ b/apps/plugins/mikmod/virtch_common.c | |||
@@ -6,12 +6,12 @@ | |||
6 | it under the terms of the GNU Library General Public License as | 6 | it under the terms of the GNU Library General Public License as |
7 | published by the Free Software Foundation; either version 2 of | 7 | published by the Free Software Foundation; either version 2 of |
8 | the License, or (at your option) any later version. | 8 | the License, or (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU Library General Public License for more details. | 13 | GNU Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public | 15 | You should have received a copy of the GNU Library General Public |
16 | License along with this library; if not, write to the Free Software | 16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
@@ -20,90 +20,96 @@ | |||
20 | 20 | ||
21 | /*============================================================================== | 21 | /*============================================================================== |
22 | 22 | ||
23 | $Id: virtch_common.c,v 1.2 2005/03/30 19:11:50 realtech Exp $ | 23 | $Id$ |
24 | 24 | ||
25 | Common source parts between the two software mixers. | 25 | Common source parts between the two software mixers. |
26 | This file is probably the ugliest part of libmikmod... | 26 | This file is probably the ugliest part of libmikmod... |
27 | 27 | ||
28 | ==============================================================================*/ | 28 | ==============================================================================*/ |
29 | 29 | ||
30 | #ifndef _IN_VIRTCH_ | 30 | #if defined(HAVE_CONFIG_H) && !defined(_IN_VIRTCH_) /* config.h isn't guarded */ |
31 | 31 | #include "config.h" | |
32 | #endif | ||
32 | #include "mikmod_internals.h" | 33 | #include "mikmod_internals.h" |
33 | 34 | ||
34 | extern int VC1_Init(void); | 35 | #ifndef NO_HQMIXER |
35 | //extern int VC2_Init(void); | 36 | extern ULONG VC1_SilenceBytes(SBYTE*,ULONG); |
36 | static int (*VC_Init_ptr)(void)=VC1_Init; | 37 | extern ULONG VC2_SilenceBytes(SBYTE*,ULONG); |
38 | extern ULONG VC1_WriteBytes(SBYTE*,ULONG); | ||
39 | extern ULONG VC2_WriteBytes(SBYTE*,ULONG); | ||
37 | extern void VC1_Exit(void); | 40 | extern void VC1_Exit(void); |
38 | //extern void VC2_Exit(void); | 41 | extern void VC2_Exit(void); |
39 | static void (*VC_Exit_ptr)(void)=VC1_Exit; | 42 | extern UWORD VC1_VoiceGetVolume(UBYTE); |
40 | extern int VC1_SetNumVoices(void); | 43 | extern UWORD VC2_VoiceGetVolume(UBYTE); |
41 | //extern int VC2_SetNumVoices(void); | 44 | extern ULONG VC1_VoiceGetPanning(UBYTE); |
42 | static int (*VC_SetNumVoices_ptr)(void); | 45 | extern ULONG VC2_VoiceGetPanning(UBYTE); |
46 | extern void VC1_VoiceSetFrequency(UBYTE,ULONG); | ||
47 | extern void VC2_VoiceSetFrequency(UBYTE,ULONG); | ||
48 | extern ULONG VC1_VoiceGetFrequency(UBYTE); | ||
49 | extern ULONG VC2_VoiceGetFrequency(UBYTE); | ||
50 | extern void VC1_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); | ||
51 | extern void VC2_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); | ||
52 | extern void VC1_VoiceStop(UBYTE); | ||
53 | extern void VC2_VoiceStop(UBYTE); | ||
54 | extern int VC1_VoiceStopped(UBYTE); | ||
55 | extern int VC2_VoiceStopped(UBYTE); | ||
56 | extern SLONG VC1_VoiceGetPosition(UBYTE); | ||
57 | extern SLONG VC2_VoiceGetPosition(UBYTE); | ||
58 | extern void VC1_VoiceSetVolume(UBYTE,UWORD); | ||
59 | extern void VC2_VoiceSetVolume(UBYTE,UWORD); | ||
60 | extern void VC1_VoiceSetPanning(UBYTE,ULONG); | ||
61 | extern void VC2_VoiceSetPanning(UBYTE,ULONG); | ||
62 | extern void VC1_SampleUnload(SWORD); | ||
63 | extern void VC2_SampleUnload(SWORD); | ||
64 | extern SWORD VC1_SampleLoad(struct SAMPLOAD*,int); | ||
65 | extern SWORD VC2_SampleLoad(struct SAMPLOAD*,int); | ||
43 | extern ULONG VC1_SampleSpace(int); | 66 | extern ULONG VC1_SampleSpace(int); |
44 | //extern ULONG VC2_SampleSpace(int); | 67 | extern ULONG VC2_SampleSpace(int); |
45 | static ULONG (*VC_SampleSpace_ptr)(int); | ||
46 | extern ULONG VC1_SampleLength(int,SAMPLE*); | 68 | extern ULONG VC1_SampleLength(int,SAMPLE*); |
47 | //extern ULONG VC2_SampleLength(int,SAMPLE*); | 69 | extern ULONG VC2_SampleLength(int,SAMPLE*); |
70 | extern ULONG VC1_VoiceRealVolume(UBYTE); | ||
71 | extern ULONG VC2_VoiceRealVolume(UBYTE); | ||
72 | #endif | ||
73 | |||
74 | |||
75 | #ifndef _IN_VIRTCH_ | ||
76 | |||
77 | #ifndef NO_HQMIXER | ||
78 | extern int VC1_Init(void); | ||
79 | extern int VC2_Init(void); | ||
80 | static int (*VC_Init_ptr)(void)=VC1_Init; | ||
81 | static void (*VC_Exit_ptr)(void)=VC1_Exit; | ||
82 | extern int VC1_SetNumVoices(void); | ||
83 | extern int VC2_SetNumVoices(void); | ||
84 | static int (*VC_SetNumVoices_ptr)(void); | ||
85 | static ULONG (*VC_SampleSpace_ptr)(int); | ||
48 | static ULONG (*VC_SampleLength_ptr)(int,SAMPLE*); | 86 | static ULONG (*VC_SampleLength_ptr)(int,SAMPLE*); |
49 | 87 | ||
50 | extern int VC1_PlayStart(void); | 88 | extern int VC2_PlayStart(void); |
51 | //extern int VC2_PlayStart(void); | 89 | static int (*VC_PlayStart_ptr)(void); |
52 | static int (*VC_PlayStart_ptr)(void); | ||
53 | extern void VC1_PlayStop(void); | ||
54 | extern void VC2_PlayStop(void); | 90 | extern void VC2_PlayStop(void); |
55 | static void (*VC_PlayStop_ptr)(void); | 91 | static void (*VC_PlayStop_ptr)(void); |
56 | 92 | ||
57 | extern SWORD VC1_SampleLoad(struct SAMPLOAD*,int); | ||
58 | //extern SWORD VC2_SampleLoad(struct SAMPLOAD*,int); | ||
59 | static SWORD (*VC_SampleLoad_ptr)(struct SAMPLOAD*,int); | 93 | static SWORD (*VC_SampleLoad_ptr)(struct SAMPLOAD*,int); |
60 | extern void VC1_SampleUnload(SWORD); | ||
61 | //extern void VC2_SampleUnload(SWORD); | ||
62 | static void (*VC_SampleUnload_ptr)(SWORD); | 94 | static void (*VC_SampleUnload_ptr)(SWORD); |
63 | 95 | ||
64 | extern ULONG VC1_WriteBytes(SBYTE*,ULONG); | ||
65 | //extern ULONG VC2_WriteBytes(SBYTE*,ULONG); | ||
66 | static ULONG (*VC_WriteBytes_ptr)(SBYTE*,ULONG); | 96 | static ULONG (*VC_WriteBytes_ptr)(SBYTE*,ULONG); |
67 | extern ULONG VC1_SilenceBytes(SBYTE*,ULONG); | ||
68 | //extern ULONG VC2_SilenceBytes(SBYTE*,ULONG); | ||
69 | static ULONG (*VC_SilenceBytes_ptr)(SBYTE*,ULONG); | 97 | static ULONG (*VC_SilenceBytes_ptr)(SBYTE*,ULONG); |
70 | 98 | ||
71 | extern void VC1_VoiceSetVolume(UBYTE,UWORD); | ||
72 | //extern void VC2_VoiceSetVolume(UBYTE,UWORD); | ||
73 | static void (*VC_VoiceSetVolume_ptr)(UBYTE,UWORD); | 99 | static void (*VC_VoiceSetVolume_ptr)(UBYTE,UWORD); |
74 | extern UWORD VC1_VoiceGetVolume(UBYTE); | ||
75 | //extern UWORD VC2_VoiceGetVolume(UBYTE); | ||
76 | static UWORD (*VC_VoiceGetVolume_ptr)(UBYTE); | 100 | static UWORD (*VC_VoiceGetVolume_ptr)(UBYTE); |
77 | extern void VC1_VoiceSetFrequency(UBYTE,ULONG); | ||
78 | //extern void VC2_VoiceSetFrequency(UBYTE,ULONG); | ||
79 | static void (*VC_VoiceSetFrequency_ptr)(UBYTE,ULONG); | 101 | static void (*VC_VoiceSetFrequency_ptr)(UBYTE,ULONG); |
80 | extern ULONG VC1_VoiceGetFrequency(UBYTE); | ||
81 | //extern ULONG VC2_VoiceGetFrequency(UBYTE); | ||
82 | static ULONG (*VC_VoiceGetFrequency_ptr)(UBYTE); | 102 | static ULONG (*VC_VoiceGetFrequency_ptr)(UBYTE); |
83 | extern void VC1_VoiceSetPanning(UBYTE,ULONG); | ||
84 | //extern void VC2_VoiceSetPanning(UBYTE,ULONG); | ||
85 | static void (*VC_VoiceSetPanning_ptr)(UBYTE,ULONG); | 103 | static void (*VC_VoiceSetPanning_ptr)(UBYTE,ULONG); |
86 | extern ULONG VC1_VoiceGetPanning(UBYTE); | ||
87 | //extern ULONG VC2_VoiceGetPanning(UBYTE); | ||
88 | static ULONG (*VC_VoiceGetPanning_ptr)(UBYTE); | 104 | static ULONG (*VC_VoiceGetPanning_ptr)(UBYTE); |
89 | extern void VC1_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); | ||
90 | //extern void VC2_VoicePlay(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); | ||
91 | static void (*VC_VoicePlay_ptr)(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); | 105 | static void (*VC_VoicePlay_ptr)(UBYTE,SWORD,ULONG,ULONG,ULONG,ULONG,UWORD); |
92 | 106 | ||
93 | extern void VC1_VoiceStop(UBYTE); | ||
94 | //extern void VC2_VoiceStop(UBYTE); | ||
95 | static void (*VC_VoiceStop_ptr)(UBYTE); | 107 | static void (*VC_VoiceStop_ptr)(UBYTE); |
96 | extern int VC1_VoiceStopped(UBYTE); | ||
97 | //extern int VC2_VoiceStopped(UBYTE); | ||
98 | static int (*VC_VoiceStopped_ptr)(UBYTE); | 108 | static int (*VC_VoiceStopped_ptr)(UBYTE); |
99 | extern SLONG VC1_VoiceGetPosition(UBYTE); | ||
100 | //extern SLONG VC2_VoiceGetPosition(UBYTE); | ||
101 | static SLONG (*VC_VoiceGetPosition_ptr)(UBYTE); | 109 | static SLONG (*VC_VoiceGetPosition_ptr)(UBYTE); |
102 | extern ULONG VC1_VoiceRealVolume(UBYTE); | ||
103 | //extern ULONG VC2_VoiceRealVolume(UBYTE); | ||
104 | static ULONG (*VC_VoiceRealVolume_ptr)(UBYTE); | 110 | static ULONG (*VC_VoiceRealVolume_ptr)(UBYTE); |
105 | 111 | ||
106 | #if defined __STDC__ || defined _MSC_VER || defined MPW_C | 112 | #if defined __STDC__ || defined _MSC_VER || defined __WATCOMC__ || defined MPW_C |
107 | #define VC_PROC0(suffix) \ | 113 | #define VC_PROC0(suffix) \ |
108 | MIKMODAPI void VC_##suffix (void) { VC_##suffix##_ptr(); } | 114 | MIKMODAPI void VC_##suffix (void) { VC_##suffix##_ptr(); } |
109 | 115 | ||
@@ -121,7 +127,9 @@ MIKMODAPI void VC_##suffix (typ1 a,typ2 b) { VC_##suffix##_ptr(a,b); } | |||
121 | 127 | ||
122 | #define VC_FUNC2(suffix,ret,typ1,typ2) \ | 128 | #define VC_FUNC2(suffix,ret,typ1,typ2) \ |
123 | MIKMODAPI ret VC_##suffix (typ1 a,typ2 b) { return VC_##suffix##_ptr(a,b); } | 129 | MIKMODAPI ret VC_##suffix (typ1 a,typ2 b) { return VC_##suffix##_ptr(a,b); } |
130 | |||
124 | #else | 131 | #else |
132 | |||
125 | #define VC_PROC0(suffix) \ | 133 | #define VC_PROC0(suffix) \ |
126 | MIKMODAPI void VC_/**/suffix (void) { VC_/**/suffix/**/_ptr(); } | 134 | MIKMODAPI void VC_/**/suffix (void) { VC_/**/suffix/**/_ptr(); } |
127 | 135 | ||
@@ -158,18 +166,18 @@ VC_PROC2(VoiceSetFrequency,UBYTE,ULONG) | |||
158 | VC_FUNC1(VoiceGetFrequency,ULONG,UBYTE) | 166 | VC_FUNC1(VoiceGetFrequency,ULONG,UBYTE) |
159 | VC_PROC2(VoiceSetPanning,UBYTE,ULONG) | 167 | VC_PROC2(VoiceSetPanning,UBYTE,ULONG) |
160 | VC_FUNC1(VoiceGetPanning,ULONG,UBYTE) | 168 | VC_FUNC1(VoiceGetPanning,ULONG,UBYTE) |
161 | 169 | ||
162 | void VC_VoicePlay(UBYTE a,SWORD b,ULONG c,ULONG d,ULONG e,ULONG f,UWORD g) | 170 | void VC_VoicePlay(UBYTE a,SWORD b,ULONG c,ULONG d,ULONG e,ULONG f,UWORD g) { |
163 | { VC_VoicePlay_ptr(a,b,c,d,e,f,g); } | 171 | VC_VoicePlay_ptr(a,b,c,d,e,f,g); |
172 | } | ||
164 | 173 | ||
165 | VC_PROC1(VoiceStop,UBYTE) | 174 | VC_PROC1(VoiceStop,UBYTE) |
166 | VC_FUNC1(VoiceStopped,int,UBYTE) | 175 | VC_FUNC1(VoiceStopped,int,UBYTE) |
167 | VC_FUNC1(VoiceGetPosition,SLONG,UBYTE) | 176 | VC_FUNC1(VoiceGetPosition,SLONG,UBYTE) |
168 | VC_FUNC1(VoiceRealVolume,ULONG,UBYTE) | 177 | VC_FUNC1(VoiceRealVolume,ULONG,UBYTE) |
169 | 178 | ||
170 | void VC_SetupPointers(void) | 179 | void VC_SetupPointers(void) |
171 | { | 180 | { |
172 | /* | ||
173 | if (md_mode&DMODE_HQMIXER) { | 181 | if (md_mode&DMODE_HQMIXER) { |
174 | VC_Init_ptr=VC2_Init; | 182 | VC_Init_ptr=VC2_Init; |
175 | VC_Exit_ptr=VC2_Exit; | 183 | VC_Exit_ptr=VC2_Exit; |
@@ -194,7 +202,6 @@ void VC_SetupPointers(void) | |||
194 | VC_VoiceGetPosition_ptr=VC2_VoiceGetPosition; | 202 | VC_VoiceGetPosition_ptr=VC2_VoiceGetPosition; |
195 | VC_VoiceRealVolume_ptr=VC2_VoiceRealVolume; | 203 | VC_VoiceRealVolume_ptr=VC2_VoiceRealVolume; |
196 | } else { | 204 | } else { |
197 | */ | ||
198 | VC_Init_ptr=VC1_Init; | 205 | VC_Init_ptr=VC1_Init; |
199 | VC_Exit_ptr=VC1_Exit; | 206 | VC_Exit_ptr=VC1_Exit; |
200 | VC_SetNumVoices_ptr=VC1_SetNumVoices; | 207 | VC_SetNumVoices_ptr=VC1_SetNumVoices; |
@@ -217,10 +224,11 @@ void VC_SetupPointers(void) | |||
217 | VC_VoiceStopped_ptr=VC1_VoiceStopped; | 224 | VC_VoiceStopped_ptr=VC1_VoiceStopped; |
218 | VC_VoiceGetPosition_ptr=VC1_VoiceGetPosition; | 225 | VC_VoiceGetPosition_ptr=VC1_VoiceGetPosition; |
219 | VC_VoiceRealVolume_ptr=VC1_VoiceRealVolume; | 226 | VC_VoiceRealVolume_ptr=VC1_VoiceRealVolume; |
220 | //} | 227 | } |
221 | } | 228 | } |
229 | #endif/* !NO_HQMIXER */ | ||
222 | 230 | ||
223 | #else | 231 | #else /* _IN_VIRTCH_ */ |
224 | 232 | ||
225 | #ifndef _VIRTCH_COMMON_ | 233 | #ifndef _VIRTCH_COMMON_ |
226 | #define _VIRTCH_COMMON_ | 234 | #define _VIRTCH_COMMON_ |
@@ -248,9 +256,7 @@ ULONG VC1_SilenceBytes(SBYTE* buf,ULONG todo) | |||
248 | todo=samples2bytes(bytes2samples(todo)); | 256 | todo=samples2bytes(bytes2samples(todo)); |
249 | 257 | ||
250 | /* clear the buffer to zero (16 bits signed) or 0x80 (8 bits unsigned) */ | 258 | /* clear the buffer to zero (16 bits signed) or 0x80 (8 bits unsigned) */ |
251 | if(vc_mode & DMODE_FLOAT) | 259 | if(vc_mode &(DMODE_16BITS|DMODE_FLOAT)) |
252 | memset(buf,0,todo); | ||
253 | else if(vc_mode & DMODE_16BITS) | ||
254 | memset(buf,0,todo); | 260 | memset(buf,0,todo); |
255 | else | 261 | else |
256 | memset(buf,0x80,todo); | 262 | memset(buf,0x80,todo); |
@@ -276,14 +282,14 @@ ULONG VC1_WriteBytes(SBYTE* buf,ULONG todo) | |||
276 | 282 | ||
277 | void VC1_Exit(void) | 283 | void VC1_Exit(void) |
278 | { | 284 | { |
279 | if(vc_tickbuf) MikMod_free(vc_tickbuf); | 285 | MikMod_free(vinf); |
280 | if(vinf) MikMod_free(vinf); | 286 | MikMod_afree(vc_tickbuf); |
281 | if(Samples) MikMod_free(Samples); | 287 | MikMod_afree(Samples); |
282 | 288 | ||
283 | vc_tickbuf = NULL; | 289 | vc_tickbuf = NULL; |
284 | vinf = NULL; | 290 | vinf = NULL; |
285 | Samples = NULL; | 291 | Samples = NULL; |
286 | 292 | ||
287 | VC_SetupPointers(); | 293 | VC_SetupPointers(); |
288 | } | 294 | } |
289 | 295 | ||
@@ -309,19 +315,19 @@ ULONG VC1_VoiceGetFrequency(UBYTE voice) | |||
309 | 315 | ||
310 | void VC1_VoicePlay(UBYTE voice,SWORD handle,ULONG start,ULONG size,ULONG reppos,ULONG repend,UWORD flags) | 316 | void VC1_VoicePlay(UBYTE voice,SWORD handle,ULONG start,ULONG size,ULONG reppos,ULONG repend,UWORD flags) |
311 | { | 317 | { |
312 | vinf[voice].flags = flags; | 318 | vinf[voice].flags = flags; |
313 | vinf[voice].handle = handle; | 319 | vinf[voice].handle = handle; |
314 | vinf[voice].start = start; | 320 | vinf[voice].start = start; |
315 | vinf[voice].size = size; | 321 | vinf[voice].size = size; |
316 | vinf[voice].reppos = reppos; | 322 | vinf[voice].reppos = reppos; |
317 | vinf[voice].repend = repend; | 323 | vinf[voice].repend = repend; |
318 | vinf[voice].kick = 1; | 324 | vinf[voice].kick = 1; |
319 | } | 325 | } |
320 | 326 | ||
321 | void VC1_VoiceStop(UBYTE voice) | 327 | void VC1_VoiceStop(UBYTE voice) |
322 | { | 328 | { |
323 | vinf[voice].active = 0; | 329 | vinf[voice].active = 0; |
324 | } | 330 | } |
325 | 331 | ||
326 | int VC1_VoiceStopped(UBYTE voice) | 332 | int VC1_VoiceStopped(UBYTE voice) |
327 | { | 333 | { |
@@ -334,7 +340,7 @@ SLONG VC1_VoiceGetPosition(UBYTE voice) | |||
334 | } | 340 | } |
335 | 341 | ||
336 | void VC1_VoiceSetVolume(UBYTE voice,UWORD vol) | 342 | void VC1_VoiceSetVolume(UBYTE voice,UWORD vol) |
337 | { | 343 | { |
338 | /* protect against clicks if volume variation is too high */ | 344 | /* protect against clicks if volume variation is too high */ |
339 | if(abs((int)vinf[voice].vol-(int)vol)>32) | 345 | if(abs((int)vinf[voice].vol-(int)vol)>32) |
340 | vinf[voice].rampvol=CLICK_BUFFER; | 346 | vinf[voice].rampvol=CLICK_BUFFER; |
@@ -353,9 +359,8 @@ void VC1_VoiceSetPanning(UBYTE voice,ULONG pan) | |||
353 | 359 | ||
354 | void VC1_SampleUnload(SWORD handle) | 360 | void VC1_SampleUnload(SWORD handle) |
355 | { | 361 | { |
356 | if (handle<MAXSAMPLEHANDLES) { | 362 | if (Samples && (handle < MAXSAMPLEHANDLES)) { |
357 | if (Samples[handle]) | 363 | MikMod_afree(Samples[handle]); |
358 | MikMod_free(Samples[handle]); | ||
359 | Samples[handle]=NULL; | 364 | Samples[handle]=NULL; |
360 | } | 365 | } |
361 | } | 366 | } |
@@ -364,10 +369,15 @@ SWORD VC1_SampleLoad(struct SAMPLOAD* sload,int type) | |||
364 | { | 369 | { |
365 | SAMPLE *s = sload->sample; | 370 | SAMPLE *s = sload->sample; |
366 | int handle; | 371 | int handle; |
367 | ULONG t, length,loopstart,loopend; | 372 | ULONG t, length,loopstart,loopend,looplen; |
368 | 373 | ||
369 | if(type==MD_HARDWARE) return -1; | 374 | if(type==MD_HARDWARE) return -1; |
370 | 375 | ||
376 | if(s->length > MAX_SAMPLE_SIZE) { | ||
377 | _mm_errno = MMERR_NOT_A_STREAM; /* better error? */ | ||
378 | return -1; | ||
379 | } | ||
380 | |||
371 | /* Find empty slot to put sample address in */ | 381 | /* Find empty slot to put sample address in */ |
372 | for(handle=0;handle<MAXSAMPLEHANDLES;handle++) | 382 | for(handle=0;handle<MAXSAMPLEHANDLES;handle++) |
373 | if(!Samples[handle]) break; | 383 | if(!Samples[handle]) break; |
@@ -376,7 +386,7 @@ SWORD VC1_SampleLoad(struct SAMPLOAD* sload,int type) | |||
376 | _mm_errno = MMERR_OUT_OF_HANDLES; | 386 | _mm_errno = MMERR_OUT_OF_HANDLES; |
377 | return -1; | 387 | return -1; |
378 | } | 388 | } |
379 | 389 | ||
380 | /* Reality check for loop settings */ | 390 | /* Reality check for loop settings */ |
381 | if (s->loopend > s->length) | 391 | if (s->loopend > s->length) |
382 | s->loopend = s->length; | 392 | s->loopend = s->length; |
@@ -390,22 +400,26 @@ SWORD VC1_SampleLoad(struct SAMPLOAD* sload,int type) | |||
390 | SL_SampleSigned(sload); | 400 | SL_SampleSigned(sload); |
391 | SL_Sample8to16(sload); | 401 | SL_Sample8to16(sload); |
392 | 402 | ||
393 | if(!(Samples[handle]=(SWORD*)MikMod_malloc((length+20)<<1))) { | 403 | if(!(Samples[handle]=(SWORD*)MikMod_amalloc((length+20)<<1))) { |
394 | _mm_errno = MMERR_SAMPLE_TOO_BIG; | 404 | _mm_errno = MMERR_SAMPLE_TOO_BIG; |
395 | return -1; | 405 | return -1; |
396 | } | 406 | } |
397 | 407 | ||
398 | /* read sample into buffer */ | 408 | /* read sample into buffer */ |
399 | if (SL_Load(Samples[handle],sload,length)) | 409 | if (SL_Load(Samples[handle],sload,length)) { |
410 | MikMod_afree(Samples[handle]); | ||
411 | Samples[handle]=NULL; | ||
400 | return -1; | 412 | return -1; |
413 | } | ||
401 | 414 | ||
402 | /* Unclick sample */ | 415 | /* Unclick sample */ |
403 | if(s->flags & SF_LOOP) { | 416 | if(s->flags & SF_LOOP) { |
417 | looplen = loopend - loopstart;/* handle short samples */ | ||
404 | if(s->flags & SF_BIDI) | 418 | if(s->flags & SF_BIDI) |
405 | for(t=0;t<16;t++) | 419 | for(t=0;t<16 && t<looplen;t++) |
406 | Samples[handle][loopend+t]=Samples[handle][(loopend-t)-1]; | 420 | Samples[handle][loopend+t]=Samples[handle][(loopend-t)-1]; |
407 | else | 421 | else |
408 | for(t=0;t<16;t++) | 422 | for(t=0;t<16 && t<looplen;t++) |
409 | Samples[handle][loopend+t]=Samples[handle][t+loopstart]; | 423 | Samples[handle][loopend+t]=Samples[handle][t+loopstart]; |
410 | } else | 424 | } else |
411 | for(t=0;t<16;t++) | 425 | for(t=0;t<16;t++) |
@@ -416,13 +430,13 @@ SWORD VC1_SampleLoad(struct SAMPLOAD* sload,int type) | |||
416 | 430 | ||
417 | ULONG VC1_SampleSpace(int type) | 431 | ULONG VC1_SampleSpace(int type) |
418 | { | 432 | { |
419 | (void)type; | 433 | (void)type; |
420 | return vc_memory; | 434 | return vc_memory; |
421 | } | 435 | } |
422 | 436 | ||
423 | ULONG VC1_SampleLength(int type,SAMPLE* s) | 437 | ULONG VC1_SampleLength(int type,SAMPLE* s) |
424 | { | 438 | { |
425 | (void)type; | 439 | (void)type; |
426 | if (!s) return 0; | 440 | if (!s) return 0; |
427 | 441 | ||
428 | return (s->length*((s->flags&SF_16BITS)?2:1))+16; | 442 | return (s->length*((s->flags&SF_16BITS)?2:1))+16; |
@@ -456,11 +470,8 @@ ULONG VC1_VoiceRealVolume(UBYTE voice) | |||
456 | return abs(k-j); | 470 | return abs(k-j); |
457 | } | 471 | } |
458 | 472 | ||
473 | #endif /* _VIRTCH_COMMON_ */ | ||
459 | 474 | ||
460 | #endif | 475 | #endif /* _IN_VIRTCH_ */ |
461 | |||
462 | MikMod_callback_t vc_callback; | ||
463 | |||
464 | #endif | ||
465 | 476 | ||
466 | /* ex:set ts=4: */ | 477 | /* ex:set ts=4: */ |